ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → Data Consistency → SAP LUW → SAP LUW, Examples
SAP LUW, UPDATE TASK
This example demonstrates how SAP LUWs are bundled using update function modules.
Other versions:
7.31 | 7.40 | 7.54
Source Code
CALL FUNCTION 'DEMO_UPDATE_DELETE' IN UPDATE TASK.
WAIT UP TO 1 SECONDS. "<--- Roll-out/Roll-in with database commit
DATA(values) = VALUE demo_update_tab(
( 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 ) ).
CALL FUNCTION 'DEMO_UPDATE_INSERT' IN UPDATE TASK
EXPORTING
values = values.
COMMIT WORK AND WAIT. "<---- End SAP LUW and start a new one
SELECT *
FROM demo_update
INTO TABLE @DATA(result).
cl_demo_output=>write( result ).
SET UPDATE TASK LOCAL.
DELETE TABLE values WITH TABLE KEY id = 'X'.
CALL FUNCTION 'DEMO_UPDATE_DELETE' IN UPDATE TASK
EXPORTING
values = values.
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 ) ).
CALL FUNCTION 'DEMO_UPDATE_MODIFY' IN UPDATE TASK
EXPORTING
values = values.
WAIT UP TO 1 SECONDS. "<--- Roll-out/Roll-in with database commit
values = VALUE #(
( id = 'Y' col1 = 1111 col2 = 2111 col3 = 3111 col4 = 4111 ) ).
CALL FUNCTION 'DEMO_UPDATE_UPDATE' IN UPDATE TASK
EXPORTING
values = values.
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
The example shows a program divided into segments by switching the work process. An implicit
database commit is
performed at the end of each segment. Here, the work process is switched using the statement WAIT UP TO
. In real programs, a switch of this kind can have
many different causes.
This program makes writes on the database that are moved to different
update function
modules. The statement COMMIT WORK
executes the function modules registered up until now using the
CALL FUNCTION IN UPDATE TASK
. This entails closing one SAP LUW and opening another.
In the first statement, COMMIT WORK
, the addition AND WAIT
specifies
synchronous updates,
where one update function module must be completed before the next one can start. In the second SAP LUW, the statement SET UPDATE TASK
switches
local updates on, which are always performed synchronously.