Question on COMMIT in DB2 COBOL program.

All sort of Mainframes Interview Questions.
Post Reply
Rahmat Ali
Registered Member
Posts: 20
Joined: Thu Feb 20, 2014 11:08 pm

Question on COMMIT in DB2 COBOL program.

Post 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.
User avatar
Anuj Dhawan
Founder
Posts: 2799
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: Question on COMMIT in DB2 COBOL program.

Post 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.
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”