BAPI
Quick answer
BAPIs enforce SAP’s business logic and validations; writing to tables directly bypasses them and corrupts data.
Key takeaways
- A BAPI is a released, remote-enabled function module for a business object (e.
- The RETURN table carries messages; an entry with type 'E' (or 'A') means failure.
- This page covers the practical pattern every ABAP developer must know.
- Watch out: Forgetting BAPI_TRANSACTION_COMMIT.
The BAPI calling pattern
A BAPI is a released, remote-enabled function module for a business object (e.g. create a sales order). You fill its import structures/tables, call it, inspect the RETURN table for errors, and, if successful, commit with BAPI_TRANSACTION_COMMIT (most BAPIs do not commit themselves).
Example
DATA lt_return TYPE bapiret2_t.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING order_header_in = ls_header
IMPORTING salesdocument = DATA(lv_vbeln)
TABLES order_items_in = lt_items
return = lt_return.
IF line_exists( lt_return[ type = 'E' ] ).
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = abap_true.
ENDIF.Always check RETURN
The RETURN table carries messages; an entry with type 'E' (or 'A') means failure. Committing without checking, or ignoring errors, leads to partial or wrong data. Checking RETURN and committing/rolling back accordingly is non-negotiable.
Why BAPIs over direct writes
BAPIs enforce SAP’s business logic and validations; writing to tables directly bypasses them and corrupts data. Always prefer a BAPI (or a modern released API) for creating/changing business objects.
Common pitfalls
- Forgetting BAPI_TRANSACTION_COMMIT.
- Not checking the RETURN table for errors.
- Direct table writes instead of a BAPI.
Want to learn this properly?
Our live, instructor-led SAP Training covers this hands-on, with real projects and a certification path.
Check your understanding
Which statement is true of BAPI?
- A. A BAPI is a released, remote-enabled function module for a business object (e.
- B. Keyboard shortcuts in SAP GUI let you perform common actions, save, back, enter, function keys, without…
- C. A profit center is a controlling (CO) organizational unit representing an area of the business for which…
Show answer
A. A BAPI is a released, remote-enabled function module for a business object (e.
Covered in the “The BAPI calling pattern” section of this lesson.
Which of these also applies to BAPI?
- A. Reading tables directly instead of using CDS/reports where appropriate.
- B. Confusing products with modules, SuccessFactors is a product; FI is a module of the ERP core.
- C. g.
Show answer
C. g.
Covered in the “The BAPI calling pattern” section of this lesson.
Which part of the Learn SAP curriculum covers BAPI?
- A. SAP troubleshooting
- B. SAP SD
- C. SAP ABAP development
Show answer
C. SAP ABAP development
This lesson sits in the SAP ABAP development section of the Learn SAP course.