SAP LUW

Embed Size (px)

Citation preview

  • 8/2/2019 SAP LUW

    1/6

    Database Logical Unit of Work (LUW)From the point of view of database programming, a database LUW is an inseparable sequence ofdatabase 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 willbe in a consistent state. If an error occurs within a database LUW, all of the database changes since thebeginning of the database LUW are reversed. This leaves the database in the state it was in before thetransaction started.

    The database changes that occur within a database LUW are not actually written to the database untilafter the database commit. Until this happens, you can use a database rollback to reverse the changes.

    In the SAP System, database commits and rollbacks can be triggered either implicitly or using explicitcommands.

    Implicit Database Commits

    A work process can only execute a single database LUW. The consequence of this is that a work processmust always end a database LUW when it finishes its work for a user or an external call. Work processestrigger an implicit database commit in the following situations:

    When a dialog step is completedControl 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 aWAIT 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

    There are two ways to trigger an explicit database commit in your application programs:

    http://help.sap.com/erp2005_ehp_04/helpdata/en/41/7af4bca79e11d1950f0000e82de14a/frameset.htmhttp://help.sap.com/erp2005_ehp_04/helpdata/en/41/7af4bca79e11d1950f0000e82de14a/frameset.htmhttp://help.sap.com/erp2005_ehp_04/helpdata/en/41/7af4bca79e11d1950f0000e82de14a/frameset.htm
  • 8/2/2019 SAP LUW

    2/6

    Call the function module DB_COMMITThe sole task of this function module is to start a database commit.

    Use the ABAP statement COMMIT WORKThis statement starts a database commit, but also performs other tasks (refer to the keyworddocumentation for COMMIT WORK).

    Implicit Database RollbacksThe following cases lead to an implicit database rollback:

    Runtime error in an application programThis occurs whenever an application program has to terminate because of an unforeseen situation(for example, trying to divide by zero).

    Termination messageTermination messages are generated using the ABAP statementMESSAGE with the message type

    A or X. In certain cases (updates), they are also generated with message types I, W, and E. Thesemessages end the current application program.

    Explicit Database Rollbacks

    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 keyworddocumentation 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. Thedatabase system uses locks to ensure that two or more users cannot change the same datasimultaneously, since this could lead to inconsistent data being written to the database. A database lockcan only be active for the duration of a database LUW. They are automatically released when thedatabase LUW ends. In order to program SAP LUWs, we need a lock mechanism within the R/3 Systemthat allows us to create locks with a longer lifetime (refer toThe SAP Locking Concept).

    http://help.sap.com/erp2005_ehp_04/helpdata/en/41/7af4c5a79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/erp2005_ehp_04/helpdata/en/41/7af4c5a79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/erp2005_ehp_04/helpdata/en/41/7af4c5a79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/erp2005_ehp_04/helpdata/en/41/7af4c5a79e11d1950f0000e82de14a/content.htm
  • 8/2/2019 SAP LUW

    3/6

    SAP LUW

    Die VerbuchungsverwaltungThe Open SQL statements INSERT, UPDATE, MODIFY, and DELETE allow you to program database

    changes that extend over several dialog steps. Even if you have not explicitly programmed a databasecommit, the implicit database commit that occurs after a screen has been processed concludes thedatabase LUW. The following diagram shows the individual database LUWs in a typical screen sequence:

    Under this procedure, you cannot roll back the database changes from previous dialog steps. It istherefore only suitable for programs in which there is no logical relationship between the individual dialogsteps.

    However, the database changes in individual dialog steps normally depend on those in other dialog steps,and must therefore all be executed or rolled back together. These dependent database changes formlogical units, and can be grouped into a single database LUW using the bundling techniques listed below.

    A logical unit consisting of dialog steps, whose changes are written to the database in a single databaseLUW is called an SAP LUW. Unlike a database LUW, an SAP LUW can span several dialog steps, andbe executed using a series of different work processes. If an SAP LUW contains database changes, you

    should either write all of them or none at all to the database. To ensure that this happens, you mustinclude a database commit when your transaction has ended successfully, and a database rollback incase the program detects an error. However, since database changes from a database LUW cannot bereversed in a subsequent database LUW, you must make all of the database changes for the SAP LUWin a single database LUW. To maintain data integrity, you must bundle all of you database changes in thefinal database LUW of the SAP LUW. The following diagram illustrates this principle:

    http://help.sap.com/saphelp_46c/helpdata/en/e5/de870535cd11d3acb00000e83539c3/frameset.htmhttp://help.sap.com/saphelp_46c/helpdata/en/e5/de870535cd11d3acb00000e83539c3/frameset.htmhttp://help.sap.com/saphelp_46c/helpdata/en/e5/de870535cd11d3acb00000e83539c3/frameset.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4bfa79e11d1950f0000e82de14a/frameset.htmhttp://help.sap.com/saphelp_46c/helpdata/en/e5/de870535cd11d3acb00000e83539c3/frameset.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4bfa79e11d1950f0000e82de14a/frameset.htmhttp://help.sap.com/saphelp_46c/helpdata/en/e5/de870535cd11d3acb00000e83539c3/frameset.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4bfa79e11d1950f0000e82de14a/frameset.htmhttp://help.sap.com/saphelp_46c/helpdata/en/e5/de870535cd11d3acb00000e83539c3/frameset.htm
  • 8/2/2019 SAP LUW

    4/6

    The bundling technique for database changes within an SAP LUW ensures that you can still reversethem. It also means that you can distribute a transaction across more than one work process, and evenacross more than one R/3 System. The possibilities for bundling database changes within an SAP LUWare listed below:

    The simplest form of bundling would be to process a whole application within a single dialog step. Here,

    the system checks the users input and updates the database without a database commit occurring withinthe dialog step itself. Of course, this is not suitable for complex business processes. Instead, the R/3Basis system contains the following bundling techniques.

    Bundling using Function Modules for Updates

    If you call a function module using the CALL FUNCTION... IN UPDATE TASK statement, the functionmodule is flagged for execution using a special update work process. This means that you can write theOpen SQL statements for the database changes in the function module instead of in your program, andcall the function module at the point in the program where you would otherwise have included thestatements. When you call a function module using the IN UPDATE TASK addition, it and its interfaceparameters are stored as a log entry in a special database table called VBLOG.

    The function module is executed using an update work process when the program reaches the COMMITWORK statement. After the COMMIT WORK statement, the dialog work process is free to receive furtheruser input. The dialog part of the transaction finishes with the COMMIT WORK statement. The updatepart of the SAP LUW then begins, and this is the responsibility of the update work process. The SAPLUW is complete once the update process has committed or rolled back all of the database changes.

    For further information about how to create function modules for use in update, refer toCreating FunctionModules for Database Updates

    http://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htm
  • 8/2/2019 SAP LUW

    5/6

    During the update, errors only occur in exceptional cases, since the system checks for all logical errors,such as incorrect entries, in the dialog phase of the SAP LUW. If a logical error occurs, the program canterminate the update using the ROLLBACK WORK statement. Then, the function modules are not called,and the log entry is deleted from table VBLOG. Errors during the update itself are usually technical, forexample, memory shortage. If a technical error occurs, the update work process triggers a databaserollback, and places the log entry back into VBLOG. It then sends a mail to the user whose dialogoriginally generated the VBLOG entry with details of the termination. These errors must be corrected bythe system administrator. After this, the returned VBLOG entries can be processed again.For further information about update administration, see Update AdministrationThis technique of bundling database changes in the last database LUW of the SAP LUW allows you toupdate the database asynchronously, reducing the response times in the dialog work process. You can,for example, decouple the update entirely from the dialog work process and use a central update workprocess on a remote database server.Bundling Using Subroutines

    The statement PERFORM ON COMMIT calls a subroutine in the dialog work process. However, it is not

    executed until the system reaches the next COMMIT WORK statement. Here, as well, the ABAPstatement COMMIT WORK defines the end of the SAP LUW, since all statements in a subroutine calledwith PERFORM ON COMMIT that make database changes are executed in the database LUW of thecorresponding dialog step.

    The advantage of this bundling technique against CALL FUNCTION... IN UPDATE TASK is betterperformance, since the update data does not have to be written into an extra table. The disadvantage,however, is that you cannot pass parameters in a PERFORM... ON COMMIT statement. Data is passedusing global variables and ABAP memory. There is a considerable danger of data inconsistency whenyou use this method to pass data.

    http://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htm
  • 8/2/2019 SAP LUW

    6/6

    Bundling Using Function Modules in Other R/3 Systems

    Function modules that you call using CALL FUNCTION... IN BACKGROUND TASK DESTINATION... areregistered for background execution in another R/3 System when the program reaches the next COMMITWORK statement (using Remote Function Call). After the COMMIT WORK, the dialog process does notwait for these function modules to be executed (asynchronous update). All of the function modules that

    you register in this way are executed together in a single database LUW. These updates are useful, forexample, when you need to maintain identical data in more than one database.

    For further details, refer to the keyword documentation.

    For more details of RFC processing, refer to the Remote Communicationssection of the BasisServicesdocumentation.

    http://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htmhttp://help.sap.com/saphelp_46c/helpdata/en/41/7af4daa79e11d1950f0000e82de14a/content.htm