BAPI Part 3: BAPI vs RFC vs OData
Understand how BAPIs, RFC and OData relate: BAPIs as released RFC function modules, RFC as the protocol (synchronous, tRFC, qRFC, bgRFC), OData services for Fiori and REST-style integration, and how to choose the right interface for local programs, SAP-to-SAP and external integrations.
Explanation
📌 KEY POINTS
✅ RFC is the communication protocol; a BAPI is a released business method implemented as an RFC-enabled function module.
✅ OData is an HTTP/REST-style protocol used by Fiori and modern integrations; OData services often call BAPIs or RAP business objects internally.
✅ Choose by consumer: ABAP program in the same system → call BAPI locally; SAP-to-SAP → RFC/BAPI (or IDoc/APIs); web/mobile/cloud → OData/REST APIs.
⚠️ Not every RFC-enabled function module is a BAPI — unreleased RFC FMs can change without notice.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Parts 1–2 called a BAPI inside ABAP. In integration projects you must also decide how external systems reach SAP.
━━━━━━━━━━━━━━━━━━━━
▶ 1. RFC VARIANTS
- sRFC (synchronous): caller waits for the result; DESTINATION in SM59.
- tRFC (transactional, IN BACKGROUND TASK): executed exactly once, asynchronously; order not guaranteed.
- qRFC: queued tRFC, preserves order per queue (SMQ1/SMQ2).
- bgRFC: newer background RFC framework replacing tRFC/qRFC in modern releases.
- Monitoring: SM58 (tRFC), SMQ1/SMQ2 (queues), SBGRFCMON (bgRFC).
━━━━━━━━━━━━━━━━━━━━
▶ 2. BAPI OVER RFC
External systems (SAP PI/PO, middleware, Java/.NET with SAP connectors) call BAPIs via RFC. Commit must be called in the same RFC session (BAPI_TRANSACTION_COMMIT via the same connection), otherwise nothing is saved.
━━━━━━━━━━━━━━━━━━━━
▶ 3. ODATA
- SAP Gateway (SEGW) or RAP service bindings expose entities over HTTP; used by Fiori apps and REST consumers.
- OData services in SEGW often call BAPIs in their CREATE_ENTITY methods; RAP services use behaviour implementations.
- Released SAP APIs in S/4HANA (API Business Hub) are mostly OData/SOAP.
━━━━━━━━━━━━━━━━━━━━
▶ 4. HOW TO CHOOSE
- Internal ABAP logic: call the BAPI directly.
- SAP ERP ↔ SAP ERP with guaranteed delivery and monitoring: IDoc or qRFC/bgRFC; synchronous lookups via RFC.
- External cloud/web: OData/REST (released APIs) through API management or integration platform.
- Mass/asynchronous: IDoc or asynchronous messaging rather than many synchronous calls.
━━━━━━━━━━━━━━━━━━━━
▶ 5. CLEAN CORE VIEW
In S/4HANA, prefer released APIs (OData/SOAP, released RFCs/BAPIs where listed). Classic BAPIs remain widely used on-premise.
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- SM59: display an RFC destination and test connection.
- Call a BAPI remotely with DESTINATION in a test program (code example).
- Look up the sales order OData API in the API Business Hub and compare its fields with BAPI_SALESORDER_CREATEFROMDAT2.
✅ CHECKPOINT: you can explain the relationship between RFC, BAPIs and OData and choose an interface type.
Code example
REPORT zbapi_rfc_demo. PARAMETERS p_dest TYPE rfcdest DEFAULT 'ERP_QAS_100'. " SM59 destination DATA: ls_return TYPE bapireturn1, " this older BAPI uses BAPIRETURN1, not BAPIRET2 lv_msg TYPE c LENGTH 200, ls_addr TYPE bapicustomer_04, lv_kunnr TYPE kunnr VALUE '0000001000'. START-OF-SELECTION.* ===== Synchronous RFC call of a BAPI in another system ===== CALL FUNCTION 'BAPI_CUSTOMER_GETDETAIL2' DESTINATION p_dest EXPORTING customerno = lv_kunnr IMPORTING customeraddress = ls_addr return = ls_return EXCEPTIONS system_failure = 1 MESSAGE lv_msg " remote dump / error communication_failure = 2 MESSAGE lv_msg " network / destination OTHERS = 3. IF sy-subrc <> 0. WRITE: / 'RFC error:', lv_msg. ELSEIF ls_return-type CA 'EA'. WRITE: / 'BAPI error:', ls_return-message. ELSE. WRITE: / ls_addr-name, ls_addr-city. ENDIF. * ===== Remote create + commit must use the SAME destination/session =====* CALL FUNCTION 'BAPI_...' DESTINATION p_dest ...* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' DESTINATION p_dest EXPORTING wait = 'X'.* CALL FUNCTION 'RFC_CONNECTION_CLOSE' EXPORTING destination = p_dest. * ===== Asynchronous, exactly once (tRFC) =====* CALL FUNCTION 'Z_REMOTE_UPDATE' IN BACKGROUND TASK DESTINATION p_dest* EXPORTING ...* COMMIT WORK. " sends the tRFC; monitor in SM58Real project scenario
A middleware team called BAPI_PO_CREATE1 via RFC and then BAPI_TRANSACTION_COMMIT via a separate connection pool entry. POs were returned with numbers but never existed in SAP, because the commit ran in a different RFC session.
The integration was changed to use a stateful connection for the BAPI and commit. Later, for a new Fiori-based supplier portal, the team used the released purchase order OData API instead of direct RFC.
Common mistakes
- Commit in a different RFC session than the BAPI.
- Using unreleased RFC FMs as integration APIs.
- Synchronous RFC for mass data that should be asynchronous.
- Ignoring SYSTEM_FAILURE/COMMUNICATION_FAILURE.
- Building custom OData when a released API exists.
Best practices
- Use released BAPIs/APIs for integration.
- Keep BAPI and commit in the same RFC session.
- Handle RFC exceptions with MESSAGE.
- Choose asynchronous techniques (IDoc, qRFC/bgRFC) for volume and reliability.
- Monitor SM58/SMQ1/SMQ2/SBGRFCMON.
Interview angle
Questions: "BAPI vs RFC?", "BAPI vs OData?", "What is tRFC/qRFC?", "Why was the document not saved when called remotely?"
Strong answer: RFC is the protocol; BAPIs are released RFC-enabled FMs of business objects; OData is HTTP-based for Fiori/REST, often wrapping BAPIs or RAP; sRFC synchronous, tRFC exactly once, qRFC ordered, bgRFC modern; remote commit must be in the same session; choose by consumer and volume, prefer released APIs.
Practice this lesson
Quick check
1. A cloud web application must create sales orders in S/4HANA. Which interface is usually most suitable?
2. Which RFC variant guarantees exactly-once execution in call order within a queue?
3. Which restriction generally applies to the data types allowed for import, export, and table parameters when designing a BAPI interface?
Interview questions
1. External system floods SAP with BAPI calls. How do you protect performance?
Answer it in your own words first, then compare.
2. Difference between BAPI and RFC.
Answer it in your own words first, then compare.
Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.
More lessons in this topic
- BAPI Part 1: What a BAPI Is and How to Find One
- BAPI Part 10: "Success but No Document" — Debugging BAPI Problems
- BAPI Part 2: Calling a BAPI — Inputs, X Structures, RETURN and Commit
- BAPI Part 4: Understanding BAPI RETURN Messages
- BAPI Part 5: Commit, WAIT, Rollback and the SAP LUW
- BAPI Part 6: Mapping Header, Item, Partner and Schedule Data
- BAPI Part 7: Test Run, Simulation and Safe BAPI Execution
- BAPI Part 8: EXTENSIONIN — Saving Custom Fields with BAPIs