The COMMIT statement ends a unit of work and commits the database changes that were made by that unit of work.
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.
None required.
.-WORK-.
>>-COMMIT-+------+--+------+-----------------------------------><
'-HOLD-'
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.
If HOLD is omitted:
All implicitly acquired locks are released; except for object level locks required for the cursors that are not closed.
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:
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;