Skip to main content

ERPL Examples

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

RFC Examples

Read Customer Data

SELECT * FROM sap_rfc_read_table('KNA1', LIMIT => 100);

Read Sales Orders

SELECT * FROM sap_rfc_read_table('VBAK', LIMIT => 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_rfc_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('CUBE');

Get Query Lineage

SELECT * FROM sap_bics_query_lineage('0D_FC_NW_C01_Q0008');

ODP Examples

Delta Replication

SELECT * FROM sap_odp_read_full(
'BW',
'VBAK$F',
replication_mode => 'DELTA'
);

Full Replication

SELECT * FROM sap_odp_read_full(
'BW',
'VBAK$F',
replication_mode => 'FULL'
);

Check Subscriptions

SELECT * FROM sap_odp_show_subscriptions();

Preview Data

SELECT * FROM sap_odp_preview('BW', 'VBAK$F', LIMIT => 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_rfc_read_table('KNA1', LIMIT => 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',
replication_mode => 'DELTA'
)
)
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

-- Analyze data lineage
WITH lineage_analysis AS (
SELECT
source_type,
target_type,
COUNT(*) AS flow_count
FROM sap_bics_query_lineage('0D_FC_NW_C01_Q0008')
GROUP BY source_type, target_type
)
SELECT
source_type,
target_type,
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;