What is LUW? How LUW works? Different types of LUW?
In this blogpost, I will try to give you brief idea about LUW (Logical Unit of Work).
It is basically required time for system to complete the process of Database (DB) data modification. Either Full or Rollback all changes done in DB data. Main purpose of LUW is to ensure data consistency in system.
There are two types of LUW’s available:
LUW’s consists of various database operations like Insert, Update, Delete and Modify on data which make changes at database level. It is used to make data consistent.
Following is list of points at which database LUWs begin and end.
Database LUW Begins
- Each time a dialog step starts (when the dialog step is sent to the work process).
- Whenever the previous database LUW ends in a database commit.
- Whenever the previous database LUW ends in a database rollback.
Database LUW Ends
- Each time a database commit occurs. This writes all the changes to the database.
- Each time a database rollback occurs. This reverses all the changes made during the LUW.
Unlike a database LUW, an SAP LUW can span multiple dialog steps and be executed using a series of different work processes. If an SAP LUW contains database changes, you should either write all of them or none to the database. Ensure that this happens, you must include a database commit when your transaction has ended successfully, and a database rollback in case the program detects an error.
However, since database changes from a database LUW cannot be reversed in a subsequent database LUW, you must make all the database changes for the SAP LUW in a single database LUW. To maintain data integrity, you must bundle all your database changes in the final database LUW of the SAP LUW.
The bundling technique for database changes within an SAP LUW ensures that you can still reverse them. It also means that you can distribute a transaction across more than one work process.
Below are the various Bundling techniques used in SAP:
1.Bundling using function modules (update)
The statement CALL FUNCTION … IN UPDATE TASK is used to register an update function module for later execution in an update work process (synchronous and asynchronous update) or in the current work process (local update).
2.Bundling using function modules (transactional RFC)
The statement CALL FUNCTION … IN BACKGROUND TASK is used to register a remote-enabled function module for later asynchronous execution in the background and through the RFC interface (transactional RFC).
A function module can be specified as either an update function module or as remote-enabled, but not both at the same time. The update is used to realize SAP LUWs within AS ABAP, while transactional RFC creates LUWs in distributed systems.
- Bundling using subroutines
The statement PERFORM … ON COMMIT is used to register a subroutine for later execution in a different work process.
Let’s Consider we are trying to save data through various functions, we are completing data creation in database but to update database explicit commit work is requires or else we must use Rollback work to reverse the change happened at database level.
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
The statements COMMIT WORK and ROLLBACK WORK determine the limits of a SAP LUW. An ABAP program can be divided into any number of SAP LUWs, wherein the end of an ABAP program always ends the last SAP LUW as well. By calling ABAP programs using CALL TRANSACTION or SUBMIT … AND RETURN, SAP LUWs can be nested.
If a program is ended or an internal session closed using SUBMIT without AND RETURN or LEAVE TO TRANSACTION and procedures are still registered in the current SAP LUW, then the SAP LUW is ended without the procedures being called or rolled back.
Developers should always keep the LUW concept in mind while designing/developing custom code to avoid any kind of data inconsistency-related issues.
Please like, share, follow and comment for more such blogpost.