Skip to main content

Module 25: RFC, BAPI & Integration

RFC (Remote Function Call) is SAP’s core technology for communication between SAP systems and external systems.
BAPIs build on RFC to provide stable, business-level APIs.

This module is essential for system integration, interfaces, and enterprise landscapes.


1. What is RFC?

Definition

RFC allows a function module in one system to be called remotely from another system or external application.

Key Characteristics

  • Synchronous or asynchronous
  • Secure communication
  • Transaction-aware
  • Widely used across SAP
SAP Integration Backbone

RFC is the foundation for BAPIs, ALE, IDocs, and many SAP interfaces.


2. RFC Types

SAP supports multiple RFC types, each for different integration needs.


2.1 Synchronous RFC (sRFC)

  • Caller waits for response
  • Immediate result
  • Most commonly used
CALL FUNCTION 'Z_GET_DATA'
DESTINATION 'RFC_DEST'
IMPORTING
ev_result = lv_result.
Use Case

Real-time data retrieval and validation.

2.2 Asynchronous RFC (aRFC)

  • Caller does not wait

  • Fire-and-forget

  • No guaranteed delivery

CALL FUNCTION 'Z_PROCESS_DATA'
STARTING NEW TASK lv_task
DESTINATION 'RFC_DEST'.
Limitation

No built-in confirmation or rollback.

2.3 Transactional RFC (tRFC)

  • Ensures exactly-once execution

  • Used for reliable data transfer

CALL FUNCTION 'Z_SEND_DATA'
IN BACKGROUND TASK
DESTINATION 'RFC_DEST'.
COMMIT WORK.
Reliability

tRFC ensures data is processed once and only once.

2.4 Queued RFC (qRFC)

  • Extension of tRFC

  • Preserves execution order

  • Uses queues

Typical Use Case

Sequential processing like financial postings.

3. Remote Enabled Function Modules

What Makes a Function Module RFC-Enabled?

  • Attribute: Remote-Enabled Module

  • No GUI statements

  • No COMMIT WORK inside

  • Serializable parameters only

FUNCTION z_get_customer_data.
*" IMPORTING iv_custid TYPE kunnr
*" EXPORTING es_customer TYPE zcust
ENDFUNCTION.
RFC Restrictions

RFC function modules must be stateless and UI-free.

4. BAPI Standards (Very Important)

What is a BAPI?

A BAPI (Business Application Programming Interface) is:

  • A standardized RFC

  • Business-object oriented

  • Stable and upgrade-safe

SAP Contract

SAP guarantees backward compatibility for released BAPIs.

4.1 BAPI Naming & Structure

Typical BAPI structure:

  • BAPI_<OBJECT>_<ACTION>

Example:

  • BAPI_SALESORDER_CREATEFROMDAT2

4.2 Standard BAPI Pattern

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = ls_header
TABLES
order_items_in = lt_items
return = lt_return.

4.3 RETURN Table (Mandatory)

  • The RETURN table:

  • Contains success, warning, error messages

  • Must always be checked

READ TABLE lt_return
WITH KEY type = 'E'
TRANSPORTING NO FIELDS.
Golden Rule

Never ignore the BAPI RETURN table.

5. Commit Handling in BAPIs

Why BAPIs Don’t Commit Automatically

BAPIs do not perform COMMIT WORK internally to allow:

  • Logical Unit of Work control

  • Transaction bundling

5.1 Explicit Commit

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.

5.2 Rollback on Error

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
Correct Flow
  • Call BAPI

  • Check RETURN

  • Commit or Rollback

  1. Error Handling in RFC & BAPI 6.1 RFC Error Handling CALL FUNCTION 'Z_REMOTE_FUNC' DESTINATION 'RFC_DEST' EXCEPTIONS system_failure = 1 communication_failure = 2.

6.2 BAPI Error Handling

Use RETURN table

Use MESSAGE ID/NUMBER

Log errors (SLG1)

Production Best Practice

Always log RFC/BAPI errors using Application Logs.

7. RFC vs BAPI vs OData – Comparison

AspectRFCBAPIOData
Full FormRemote Function CallBusiness Application Programming InterfaceOpen Data Protocol
Primary PurposeTechnical remote function executionBusiness-level, stable SAP APIsREST-based data & business services
TechnologyABAP Function ModulesRFC-based standardized FMsHTTP / REST / JSON
ProtocolSAP RFC protocolSAP RFC protocolHTTP(S)
Communication TypeSAP ↔ SAP / External (via connectors)SAP ↔ SAP / ExternalSAP ↔ Any (web, mobile, cloud)
StatelessYesYesYes
UI Friendly
Used by UI5 / Fiori
CRUD SupportCustomBusiness-specificNative (GET, POST, PUT, DELETE)
Data FormatABAP structuresABAP structuresJSON / XML
Versioning SupportLimited✅ (service versions)
SecuritySAP authorizationsSAP authorizationsOAuth / SAP auth / JWT
PerformanceHigh (binary)HighMedium (HTTP overhead)
Transaction HandlingExplicitExplicit (BAPI_TRANSACTION_COMMIT)Stateless (per request)
Error HandlingExceptionsRETURN tableHTTP status + error payload
Upgrade Safety❌ (custom RFCs)✅ (released BAPIs)
Internet Accessible
Modern SAP Direction⚠️ Limited⚠️ Maintenance & core✅ Strategic
Typical Use CasesSystem-to-system callsBusiness object operationsUI, APIs, cloud integration

7.1 When to Use What (Decision Guide)

✅ Use RFC when:

  • SAP ↔ SAP technical integration

  • Internal system calls

  • High performance required

  • No UI or internet exposure

::: Calling a utility function from another SAP system. :::

✅ Use BAPI when:

  • Performing business operations

  • Upgrade safety is required

  • Standard SAP object manipulation

  • ECC / S/4 core integrations

::: Creating Sales Orders, Purchase Orders, Goods Movements. :::

✅ Use OData when:

  • UI5 / Fiori applications

  • Cloud or external integrations

  • REST-based APIs

  • RAP-based developments

::: Fiori app consuming Sales Order data. :::

7.2 Modern SAP Recommendation (S/4HANA)

Internal SAP logic        → Classes / CDS
System-to-system (SAP) → BAPI
Modern UI / APIs → OData (RAP)
Legacy integrations → RFC

8. Common Integration Pitfalls

Avoid These
  • COMMIT WORK inside RFC FM

  • Ignoring RETURN messages

  • Using SELECT directly instead of BAPIs

  • Hard-coded RFC destinations

  • Missing authorization checks

9. Interview-Grade Explanation

Q: How do you design a reliable SAP integration?

Answer:

I use the appropriate RFC type based on reliability and sequencing needs, prefer released BAPIs for business operations, handle errors via RETURN tables and exceptions, control commits explicitly, and ensure logging and restartability.

This Answer Works

This shows real integration experience, not textbook knowledge.

10. Summary

  • RFC enables SAP-to-SAP and external communication

  • Different RFC types serve different reliability needs

  • Remote-enabled function modules are stateless

  • BAPIs are standardized, stable APIs

  • Explicit commit handling is mandatory

  • Robust error handling is critical

11. Practice Exercises

  • Create an RFC-enabled function module.

  • Call it synchronously from another system.

  • Use a BAPI and handle RETURN messages.

  • Implement explicit commit/rollback logic.

  • Compare sRFC vs tRFC use cases.

12. What’s Next?

➡️ Module 26: OData Services (ABAP Backend)

Learning Tip

Strong RFC & BAPI knowledge is mandatory for enterprise ABAP developers.