Commit and rollback
Makes a set of changes permanent together, or undoes them together.
Also written unit of work, syncpoint, two-phase commit
Why it matters. Moving money changes two accounts. If only one change stayed, the bank would be wrong by that amount.
See it
Step one: take money from one account.
Syntax
COMMIT ROLLBACK EXEC CICS SYNCPOINT [ROLLBACK] END-EXEC
- COMMIT
- Make the changes permanent and let go of the locks.
- ROLLBACK
- Undo everything since the last commit.
- SAVEPOINT / ROLLBACK TO SAVEPOINT
- Undo back to a marked point, not all the way.
- SYNCPOINT
- The CICS command that commits. Under CICS you use this, not SQL COMMIT.
Try it COMMIT
- 1
Take 100 from ACCT0001, then change your mind. You're in the SYSIN lines of job ROLLTST, a DSNTEP2 step. Below you is a SELECT that reads the balance. Write the statement that takes 100 off the balance of ACCT0001.
SYSIN UPDATE M1B.ACCOUNTS SET BALANCE = BALANCE - 100 WHERE ACCTNO = 'ACCT0001'; - 2
Now undo it. Write the statement that takes the update back.
SYSIN ROLLBACK; - 3
Submit the job ROLLTST from your DEV JCL library.
SUBMIT 'ZB0001.DEV.JCL(ROLLTST)' - 4
Read the output of the job. Look at the balance at the end.
OUTPUT ROLLTST - 5
Now do it for real. You're in the SYSIN lines of job COMMITTX. It has the same UPDATE above you and the same SELECT below. Write the statement that makes the change permanent.
SYSIN COMMIT; - 6
Submit the job COMMITTX from your DEV JCL library.
SUBMIT 'ZB0001.DEV.JCL(COMMITTX)' - 7
Read the output of the job. Look at the balance at the end.
OUTPUT COMMITTX
Remember
- COMMIT makes the changes permanent. ROLLBACK undoes them.
- A unit of work ends at a COMMIT or a ROLLBACK. A program that ends normally commits, and one that abends is rolled back. A COMMIT also lets go of the locks.
- A debit and its credit belong in the same unit of work.
The usual mistake
COMMIT after the debit, and again after the credit
If the program stops between the two, money has left one account and not reached the other.
One COMMIT, after both changes
On real z/OS
In MF/OS the unit of work is one run: a single SQL run, or one COBOL program, and it commits when it ends. On real Db2 a unit of work can span many statements. Under CICS, an SQL COMMIT is not allowed (SQLCODE -925): use EXEC CICS SYNCPOINT.
Where can I practise Commit and rollback?
Right here, at ZedBank. You take a junior job at a simulated bank and use Commit and rollback in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- CICS transactionOne unit of online work in CICS: the whole exchange of receiving a request, doing the work, and sending a response.
- CICSThe transaction manager that runs online mainframe applications, and the software behind a great many screens bank staff use.
- DB2 for z/OSIBM's relational database on the mainframe, where a great deal of the world's banking and insurance data is stored.
- Online transaction processingHandling many small pieces of work in real time while someone waits: a card payment, a balance check, a seat booking.
- Batch processingRunning work in bulk, without anyone watching, usually on a schedule. The overnight run that settles a day of transactions.