What is LUW? How LUW works? Different types of LUW?

 

What is LUW? How LUW works? Different types of LUW?

LUW (Logical Unit of Work).

It's basically a required time for a system to complete the process of Database (DB) data modifications. Either full/rollback all changes done in Database (DB) data. The main purpose of LUW is to ensure that the data consistency in the system.

There are two types of LUW’s available:

1.Database LUW

2.SAP LUW

1.Database LUW:

LUW’s consists of various database operations like Insert/Update/ Delete & Modify on data which make changes at database level. This used to make data consistent.

Following is the list of points at which database LUW's begin and end.

Database LUW Begins

  • When each time a dialog step starts,  when the dialog step is sent to the work process.
  • When ever the previous database, LUW ends in a database commit.
  • When ever the previous database, LUW ends in a database rollback.

Database LUW Ends

  • Each time a database commit occurs , this will writes all the changes to the database.
  • Each time a database rollback occurs, this will reverses all the changes made during the LUW.

2.SAP LUW:

Un-like a database LUW's, an SAP LUW's can span multiple dialog steps & be executed using a series of different work processes. If an SAP LUW contains database changes, we should either write all of them or none to the database. Ensure that this happens, we must include a database commit when your transaction has ended successfully & a database rollback in case the program detects an error.

Since database changes from a database LUW's cannot be reversed in a subsequent database LUW's, we must make all the database changes for the SAP LUW's in a single database LUW's. To maintain data integrity, we must bundle all your database changes in the final database LUW's of the SAP LUW's.

Bundling technique for the database changes within an SAP LUW's ensures that you can still reverse them. It means that you can distribute a transaction across more than one work processes.

Below were the various bundling techniques used in SAP are -

1.Bundling using function modules (update)
Statement CALL FUNCTION … IN UPDATE TASK  - used to register an update function module(FM) 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)
Statement CALL FUNCTION … IN BACKGROUND TASK  -  used to register a remote enabled function module(RFC) for later asynchronous execution in the background and through the RFC interface (transactional RFC).

Note
Function module(FM) can be specified as either an update function module(FM) or as remote enabled, but not both at the same time. The update is used to realize SAP LUW's within AS ABAP, while transactional RFC creates LUW's in distributed system.

  1. Bundling using subroutines
    The statement PERFORM … ON COMMIT  - used to register a subroutine for later execution in a different work processes.

For example: Lets consider you are trying to save data through various function, you are completing data creation in database but to update database explicit commit work is required .We must use Rollback work to reverse the changes happened at database level(DB level).

DATA(values) = VALUE demo_update_tab( ).
EXPORT value = valuesTO 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

Notes

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.

Conclusion:

Developers should always keep the LUW concept in mind while designing/developing custom code to avoid any kind of data inconsistency-related issues.

Also there is one further type of LUW: The RAP LUW.

RAP LUW: The LUW in RAP is the sum of all operations and workflows that are used to transfer data from one consistent state to another. A RAP LUW begins with creating new data on the RAP transactional buffer or by retrieving data from the database to the transactional buffer. It is terminated with COMMIT ENTITIES or ROLLBACK ENTITIES.


Comments

Popular posts from this blog

EVENTS IN INTERACTIVE REPORTS OF SAP ABAP

Differences Between Classic & New BAdIs :

SAP ABAP Fresher Resume/ CV Writing Format..