COMMIT

The COMMIT statement ends a unit of work and commits the database changes that were made by that unit of work.

Invocation

This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared.

COMMIT is not allowed in a trigger program if the trigger program and the triggering program run under the same commitment definition. COMMIT is not allowed in a procedure if the procedure is called on a remote application server.

Authorization

None required.

Syntax

          .-WORK-.
>>-COMMIT-+------+--+------+-----------------------------------><
                    '-HOLD-'
 

Description

The COMMIT statement ends the unit of work in which it is executed and starts a new unit of work. It commits all changes made by ALTER, CALL, CREATE, COMMENT ON, DELETE, DROP (except DROP COLLECTION), GRANT, INSERT, LABEL ON, RENAME, REVOKE, and UPDATE statements executed during the unit of work.

Connections in the release-pending state are ended.

WORK
COMMIT WORK has the same effect as COMMIT.

HOLD

Indicates a hold on resources. If specified, currently open cursors are not closed and all resources acquired during the unit of work are held. Locks on specific rows and objects implicitly acquired during the unit of work are released.

If HOLD is omitted:

All implicitly acquired locks are released; except for object level locks required for the cursors that are not closed.

Notes

An implicit COMMIT may be performed under some circumstances. However, it is recommended that an explicit COMMIT or ROLLBACK be issued before the application ends.

A unit of work can include the processing of up to 4 million rows, including rows retrieved during a SELECT or FETCH statement33, and rows inserted, deleted, or updated as part of INSERT, DELETE, and UPDATE statements.34

The commit and rollback operations do not affect the DROP COLLECTION statement, and this statement is not, therefore, allowed in an application program that also specifies COMMIT(*CHG), COMMIT(*CS), COMMIT(*ALL), or COMMIT(*RR).

The commitment definition used by SQL is determined as follows:

Example

In a PL/I program, compiled with COMMIT (*CHG), transfer a certain amount of commission (COMM) from one employee (EMPNO) to another in the EMPLOYEE table. Subtract the amount from one row and add it to the other. Use the COMMIT WORK statement to ensure that no permanent changes are made to the database until both operations are completed successfully.

 XFRCOMM:  PROC OPTIONS(MAIN);
   EXEC SQL  BEGIN DECLARE SECTION;
     DCL  AMOUNT       FIXED DECIMAL(5,2);
     DCL  FROM_EMPNO   CHAR(6);
     DCL  TO_EMPNO     CHAR(6);
   EXEC SQL  END DECLARE SECTION;
   EXEC SQL  INCLUDE SQLCA;
   EXEC SQL  WHENEVER SQLERROR GOTO SQLERR;
   GET ...
   EXEC SQL  UPDATE EMPLOYEE
               SET COMM = COMM - :AMOUNT
               WHERE EMPNO = :FROM_EMPNO;
   EXEC SQL  UPDATE EMPLOYEE
               SET COMM = COMM + :AMOUNT
               WHERE EMPNO = :TO_EMPNO;
 FINISHED:
   EXEC SQL  COMMIT WORK;
   RETURN;
 SQLERR:
   PUT ...
   EXEC SQL  WHENEVER SQLERROR CONTINUE;    /* continue if error on rollback    */
   EXEC SQL  ROLLBACK WORK;
   RETURN;
 END XFRCOMM;


Footnotes:

33
This limit also includes:

34
Unless you specified COMMIT(*CHG) or COMMIT(*CS), in which case these rows are not included in this total.


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