Modularization Part 5: Update Function Modules and IN UPDATE TASK
Understand SAP's classic update technique: logical units of work, update function modules (V1/V2), CALL FUNCTION … IN UPDATE TASK, COMMIT WORK and ROLLBACK WORK, PERFORM ON COMMIT, SM13 — and why RAP and BAPIs rely on it.
Explanation
📌 KEY POINTS
✅ An SAP LUW groups all database changes of a business transaction — they are written together or not at all.
✅ CALL FUNCTION 'Z_UPD' IN UPDATE TASK only registers the call; it runs at COMMIT WORK.
✅ V1 = critical, synchronous-with-commit updates; V2 = statistical, lower priority.
⚠️ Never COMMIT WORK inside an update function module or in code called from BAdIs/user exits of standard transactions.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Parts 1–4 covered units. This part explains how SAP transactions save data consistently — you will see it in every standard transaction, BAPI and in RAP's save phase.
━━━━━━━━━━━━━━━━━━━━
▶ 1. DATABASE LUW VS SAP LUW
- Database LUW: changes between two database commits. Every dialog step (screen change) triggers an implicit database commit.
- SAP LUW: a business transaction spanning several dialog steps (e.g. VA01 screens). To keep it atomic, changes are collected and executed together at COMMIT WORK in the update task.
━━━━━━━━━━━━━━━━━━━━
▶ 2. UPDATE FUNCTION MODULES
- Processing type "Update module" in SE37 (start immediately = V1, start delayed = V2).
- Only IMPORTING and TABLES parameters (by value), no EXPORTING — they run later, in the update work process.
- Contain the actual INSERT/UPDATE/DELETE statements.
━━━━━━━━━━━━━━━━━━━━
▶ 3. THE FLOW
- Dialog/program: CALL FUNCTION 'Z_FLIGHT_BOOK_UPD' IN UPDATE TASK EXPORTING … (registered, not executed).
- More registrations possible (several tables/FMs).
- COMMIT WORK — the update work process executes all registered update FMs in one database LUW.
- On error in an update FM → all changes rolled back, update terminated, entry in SM13, user gets an express mail.
- COMMIT WORK AND WAIT — waits until the update is finished (synchronous) — use when the next step needs the data (e.g. read the new document).
- ROLLBACK WORK — discards all registered update calls.\n\n━━━━━━━━━━━━━━━━━━━━\n▶ 4. PERFORM … ON COMMIT\nRegisters a FORM to be executed at COMMIT WORK (in the dialog process), e.g. to collect data before the update. ON ROLLBACK for cleanup.
━━━━━━━━━━━━━━━━━━━━
▶ 5. LOCKS
Lock the objects (ENQUEUE) before changing; locks are passed to the update task (_SCOPE = 2 default) and released after the update.
━━━━━━━━━━━━━━━━━━━━
▶ 6. WHERE YOU MEET THIS
- Standard transactions and BAPIs (BAPI_TRANSACTION_COMMIT = COMMIT WORK).
- User exits/BAdIs in save processing — they run inside SAP's LUW: no COMMIT WORK there!
- RAP unmanaged/unmanaged-save scenarios call legacy code IN UPDATE TASK in the save phase.
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- Create update FM Z_FLIGHT_LOG_UPD (update module, start immediately) inserting into a custom log table.
- Register it in a report IN UPDATE TASK, then COMMIT WORK AND WAIT.
- Force an error in the FM and check SM13.
✅ CHECKPOINT: you understand how SAP transactions save atomically and where not to commit.
Code example
* ===== Update function module (SE37: Processing type = Update module, V1) =====FUNCTION z_flight_log_upd.*" IMPORTING*" VALUE(IS_LOG) TYPE ZFLIGHT_LOG " custom table ZFLIGHT_LOG INSERT zflight_log FROM is_log. IF sy-subrc <> 0. MESSAGE a020(zflight). " abort -> whole update rolled back, SM13 ENDIF.ENDFUNCTION. * ===== Caller: register, then commit =====REPORT zmod_part5.DATA gs_log TYPE zflight_log. START-OF-SELECTION.* 1. lock the object (lock object EZFLIGHT_LOG created in SE11) CALL FUNCTION 'ENQUEUE_EZFLIGHT_LOG' EXPORTING carrid = 'LH' connid = '0400' EXCEPTIONS foreign_lock = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE 'Flight is being processed by another user' TYPE 'E'. ENDIF. * 2. register the update (NOT executed yet) gs_log-carrid = 'LH'. gs_log-connid = '0400'. gs_log-changed_by = sy-uname. gs_log-changed_on = sy-datum. CALL FUNCTION 'Z_FLIGHT_LOG_UPD' IN UPDATE TASK EXPORTING is_log = gs_log. * 3. optional: FORM executed at commit (dialog process) PERFORM notify_on_commit ON COMMIT. * 4. commit: all registered update FMs run together COMMIT WORK AND WAIT. " wait: next step needs the data IF sy-subrc <> 0. WRITE: / 'update failed - see SM13'. ENDIF.* locks are released by the update task after the update FORM notify_on_commit.* e.g. trigger a workflow event or prepare a mailENDFORM. * NEVER: COMMIT WORK inside Z_FLIGHT_LOG_UPD, or in user exits/BAdIs* running inside a standard transaction's save processing.Real project scenario
A developer added a COMMIT WORK into a user exit during sales order save "to make sure the Z table is written". Occasionally, the order save later failed; the Z table already contained data for orders that did not exist, and some orders were partially saved.
The fix wrote the Z table via an update function module registered IN UPDATE TASK in the exit — without COMMIT. SAP's own COMMIT WORK then saved order and Z data together, or neither.
Common mistakes
- COMMIT WORK in user exits, BAdIs or update modules.
- Expecting IN UPDATE TASK calls to run immediately.
- EXPORTING parameters in update FMs.
- Not using COMMIT WORK AND WAIT when the next step reads the new data.
- Ignoring SM13 update errors.
Best practices
- Put DB changes of a business transaction into update FMs.
- Register with IN UPDATE TASK; commit once at the end.
- Use AND WAIT when subsequent reads depend on the update.
- Lock objects before changing them.
- Monitor SM13 for update terminations.
Interview angle
Questions: "What is an SAP LUW?", "What does IN UPDATE TASK do?", "V1 vs V2 update?", "Why no COMMIT WORK in user exits?"
Strong answer: an SAP LUW bundles changes of a business transaction across dialog steps; update FMs registered IN UPDATE TASK execute together at COMMIT WORK in the update process (V1 critical, V2 statistical), rolled back entirely on error (SM13); COMMIT WORK AND WAIT is synchronous; exits run inside SAP's LUW, so committing there breaks atomicity.
Practice this lesson
Quick check
1. A program shows "saved" but the record written via an update FM IN UPDATE TASK is missing. Where do you look first?
2. V1 update is:
3. Update FMs are triggered by:
Interview questions
1. Users get a success message after saving a sales-related custom document, but the record is sometimes missing in the database. What could be wrong with the update logic?
Answer it in your own words first, then compare.
2. What is the cost of many small function-module calls in a loop?
Answer it in your own words first, then compare.
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
- Modularization Part 1: Why and How to Split ABAP Programs
- Modularization Part 10: Modularization for Unit Testing and Regression Safety
- Modularization Part 2: FORM Routines — Legacy but Still Important
- Modularization Part 3: FORM vs Method vs Function Module
- Modularization Part 4: Function Modules and Function Groups
- Modularization Part 6: Methods and Local Classes
- Modularization Part 7: Global Classes vs Local Classes
- Modularization Part 8: Parameter Passing — IMPORTING, EXPORTING, CHANGING and RETURNING