ABAP Developmentintermediate
Calling a BAPI Correctly
Return table handling and BAPI_TRANSACTION_COMMIT.
Explanation
Every BAPI returns a RETURN table (or structure) โ always inspect it for E/A messages and roll back if any. BAPIs never commit themselves; call BAPI_TRANSACTION_COMMIT WAIT after a successful call. Passing WAIT = 'X' ensures the update task finishes before your code continues.
Code example
ABAP Code
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' EXPORTING order_header_in = ls_header IMPORTING salesdocument = lv_vbeln TABLES order_items_in = lt_items return = lt_return.IF line_exists( lt_return[ type = 'E' ] ) OR line_exists( lt_return[ type = 'A' ] ). CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'.ENDIF.Real project scenario
An integration missed BAPI_TRANSACTION_COMMIT and 20% of sales orders silently failed. Adding the commit and RETURN check fixed the loss.
Common mistakes
Ignoring RETURN messages; committing before checking; using COMMIT WORK directly instead of BAPI_TRANSACTION_COMMIT.
Best practices
Always centralise BAPI calls in a service class that handles the commit/rollback pattern uniformly.
Interview angle
When to use WAIT = 'X'.