BAPI
ABAP Developmentintermediate

BAPI Part 5: Commit, WAIT, Rollback and the SAP LUW

Key takeaway

Control transactions around BAPIs: why most BAPIs do not commit, BAPI TRANSACTION COMMIT with WAIT, BAPI TRANSACTION ROLLBACK, one LUW per business document, calling several BAPIs in one LUW, and what happens with update errors after the commit.

Explanation

📌 KEY POINTS
✅ Most BAPIs register their database changes in the update task; nothing is saved until the caller commits.

✅ BAPI_TRANSACTION_COMMIT with WAIT = 'X' waits until the update is done — needed before reading the new document or calling a dependent BAPI.

✅ On errors, BAPI_TRANSACTION_ROLLBACK discards everything registered since the last commit.

⚠️ A successful RETURN does not guarantee the update succeeds — update errors appear later in SM13; with WAIT = 'X' the commit's RETURN shows them.

━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE

Part 4 read RETURN. Now we decide what gets saved and when.

━━━━━━━━━━━━━━━━━━━━
▶ 1. WHY BAPIS DON'T COMMIT

The caller may need several BAPIs to form one business transaction (e.g. create order + change something else). Leaving the commit to the caller allows all-or-nothing behaviour.\n\n━━━━━━━━━━━━━━━━━━━━\n▶ 2. BAPI_TRANSACTION_COMMIT\n• Calls COMMIT WORK (AND WAIT if WAIT = 'X').

  • RETURN parameter: reports problems of the synchronous commit (with WAIT).
  • Without WAIT, the program continues while the update runs; reading the document immediately may fail.\n\n━━━━━━━━━━━━━━━━━━━━\n▶ 3. BAPI_TRANSACTION_ROLLBACK\nCalls ROLLBACK WORK — discards registered updates and releases locks. Always call it after E/A messages, before processing the next document.

━━━━━━━━━━━━━━━━━━━━
▶ 4. ONE LUW PER BUSINESS DOCUMENT

In uploads, commit (or roll back) after each document, so one bad row doesn't discard the others, and locks are released.

━━━━━━━━━━━━━━━━━━━━
▶ 5. SEVERAL BAPIS IN ONE LUW

  • Allowed when documented (e.g. dependent changes that must succeed together).
  • If the second BAPI needs data from the first document in the database, you need a commit in between — then they are no longer one LUW.
  • Some BAPIs must not be combined in one LUW (see documentation: "must not be called together with …").

━━━━━━━━━━━━━━━━━━━━
▶ 6. BAPIS THAT COMMIT THEMSELVES

A few older BAPIs commit internally (check documentation, e.g. some master data BAPIs). Don't combine them with others in one LUW.

━━━━━━━━━━━━━━━━━━━━
▶ 7. AFTER THE COMMIT

  • Check document existence if critical (SELECT SINGLE on the header table).
  • Update terminations: SM13 and ST22; monitor them in interfaces.

━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP

  1. Post a goods movement with BAPI_GOODSMVT_CREATE (code example) without commit — check MKPF: nothing.
  2. Commit with WAIT and read the material document.
  3. Force an error and verify rollback.

✅ CHECKPOINT: you control commit and rollback deliberately around each BAPI-based business transaction.

Code example

ABAP Code
REPORT zbapi_goodsmvt. DATA: ls_header TYPE bapi2017_gm_head_01,      ls_code   TYPE bapi2017_gm_code,      lt_items  TYPE STANDARD TABLE OF bapi2017_gm_item_create,      ls_item   TYPE bapi2017_gm_item_create,      lt_return TYPE STANDARD TABLE OF bapiret2,      ls_return TYPE bapiret2,      ls_commit TYPE bapiret2,      lv_mblnr  TYPE mblnr,      lv_mjahr  TYPE mjahr,      lv_error  TYPE abap_bool. START-OF-SELECTION.* ===== Step 1: goods receipt without PO (movement type 501) =====  ls_header-pstng_date = sy-datum.  ls_header-doc_date   = sy-datum.  ls_code-gm_code      = '05'.                  " other goods receipts   ls_item-material  = 'M-01'.  ls_item-plant     = '1000'.  ls_item-stge_loc  = '0001'.  ls_item-move_type = '501'.  ls_item-entry_qnt = 10.  APPEND ls_item TO lt_items. * ===== Step 2: BAPI registers the posting (no commit yet) =====  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'    EXPORTING      goodsmvt_header  = ls_header      goodsmvt_code    = ls_code    IMPORTING      materialdocument = lv_mblnr      matdocumentyear  = lv_mjahr    TABLES      goodsmvt_item    = lt_items      return           = lt_return.   LOOP AT lt_return INTO ls_return WHERE type CA 'EA'.    lv_error = abap_true.    WRITE: / ls_return-message.  ENDLOOP. * ===== Step 3: caller decides =====  IF lv_error = abap_true.    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.   " discard + release locks  ELSE.    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'      EXPORTING wait   = 'X'                    " wait for update task      IMPORTING return = ls_commit.    IF ls_commit-type CA 'EA'.      WRITE: / 'Update failed:', ls_commit-message.   " also check SM13    ELSE.      WRITE: / 'Material document', lv_mblnr, lv_mjahr.    ENDIF.  ENDIF.

Real project scenario

A goods receipt interface posted material documents and immediately called a Z BAPI to update a tracking table with the document number. Randomly, the second step failed with "document not found", because the first commit was issued without WAIT and the update had not finished.
Using BAPI_TRANSACTION_COMMIT with WAIT = 'X' and checking its RETURN fixed the timing. The team also added an SM13 monitor alert for update terminations from the interface user.

Common mistakes

  • Forgetting the commit (nothing saved, locks held).
  • Commit without WAIT, then reading the new document.
  • No rollback after errors, so the next document's commit saves partial data.
  • Combining BAPIs that commit themselves with others.
  • Not monitoring SM13 update errors.

Best practices

  • One LUW per business document in mass processing.
  • Commit with WAIT when results are needed immediately.
  • Roll back after E/A.
  • Read BAPI documentation for LUW restrictions.
  • Monitor SM13/ST22 for update terminations.

Interview angle

Questions: "Why do BAPIs not commit?", "What does WAIT do?", "What happens if you don't roll back after an error?"
Strong answer: BAPIs register updates in the update task, caller controls the LUW; BAPI_TRANSACTION_COMMIT WAIT = 'X' waits for V1 update (needed before reading/dependent calls) and returns update errors; ROLLBACK discards and releases locks; without it the next commit may save leftovers; one LUW per document; monitor SM13.

Practice this lesson

Quick check

1. An upload processes 1,000 orders. Where should BAPI_TRANSACTION_COMMIT be called?

2. BAPI_TRANSACTION_COMMIT with WAIT = X ensures…

3. BAPI_TRANSACTION_ROLLBACK should be called when:

Interview questions

1. Why must you call BAPI_TRANSACTION_COMMIT?

Answer it in your own words first, then compare.

2. How do you post multiple sales orders in one program transactionally?

Answer it in your own words first, then compare.

Practice more with Interview AI →

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

Interview questions on this topic

Related SAP topics