DB2 Server for VSE & VM: Application Programming


Using Logical Units of Work

Defining the Logical Unit of Work

A logical unit of work (LUW) is a sequence of SQL statements

(possibly with intervening host language code) that the database manager treats as a whole.

The system ensures the consistency of data at the LUW level, by ensuring that either all operations within an LUW are completed, or none are completed.

Suppose, for example, that money is to be deducted from one account and added to another. If both these updates are placed in a single LUW, and if a system failure occurs while they are in progress, then when the system is restarted, the data is automatically restored to the state it was in before the LUW began. If a program error occurs, all changes made by the statement in error are restored. Work done in the LUW prior to execution of the statement in error is not undone, unless you specifically roll it back. To determine whether the LUW terminated automatically, you should check the value of SQLWARN6 in the SQLCA. See Using the Automatic Error-Handling Facilities for more information.

Beginning a Logical Unit of Work

An LUW is begun implicitly with the first executable SQL statement and is ended by either a COMMIT or a ROLLBACK statement, or when the program ends.

The following are examples of statements that do not start a logical unit of work:

   BEGIN DECLARE SECTION          INCLUDE SQLCA
   END DECLARE SECTION            INCLUDE SQLDA
   WHENEVER

An executable SQL statement always occurs within an LUW. If such a statement is encountered after you end an LUW, it automatically starts another.

Considering the CICS/VSE Logical Unit of Work (DB2 Server for VSE Only)

For logical unit of work processing to function as described in this manual, ALL CICS/VSE INSTALLATIONS MUST DO THE FOLLOWING:

  1. The CICS System Initialization Table (DFHSIT) must be generated with DBP=YES.

    If this is not done, the CICS/VSE system attempts to commit all changes, regardless of whether a rollback was intended. (Alternatively, DBP=xx can be specified if a suffixed version of the CICS/VSE Dynamic Backout Program is being used.)

  2. In addition, each online application that has access to the application server must have Dynamic Transaction Backout set to YES. You can do this by |specifying DTB=YES in the resource definition online (RDO) facility |(or DFHCSDUP).

    Your installation can specify DTB=YES on the initial |DFHCSDUP statement, or DTB=YES on each entry |DFHCSDUP statement for applications having access to the database manager.
    Note:DTB=NO is not supported in RDO. All transactions defined in the macro with DTB=NO are handled in RDO as if DTB=YES had been specified. For more information, see the CICS/VSE Resource Definition (Online) manual.

For more information, refer to the CICS/VSE System Programming Reference or the CICS/VSE Resource Definition (Macro) manuals.

Ending a Logical Unit of Work

When you end an LUW, you can use either the COMMIT statement to save its changes, or the ROLLBACK statement to ensure that these changes are not saved.

Using the COMMIT Statement

This statement ends the current LUW, and commits any changes made during it.

Changes should be committed as soon as application requirements permit. In particular, programs should be written so that uncommitted changes are not held over a terminal read request, which can result in locks and other resources being held for a long time.

Each application program must explicitly end its LUW before terminating. If you do not end it explicitly, the system automatically commits (upon successful termination of the program) all changes made by the program during its pending LUW unless one of the following conditions occurs:

See Creating the Epilog and Using the Automatic Error-Handling Facilities for more information about program termination.

Note:The COMMIT statement has no effect on the contents of host variables.

Using the ROLLBACK Statement

This statement ends the current LUW, and restores the data to the state it was in prior to the LUW beginning.
Note:The ROLLBACK statement has no effect on the contents of host variables.

Under some circumstances, the system automatically backs out of an LUW. Refer to Automatically Locking Dbspaces for more information.
Note:If you use a ROLLBACK statement in a routine that was entered because of an error or warning and you use the SQL WHENEVER statement, specify WHENEVER SQLERROR CONTINUE and WHENEVER SQLWARNING CONTINUE before the ROLLBACK. This avoids a program loop if the ROLLBACK fails with an error or warning.

The ROLLBACK statement should not be issued if a severe error occurs (indicated by an S in the SQLWARN0 field of the SQLCA). The only statement that can be issued after a severe error is a CONNECT statement.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]