Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  Data Consistency →  SAP LUW 

COMMIT WORK

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


 COMMIT WORK [AND WAIT]. 

Effect

The COMMIT WORK statement closes the current SAP LUW and opens a new one. All change requests from the current SAP LUW are then committed. In this case, COMMIT WORK performs the following actions:

  • It executes all subroutines registered using PERFORM ON COMMIT.

    The order is based on the order of registration or according to the priority specified using the LEVEL addition. The following statements are not allowed to be executed in a subroutine of this type:

    PERFORM ... ON COMMIT|ROLLBACK
    COMMIT WORK
    ROLLBACK WORK

    The statement CALL FUNCTION ... IN UPDATE TASK can be executed.

  • It triggers an internal event for the persistence service of the Object Services.

    If event handlers are registered by the persistence service, they collect the changes to the objects managed by the service and use CALL FUNCTION ... IN UPDATE TASK to pass them to a special update function module, registered as the final update module.

  • It triggers the processing of all update function modules registered using CALL FUNCTION ... IN UPDATE TASK in the update work process or, for local updates, in the current work process as well.

    All high-priority ("VB1") update function modules are executed in the order of their registration and in a shared database LUW. If the addition AND WAIT is not specified, the program does not wait (in non-local updates) until the update work process has executed it (asynchronous updates), but instead is resumed immediately after COMMIT WORK. However, if the addition AND WAIT is specified, program processing after COMMIT WORK will not continue until the update work process has executed the high-priority update function modules (synchronous updating).

    When all high-priority update function modules are completed successfully, the statement executes the low-priority ("VB2") update function modules in the order of registration together in a shared database LUW.

    After the execution of high-priority update function modules, the individual function modules registered using CALL FUNCTION ... IN BACKGROUND are each registered in their own database LUW by destination.

    Within an update function module started using COMMIT WORK, statements that cause a database commit cannot be executed. In particular, the following are forbidden:

    COMMIT WORK
    ROLLBACK WORK
    SUBMIT
    CALL TRANSACTION
    LEAVE TO TRANSACTION
    CALL DIALOG
    CALL SCREEN

    If, however, a database commit or a database rollback does take place, the update is canceled.

    The statement PERFORM ... ON COMMIT can be executed. The registered subroutine must be defined in the current function group.

  • It handles all SAP locks set in the current program in accordance with the value of the formal parameter _SCOPE of the corresponding lock function modules.

  • It triggers a database commit that also terminates the current database LUW and closes all database cursors.

  • It triggers the TRANSACTION_FINISHED event of the system class CL_SYSTEM_TRANSACTION_STATE. The parameter KIND is set to the value of the constant CL_SYSTEM_TRANSACTION_STATE=>COMMIT_WORK.
  • If the statement COMMIT WORK is executed by calling special programs, be aware of the following:

    • In a program executed using batch input, or if you have called the program using the USING addition of the statement CALL TRANSACTION, COMMIT WORK terminates batch input processing by default. This setting can be overwritten in the statement CALL TRANSACTION using the component RACOMMIT of the structure CTU_PARAMS, passed to the statement OPTIONS FROM.
    • In a program called using CALL DIALOG, COMMIT WORK does not initiate the processing of subroutines or updated function modules registered using PERFORM ON COMMIT and CALL FUNCTION ... IN UPDATE TASK and does not close the current SAP LUW. At the earliest, the SAP LUW can be closed by the statement COMMIT WORK in the calling program. Only transactional remote function calls or background remote function calls registered using CALL FUNCTION ... IN BACKGROUND within a dialog module are also started there using COMMIT WORK. Any bgRFCs, tRFCs, or qRFCs registered in a dialog module and not started there using COMMIT WORK are not executed.
    • The COMMIT WORK statement cannot be executed during the update or during the execution of subroutines registered using PERFORM ... {COMMIT|ROLLBACK}.
    • The statement COMMIT WORK must not be executed in units or LUWs that are managed by transactional RFC calls (bgRFC, tRFC, or qRFC).

    System Fields

    sy-subrc Meaning
    0 You have specified the AND WAIT addition, and the update of the update function modules was successful.
    4 You have specified the AND WAIT addition, and the update of the update function modules was not successful.

    The COMMIT WORK statement always sets sy-subrc to 0 if the AND WAIT addition is not specified.


    Notes

    • An SAP LUW that is not closed by COMMIT WORK, but by ending the current program or closing the internal session, has no effect on the registered procedures. Registered update function modules remain on the database but can no longer be executed.
    • The COMMIT WORK statement closes all database cursors. Open SQL statements that access a database cursor later (SELECT loop and FETCH) raise an unhandleable exception.
    • COMMIT WORK also triggers a database commit in programs called using CALL DIALOG.

    Exceptions


    Non-Catchable Exceptions

    • Cause: COMMIT WORK is not allowed within a FORM called using PERFORM ... ON COMMIT.
      Runtime Error: COMMIT_IN_PERFORM_ON_COMMIT
    • Cause: COMMIT WORK is not allowed within the update.
      Runtime Error: COMMIT_IN_POSTING