Skip to main content

ERPL Examples

Real-world examples using ERPL for on-premise SAP integration.

RFC Examples

Read Customer Data

SELECT * FROM sap_read_table('KNA1', MAX_ROWS => 100);

Read Sales Orders

SELECT * FROM sap_read_table('VBAK', MAX_ROWS => 100);

Call BAPI Function

SELECT * FROM sap_rfc_invoke(
'BAPI_FLIGHT_GETLIST',
path => '/FLIGHT_LIST'
);

Get Function Metadata

SELECT * FROM sap_rfc_describe_function('BAPI_FLIGHT_GETLIST');

Get Table Structure

SELECT * FROM sap_describe_fields('KNA1');

BICS Examples

Execute BW Query

SELECT * FROM sap_bics_result(
sap_bics_filter(
sap_bics_begin('0BWTESTCUBE'),
'0CALMONTH', '202401'
)
);

List Available Cubes

SELECT * FROM sap_bics_show(obj_type => 'CUBE');

Get Query Lineage

-- All lineage edges touching one BEx query
SELECT *
FROM sap_bics_lineage_edges()
WHERE tgt_name = '0D_FC_NW_C01_Q0008' OR src_name = '0D_FC_NW_C01_Q0008';

ODP Examples

Delta Replication

SELECT * FROM sap_odp_read_full(
'BW',
'VBAK$F'
);

Full Replication

SELECT * FROM sap_odp_read_full(
'BW',
'VBAK$F'
);

Check Subscriptions

SELECT * FROM sap_odp_show_subscriptions();

Preview Data

SELECT * FROM sap_odp_preview('BW', 'VBAK$F', max_rows => 100);

Advanced Examples

Cross-Protocol Data Integration

-- Combine RFC and BICS data
WITH erp_customers AS (
SELECT KUNNR AS customer_id, NAME1 AS customer_name
FROM sap_read_table('KNA1', MAX_ROWS => 1000)
),
bw_sales AS (
SELECT
"0CUSTOMER" AS customer_id,
"0SALES_AMOUNT" AS sales_amount
FROM sap_bics_result(
sap_bics_filter(
sap_bics_begin('0BWTESTCUBE'),
'0CALMONTH', '202401'
)
)
)
SELECT
e.customer_id,
e.customer_name,
b.sales_amount
FROM erp_customers e
JOIN bw_sales b ON e.customer_id = b.customer_id;

ODP Delta Pipeline

-- Daily delta replication pipeline
WITH delta_data AS (
SELECT
*,
RECORD_MODE,
CASE RECORD_MODE
WHEN 'I' THEN 'INSERT'
WHEN 'U' THEN 'UPDATE'
WHEN 'D' THEN 'DELETE'
ELSE 'UNKNOWN'
END AS change_type
FROM sap_odp_read_full(
'BW',
'VBAK$F'
)
)
SELECT
change_type,
COUNT(*) AS record_count,
MIN(ERDAT) AS earliest_date,
MAX(ERDAT) AS latest_date
FROM delta_data
GROUP BY change_type
ORDER BY change_type;

BICS Lineage Analysis

-- Aggregate edges related to one BEx query by source/target kind
WITH query_edges AS (
SELECT src_kind, tgt_kind
FROM sap_bics_lineage_edges()
WHERE tgt_name = '0D_FC_NW_C01_Q0008' OR src_name = '0D_FC_NW_C01_Q0008'
),
lineage_analysis AS (
SELECT src_kind, tgt_kind, COUNT(*) AS flow_count
FROM query_edges
GROUP BY src_kind, tgt_kind
)
SELECT
src_kind,
tgt_kind,
flow_count,
ROUND(flow_count * 100.0 / SUM(flow_count) OVER(), 2) AS percentage
FROM lineage_analysis
ORDER BY flow_count DESC;

RFC Function Discovery

-- Discover BAPI functions
SELECT
function_name,
COUNT(*) AS parameter_count
FROM sap_rfc_show_function()
WHERE function_name LIKE '%BAPI%'
GROUP BY function_name
ORDER BY parameter_count DESC;

ODP Subscription Management

-- Monitor subscription health
WITH subscription_health AS (
SELECT
subscriber_name,
data_source,
context,
status,
CASE
WHEN status = 'ACTIVE' THEN 'HEALTHY'
WHEN status = 'ERROR' THEN 'NEEDS_ATTENTION'
WHEN status = 'SUSPENDED' THEN 'SUSPENDED'
ELSE 'UNKNOWN'
END AS health_status,
last_used_date,
CURRENT_DATE - last_used_date AS days_since_last_use
FROM sap_odp_show_subscriptions()
)
SELECT
subscriber_name,
data_source,
health_status,
days_since_last_use,
CASE
WHEN days_since_last_use > 7 THEN 'STALE'
WHEN days_since_last_use > 1 THEN 'RECENT'
ELSE 'CURRENT'
END AS usage_status
FROM subscription_health
ORDER BY days_since_last_use DESC;