Page 1 of 1

Question on COMMIT in DB2 COBOL program.

Posted: Sun Sep 20, 2015 2:07 pm
by Rahmat Ali
Interviewer asked a question that in a DB2/COBOL program, we want to update a table and we missed to code COMMIT in the program. Will the table gets updated when the program executes successfully?

Though I answered that when program executes successfully then COMMIT will happen on its own. Hence the table should get updated. But I always thought that without an explicit COMMIT in the program, changes are not permanent. Without coding COMMIT also does it works? Can someone please elaborate on this. Will appreciate your help.

Re: Question on COMMIT in DB2 COBOL program.

Posted: Fri Oct 02, 2015 1:54 pm
by Anuj Dhawan
Your answer is correct.

DB2, COBOL and zOS all together makes a logical unit-of-work (called UOW usually) for a given COBOL-DB2 program. If the program executes successfully, the unit-of-work completes successfully, DB2 issues an implicit COMMIT and all the changes are written to stones.

On the other hand, not issuing an explicit COMMIT is a bad idea of programming. If your program abends, for example there is some system abend like an S222, when you cancel the batch Job - DB2 will treat the thread as ABORTed and will rollback changes to the last commit point (if specified or will go back to the start of the unit-of-work if you don't commit).

On the other hand, if your program encounters a logical problem - a data problem or business logic problem - and the program does not ABEND instead simply sets a bad return code and terminates. Then in this case, for DB2 sub-system unless your program explicitly requests a ROLLBACK, it will perform an implicit (automatic) COMMIT at program termination. And it might not be correct logical ending of the unit-of-work.