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
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.
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'.
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.
tRFC ensures data is processed once and only once.
2.4 Queued RFC (qRFC)
-
Extension of tRFC
-
Preserves execution order
-
Uses queues
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 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 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.
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'.
-
Call BAPI
-
Check RETURN
-
Commit or Rollback
- 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)
Always log RFC/BAPI errors using Application Logs.
7. RFC vs BAPI vs OData – Comparison
| Aspect | RFC | BAPI | OData |
|---|---|---|---|
| Full Form | Remote Function Call | Business Application Programming Interface | Open Data Protocol |
| Primary Purpose | Technical remote function execution | Business-level, stable SAP APIs | REST-based data & business services |
| Technology | ABAP Function Modules | RFC-based standardized FMs | HTTP / REST / JSON |
| Protocol | SAP RFC protocol | SAP RFC protocol | HTTP(S) |
| Communication Type | SAP ↔ SAP / External (via connectors) | SAP ↔ SAP / External | SAP ↔ Any (web, mobile, cloud) |
| Stateless | Yes | Yes | Yes |
| UI Friendly | ❌ | ❌ | ✅ |
| Used by UI5 / Fiori | ❌ | ❌ | ✅ |
| CRUD Support | Custom | Business-specific | Native (GET, POST, PUT, DELETE) |
| Data Format | ABAP structures | ABAP structures | JSON / XML |
| Versioning Support | ❌ | Limited | ✅ (service versions) |
| Security | SAP authorizations | SAP authorizations | OAuth / SAP auth / JWT |
| Performance | High (binary) | High | Medium (HTTP overhead) |
| Transaction Handling | Explicit | Explicit (BAPI_TRANSACTION_COMMIT) | Stateless (per request) |
| Error Handling | Exceptions | RETURN table | HTTP status + error payload |
| Upgrade Safety | ❌ (custom RFCs) | ✅ (released BAPIs) | ✅ |
| Internet Accessible | ❌ | ❌ | ✅ |
| Modern SAP Direction | ⚠️ Limited | ⚠️ Maintenance & core | ✅ Strategic |
| Typical Use Cases | System-to-system calls | Business object operations | UI, 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
-
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 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)
Strong RFC & BAPI knowledge is mandatory for enterprise ABAP developers.