ERPClimb logoERPClimb
BAPI
ABAP Developmentintermediate 8 min read

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

Preview · a free account unlocks the full lesson

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.

In this lessonShow sections

Visual overview

BAPI Part 5: Commit, WAIT, Rollback and the SAP LUW — learning sheetFlow: Post a goods movement with BAPI_GOODSMVT_CREATE (code example) without commit — check MKPF: nothing → Commit with WAIT and read the material document → Force an error and verify rollback. Key ideas: WHY BAPIS DON'T COMMIT; BAPI_TRANSACTION_COMMIT; BAPI_TRANSACTION_ROLLBACK; ONE LUW PER BUSINESS DOCUMENT. Watch out: A successful RETURN does not guarantee the update succeeds — update errors appear later in SM13; with WAIT = 'X' the commit's RETURN shows them.ERPClimb.com / ABAP / LESSON 5/10 / LEARNING SHEETBAPI Part 5: Commit, WAIT, Rollback and the SAP LUW1 · HOW IT FLOWS1Post a goods movementwith BAPI_GOODSMVT_CREATE(code example) without…2Commit with WAIT and readthe material document3Force an error and verifyrollback2 · KEY IDEAS EXPLAINEDWhy BAPIs Don't CommitThe caller may need several BAPIs to form onebusiness transaction (e.g. create order + changesomething else). Leaving the commit to the caller…BAPI_TRANSACTION_COMMITCalls COMMIT WORK (AND WAIT if WAIT = 'X').RETURN parameter: reports problems of thesynchronous commit (with WAIT).BAPI_TRANSACTION_ROLLBACKCalls ROLLBACK WORK — discards registered updatesand releases locks. Always call it after E/Amessages, before processing the next document.One LUW Per Business DocumentIn uploads, commit (or roll back) after eachdocument, so one bad row doesn't discard theothers, and locks are released.3 · REMEMBER · WATCH OUTRememberMost BAPIs register their database changes in the update task; nothingis 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 registeredsince the last commit.!Watch outA successful RETURN does notguarantee the update succeeds —update errors appear later in SM13;with WAIT = 'X' the commit's RETURNshows them.4 · IN A REAL PROJECTA goods receipt interface posted material documents and immediately called a Z BAPI to update a tracking tablewith the document number. Randomly, the second step failed with "document not found", because thefirst commit was issued without WAIT and the update had not finished. Using BAPI_TRANSACTION_COMMIT with WAIT…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 4 covered reading the RETURN table. Now the question is what actually gets saved, and when.

Most BAPIs register their database changes in the update task; nothing is saved until the caller commits. The reasoning behind this is that a caller may need to combine several BAPIs into a single business transaction — creating an order and then changing something else, for instance — and leaving the commit entirely up to the caller is what makes genuine all-or-nothing behavior possible.

BAPI_TRANSACTION_COMMIT with WAIT = 'X' waits until the update is done — needed before reading the new document or calling a dependent BAPI. Internally it calls COMMIT WORK, and AND WAIT specifically when WAIT = 'X' is passed. Its own RETURN parameter reports any problems from that synchronous commit, but only when WAIT was actually set — without WAIT, the program carries on executing while the update runs in the background, so trying to read the document immediately afterward can fail.

BAPI_TRANSACTION_ROLLBACK calls ROLLBACK WORK, discarding everything registered since the last commit and releasing any locks that were held. On errors, BAPI_TRANSACTION_ROLLBACK discards everything registered since the last commit, and it's worth calling it immediately after any E or A message, before moving on to process the next document.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.