SAP API Call Patterns
This page collects practical SAP API examples, the common calls across OData, BAPI and IDoc, so you can connect the concepts to real requests and code.
Three SAP API call patterns. An OData read: GET the A_BusinessPartner entity set of API_BUSINESS_PARTNER with $filter and $top and a bearer token. A BAPI create in ABAP: CALL FUNCTION BAPI_PO_CREATE1, check RETURN for type E, then BAPI_TRANSACTION_COMMIT. An IDoc: outbound event to IDoc to dispatch, inbound IDoc to posting function module, monitored in WE02 or BD87.
- Watch out: Skipping result/error checks (RETURN, HTTP status, IDoc status).
- Worked examples: odata read (s/4hana api), bapi create (abap), idoc (concept).
- How Examples fits into SAP APIs and the wider SAP landscape
OData read (S/4HANA API)
GET /sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner?$filter=BusinessPartnerCategory eq '2'&$top=10
Authorization: Bearer <token>BAPI create (ABAP)
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING poheader = ls_header
IMPORTING exppurchaseorder = DATA(lv_po)
TABLES poitem = lt_items return = lt_return.
IF NOT line_exists( lt_return[ type = 'E' ] ).
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.IDoc (concept)
" Outbound: application event → IDoc generated → dispatched (ALE/EDI)
" Inbound: IDoc received → posting function module → document created
" Monitor: WE02 / BD87Using the examples
Adapt these patterns: obtain proper authentication, check results (RETURN for BAPIs, HTTP status for OData, statuses for IDocs), and handle errors. Use the SAP Business Accelerator Hub to find the exact released API and try it before coding.
Common pitfalls
- Skipping result/error checks (RETURN, HTTP status, IDoc status).
- Hard-coded credentials.
- Not using the API Business Hub to find released APIs.