Inserts are not finished when SQLCODE is 0. They become durable when the unit of recovery commits. In DB2 for z/OS the statement you write in COBOL is not always EXEC SQL COMMIT — CICS, IMS, and RRSAF want their own syncpoint verbs so every recoverable resource (Db2, VSAM, MQ, IMS DB) goes together. This page is the COBOL programmer’s map: batch COMMIT/ROLLBACK, CICS/IMS units of work, and when Db2 commits for you if you forget.
A unit of recovery (UR) is the set of Db2 changes that will commit or roll back together. A unit of work (UOW) in CICS or IMS is the same idea at the transaction-manager level and can include non-Db2 resources. In a TSO batch program that only touches Db2, UR and UOW are practically the same thing and SQL COMMIT ends both.
After COMMIT:
After ROLLBACK (without TO SAVEPOINT): all relational changes of the UR are undone, locks release, and cursors close — including WITH HOLD for the SQL ROLLBACK statement.
Under the TSO attachment (DSN RUN) and the call attachment facility (CAF), SQL COMMIT and SQL ROLLBACK are the right verbs.
1234567891011121314EXEC SQL UPDATE DSN8C10.EMP SET SALARY = SALARY * 1.03 WHERE WORKDEPT = :WS-DEPT END-EXEC. IF SQLCODE = 0 EXEC SQL COMMIT END-EXEC ELSE EXEC SQL ROLLBACK END-EXEC END-IF.
Check SQLCODE after COMMIT too. A failed COMMIT is not “probably fine.” Batch programs that update many rows should COMMIT on a count or key boundary (every 500 rows, every account) so a restart does not replay an hour of uncommitted work and so you do not hold locks that stall online transactions.
WITH HOLD cursors survive SQL COMMIT: reopen is unnecessary, but you must FETCH again before WHERE CURRENT OF. If you commit inside a FETCH loop without WITH HOLD, the next FETCH fails because the cursor is closed — CLOSE is optional at that point, OPEN is required again.
123EXEC SQL ROLLBACK END-EXEC.
Use ROLLBACK when a business rule fails after you already changed rows, or after SQLCODE -913 (timeout/deadlock without automatic rollback). After -911 Db2 already rolled back the UR; issuing another ROLLBACK is usually harmless but the data changes are already gone. Savepoints (ROLLBACK TO SAVEPOINT) undo part of a UR without ending it — useful in complex batch, and one of the few SQL rollback forms CICS/IMS still allow, for Db2 changes only.
| Environment | Commit | Rollback |
|---|---|---|
| TSO / DSN RUN | EXEC SQL COMMIT | EXEC SQL ROLLBACK |
| CAF (DSNALI) | EXEC SQL COMMIT | EXEC SQL ROLLBACK |
| CICS (DSNCLI) | EXEC CICS SYNCPOINT | EXEC CICS SYNCPOINT ROLLBACK |
| IMS (DFSLI000) | CHKP / SYNC | ROLB / ROLL |
| RRSAF (DSNRLI) | SRRCMIT (RRS) | SRRBACK (RRS) |
IBM documents that SQL COMMIT and SQL ROLLBACK are not valid in CICS. You get SQLCODE -925 (COMMIT) or -926 (ROLLBACK). CICS is the coordinator. Db2 participates through two-phase commit with any other recoverable resources on the task.
12345EXEC CICS SYNCPOINT END-EXEC. EXEC CICS SYNCPOINT ROLLBACK END-EXEC.
A unit of work in CICS ends:
If the task abends, CICS rolls back recoverable resources, including Db2. SYNCPOINT in the middle of a pseudo-conversational design commits what you just did; the next task is a new UOW. Do not expect a WITH HOLD cursor to remain after EOT.
Message-driven and batch DL/I programs must not issue SQL COMMIT or SQL ROLLBACK (again -925/-926). Use:
IBM warns batch DL/I programs to checkpoint before the program ends. If the job step fails after the COBOL program returned but before IMS finished its own commit, you can get Db2 committed and IMS not, or indoubt URs. Unique checkpoint IDs plus XRST on restart are the IMS recovery pattern — SQL COMMIT cannot substitute.
Programs that use the Recoverable Resource Services attachment (DSNRLI) should commit with SRRCMIT and back out with SRRBACK, not SQL COMMIT. -925/-926 apply here too. RRSAF is how many stored procedures and mixed-resource batch jobs join an RRS-coordinated UOW.
You will hear “it commits when the program ends.” That is only true in some attachments and only on normal termination:
Implicit commit is a safety net, not a design. A 2-hour UPDATE without checkpoints holds locks, fills the log, and makes restart painful. Issue COMMIT (or SYNCPOINT/CHKP) at documented intervals. After an implicit commit you cannot ROLLBACK the work that already committed — only compensating transactions.
Commit frequency is a lock and restart decision:
Restartable COBOL batch stores the last committed key and skips to that key on rerun. That only works if you COMMIT after writing the checkpoint record in the same UR as the Db2 changes — or you use IMS checkpoints that include your restart token.
Changing a Db2 row without COMMIT is like stacking blocks on a table but not gluing them. COMMIT is the glue. ROLLBACK knocks the un-glued blocks off. In the batch classroom the teacher (Db2) will glue whatever is left when you leave the room nicely. If you knock the table over (abend), the un-glued blocks fall. In the CICS playground a different teacher (CICS) holds the glue bottle; you must ask that teacher (SYNCPOINT), not the Db2 teacher, or the VSAM blocks and the Db2 blocks will not stick at the same time.
1. In a CICS COBOL program you should commit with:
2. In TSO/batch COBOL attached through DSN or CAF, SQL COMMIT:
3. SQLCODE -926 means:
4. When does Db2 commit automatically in batch TSO/CAF?
5. IMS batch DL/I programs should commit with: