Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  Data Consistency →  SAP LUW →  SAP LUW, Examples 

SAP LUW, ON COMMIT

This example demonstrates how SAP LUWs are bundled using subroutines.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(values) = VALUE demo_update_tab( ).
    EXPORT values = values TO MEMORY ID 'DEL'.
    PERFORM delete ON COMMIT.

    WAIT UP TO 1 SECONDS. "<--- Roll-out/Roll-in with database commit

    values = VALUE #(
      ( id = 'X' col1 = 100 col2 = 200 col3 = 300 col4 = 400 )
      ( id = 'Y' col1 = 110 col2 = 210 col3 = 310 col4 = 410 )
      ( id = 'Z' col1 = 120 col2 = 220 col3 = 320 col4 = 420 ) ).

    EXPORT values = values TO MEMORY ID 'INS'.
    PERFORM insert ON COMMIT .

    COMMIT WORK. "<---- End SAP LUW and start a new one

    SELECT *
           FROM demo_update
           INTO TABLE @DATA(result).
    cl_demo_output=>write( result ).

    DELETE TABLE values WITH TABLE KEY id = 'X'.

    EXPORT values = values TO MEMORY ID 'DEL'.
    PERFORM delete ON COMMIT.

    WAIT UP TO 1 SECONDS. "<--- Roll-out/Roll-in with database commit

    values = VALUE #(
      ( id = 'Y' col1 = 1100 col2 = 2100 col3 = 3100 col4 = 4100 )
      ( id = 'Z' col1 = 1200 col2 = 2200 col3 = 3200 col4 = 4200 ) ).

    EXPORT values = values TO MEMORY ID 'MOD'.
    PERFORM modify ON COMMIT.

    WAIT UP TO 1 SECONDS. "<--- Roll-out/Roll-in with database commit

    values = VALUE #(
      ( id = 'Y' col1 = 1111 col2 = 2111 col3 = 3111 col4 = 4111 ) ).

    EXPORT values = values TO MEMORY ID 'UPD'.
    PERFORM update ON COMMIT .

    COMMIT WORK. "<---- End SAP LUW and start a new one

    SELECT *
           FROM demo_update
           INTO TABLE @result.
    cl_demo_output=>write( result ).

    cl_demo_output=>display( ).

Description

This example works mainly in the same way as the executable example for updates, but also demonstrates bundling using subroutines registered using the statement PERFORM ON COMMIT.

No parameters can be passed in this type of bundling, which means that the internal table used in the database writes is passed using the statements EXPORT and IMPORT and the ABAP Memory.

The registered subroutines are called using the statements COMMIT WORK, which can be monitored using ABAP Debugger. The subroutines themselves do not implement the writes and call methods of a class instead (as recommended).