Monday, 1 July 2013

LUW and SAP LUW

Transactions and Logical Units of Work  Locate the document in its SAP Library structure

In everyday language, a transaction is a sequence of actions that logically belong together in a business sense and that either procure or process data. It covers a self-contained procedure, for example, generating a list of customers, creating a flight booking, or sending reminders to customers. From the user’s viewpoint, it forms a logical unit.
The completeness and correctness of data must be assured within this unit. In the middle of a transaction, the data will usually be inconsistent. For example, when you transfer an amount in financial accounting, this must first be deducted from one account before being credited to another. In between the two postings, the data is inconsistent, since the amount that you are posting does not exist in either account. It is essential for application programmers to know that their data is consistent at the end of the transaction. If an error occurs, it must be possible to undo the changes made within a logical process.
There are three relevant concepts in this context:
Database Logical Unit of Work (LUW)
A database LUW is the mechanism used by the database to ensure that its data is always consistent.
SAP LUW
An SAP LUW is a logical unit consisting of dialog steps, whose changes are written to the database in a single database LUW.
SAP Transaction
An SAP transaction is an ABAP application program that you start using a transaction code. It may contain one or more SAP LUWs.
The following sections of this documentation explain these three terms in more detail.
***************************************************

Database Logical Unit of Work (LUW)  Locate the document in its SAP Library structure

From the point of view of database programming, a database LUW is an inseparable sequence of database operations that ends with a database commit. The database LUW is either fully executed by the database system or not at all. Once a database LUW has been successfully executed, the database will be in a consistent state. If an error occurs within a database LUW, all of the database changes since the beginning of the database LUW are reversed. This leaves the database in the state it was in before the transaction started.
This graphic is explained in the accompanying text
The database changes that occur within a database LUW are not actually written to the database until after the database commit. Until this happens, you can use a database rollback to reverse the changes. In the R/3 System, database commits and rollbacks can be triggered either implicitly or using explicit commands.
Implicit Database Commits in the R/3 System
A work process can only execute a single database LUW. The consequence of this is that a work process must always end a database LUW when it finishes its work for a user or an external call. Work processes trigger an implicit database commit in the following situations:
·        When a dialog step is completed
Control changes from the work process back to the SAP GUI.
·        When a function module is called in another work process (RFC).
Control passes to the other work process.
·        When the called function module (RFC) in the other work process ends.
Control returns to the calling work process.
·        When a WAIT statement interrupts the work process.
Control passes to another work process.
·        Error dialogs (information, warning, or error messages) in dialog steps.
Control passes from the work process to the SAP GUI.
Explicit Database Commits in the R/3 System
There are two ways to trigger an explicit database commit in your application programs:
·        Call the function module DB_COMMIT
The sole task of this function module is to start a database commit.
·        Use the ABAP statement COMMIT WORK
This statement starts a database commit, but also performs other tasks (refer to the keyword documentation for COMMIT WORK).
Implicit Database Rollbacks in the R/3 System
The following cases lead to an implicit database rollback:
·        Runtime error in an application program
This occurs whenever an application program has to terminate because of an unforeseen situation (for example, trying to divide by zero).
·        Termination message
Termination messages are generated using the ABAP statement MESSAGE with the message type A or X. In certain cases (updates), they are also generated with message types I, W, and E. These messages end the current application program.
Explicit Database Rollbacks in the R/3 System
You can trigger a database rollback explicitly using the ABAP statement ROLLBACK WORK. This statement starts a database rollback, but also performs other tasks (refer to the keyword documentation for ROLLBACK WORK).
From the above, we can draw up the following list of points at which database LUWs begin and end.
A 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.
A Database LUW Ends
·        Each time a database commit occurs. This writes all of the changes to the database.
·        Each time a database rollback occurs. This reverses all of the changes made during the LUW.
Database LUWs and Database Locks
As well as the database changes made within it, a database LUW also consists of database locks. The database system uses locks to ensure that two or more users cannot change the same data simultaneously, since this could lead to inconsistent data being written to the database. A database lock can only be active for the duration of a database LUW. They are automatically released when the database LUW ends. In order to program SAP LUWs, we need a lock mechanism within the R/3 System that allows us to create locks with a longer lifetime (refer to The R/3 Locking Concept).

*******************************************************

Logical Unit of Work (LUW )
A Logical Unit of Work (LUW or database transaction) is an inseparable sequence of database operations which must be executed either in its entirely or not at all. For the database system, it thus constitutes a unit.

LUWs help to guarantee database integrity. When an LUW has been successfully concluded, the database is once again in a correct state. If, however, an error occurs within an LUW, all database changes made since the beginning of the LUW are canceled and the database is then in the same state as before the LUW started.

In the R/3 System, there are three terms frequently used in this context:
Database Logical Unit of Work (LUW)
A database LUW is the mechanism used by the database to ensure that its data is always consistent.
SAP LUW
An SAP LUW is a logical unit consisting of dialog steps, whose changes are written to the database in a single database LUW.
SAP Transaction
An SAP transaction is an application program that you start using a transaction code. It may contain one or more SAP LUWs.

No comments:

Post a Comment