BAPI
ABAP DevelopmentIntermediate

BAPI_TRANSACTION_COMMIT, ROLLBACK and SAP LUW

Understand why many BAPIs need explicit commit and how SAP LUW works.

Explanation

Many BAPIs do not commit database changes automatically. They perform checks and register update tasks, but the caller must explicitly call BAPI_TRANSACTION_COMMIT after successful processing. This gives the caller control over the SAP Logical Unit of Work. If multiple BAPIs must succeed together, commit should happen only after all required BAPIs finish without errors. If any BAPI fails, rollback should be called. The WAIT parameter is useful when the caller needs the update to finish before reading the created document.

Code example

ABAP Code
* Purpose:* Show correct commit control after a BAPI call.* Many BAPIs require explicit commit from the caller. CALL FUNCTION 'BAPI_GOODSMVT_CREATE'  EXPORTING    goodsmvt_header  = ls_header    goodsmvt_code    = ls_code  IMPORTING    materialdocument = lv_mblnr  TABLES    goodsmvt_item    = lt_item    return           = lt_return. IF line_exists( lt_return[ type = 'E' ] ) OR   line_exists( lt_return[ type = 'A' ] ).   * Rollback because BAPI returned business error  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE.   * WAIT = X ensures update task completes before next read/check  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'    EXPORTING      wait = abap_true. ENDIF.

Real project scenario

A sales order interface called BAPI_SALESORDER_CREATEFROMDAT2 but forgot BAPI_TRANSACTION_COMMIT. The BAPI returned a document number, but the sales order was not saved.

Common mistakes

- Forgetting BAPI_TRANSACTION_COMMIT. - Calling commit before checking RETURN. - Not using WAIT when immediate read-after-write is needed. - Committing each row separately without design review.

Best practices

- Commit only after successful RETURN check. - Use rollback on errors. - Use WAIT when follow-up read depends on update completion. - Design commit frequency carefully for mass uploads.

Interview angle

A strong answer should explain SAP LUW, explicit commit, rollback and WAIT parameter.