Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Explcit ROLLBACK used in COBOL code.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Wed Mar 23, 2011 12:24 am    Post subject: Explcit ROLLBACK used in COBOL code.
Reply with quote

I want to know what is the role of using explicit ROLLBACK in a cobol program in the error handling paragraph..In my program when SQLCODE not = 0 / 100 then they do an explicit ROLLBACK and abort the module throwing the error message.

As far as my knowledge when the program terminates abnormally then the rollback hapens automatically in DB2 right? Pls correct me if my understanding is wrong!

Thanks,
Back to top
View user's profile Send private message

Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Wed Mar 23, 2011 1:09 pm    Post subject:
Reply with quote

DB2 will roll back the current unit of work when the program is terminated abnormally, so the explicit ROLLBACK statement is redundant.

There could be application designs that will require explicit ROLLBACK of the business transactions performed, followed by some updates to e.g. logging tables. These updates must then be explicitly committed before abending the program, as abending will still terminate the current unit of work with rollback.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Wed Mar 23, 2011 1:17 pm    Post subject:
Reply with quote

normally,
if a program abends,
you do not have the opportunity to issue any instructions.

a non-zero sql code is not a program abend. it is the result of a db2 process,
where a <zero return code indicates the sql was not successful
and a >zero return code indicates a warning.

an explicit roll-back allows an application to terminate normally,
which is a much less resource intensive process than forcing an abend in a module,
which requires the op-system to go thru tons of code to process the abend.
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Wed Mar 23, 2011 11:44 pm    Post subject:
Reply with quote

Scenario
=========
Let me explain:
In the cobol program which I am refering to, when the SQLCODE from an update table statement is NOT = 0 or 100 they do 2 things.

a) First the rollback para is performed,In which they do the an explicit ROLLBACK and do a final update on the table.

b)Next they call a subroutine to force abend the program displaying the query information which failed and the SQLCODE.


Problem
==========
But the problem is when they display the SQLCODE then it shows 0 in the spool, because the rollback statement's SQLCODE overiddes the original SQLCODE returned from the update query. This is meisleading and wrong..

Understanding
==========
So I am thinking is it wise to eliminate the explicit rollback from the code, as the DB2 should automatically do a rollback when the update query fails and the pgm terminates. If I eliminate the explicit rollback then the SQLCODE displayed in the spool will be corrected.

Please correct me if my understanding is wrong!

Thank You
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Wed Mar 23, 2011 11:47 pm    Post subject:
Reply with quote

Why not just save the SQLCODE in another variable BEFORE doing the ROOLBACK and displaying this other variable? That would probably require much less work than actually figuring out the impact of changing the way the code works now with the ROLLBACK.
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Wed Mar 23, 2011 11:49 pm    Post subject:
Reply with quote

Dick, your signature is really funny icon_biggrin.gif
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Wed Mar 23, 2011 11:59 pm    Post subject:
Reply with quote

Robert Sample wrote:
Why not just save the SQLCODE in another variable BEFORE doing the ROOLBACK and displaying this other variable? That would probably require much less work than actually figuring out the impact of changing the way the code works now with the ROLLBACK.


Hi Robert,

Definately a good idea icon_smile.gif Will try this..but it may become a little messy because they use a standard subroutine to force abend the pgm..and that routine takes the value directly from SQLCA..

I will try the following logic.

1. Run update query
2. Check if SQLCODE NOT = 0
a) move SQLCODE to WS-SQLCODE
b) peform explicit ROLLBACK + Final UPDATE
c) Move WS-SQLCODE to SQLCODE
d) call the standard ABORT subroutine which uses the values of SQLCA.


Does this look good?

Thanks,
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Thu Mar 24, 2011 12:02 am    Post subject:
Reply with quote

It may sound beaureucratic but they are very particular to use that subroutine to abend he program..The called subroutine has the SQLCA passed to it as one of the linkage parameters..
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 658
Location: Whitby, ON, Canada

PostPosted: Thu Mar 24, 2011 3:53 am    Post subject:
Reply with quote

Wait a minute, won't the "final update" be rolled back by the abend issued by the ABORT subroutine?

For this to work, the sequence would have to be:

ROLLBACK
Perform final update
COMMIT
Call ABORT routine
abend

Or does the ABORT subroutine not issue an abend?
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Fri Mar 25, 2011 1:17 am    Post subject:
Reply with quote

don.leahy wrote:
Wait a minute, won't the "final update" be rolled back by the abend issued by the ABORT subroutine?

For this to work, the sequence would have to be:

ROLLBACK
Perform final update
COMMIT
Call ABORT routine
abend

Or does the ABORT subroutine not issue an abend?


Hmm..valid point buddy..I need to put my thinking cap on icon_biggrin.gif
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Mar 25, 2011 3:05 pm    Post subject:
Reply with quote

Rijit wrote:
Problem
==========
But the problem is when they display the SQLCODE then it shows 0 in the spool, because the rollback statement's SQLCODE overiddes the original SQLCODE returned from the update query. This is meisleading and wrong..

I will suggest that you declare a copy of SQLCA in your working storage. No need to declare the individual fields, just an area big enough to hold the SQLCA area.

Just before issuing the rollback, move the contents of the original SQLCA to the copy area, and use that as call parameter when you call the force abend routine, or move the copy SQLCA information back to the original area before calling the abend code.

That way the intervening DB2 calls does not interfere with your original abend situation.

Remember, you should still be able to issue a forced abend documenting DB2 calls that goes wrong in the period between the rollback and the last commit.
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Sat Mar 26, 2011 1:56 am    Post subject:
Reply with quote

Superb idea!! Thanks Kjeld icon_biggrin.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
This topic is locked: you cannot edit posts or make replies. how to code for GDG in Rexx cvnlynn CLIST & REXX 13 Wed Aug 09, 2017 9:13 pm
This topic is locked: you cannot edit posts or make replies. rexx code to create a ps file Bharath Vikraman CLIST & REXX 4 Mon Aug 07, 2017 10:30 am
No new posts I want to retire TRX and use only Rex... Abhinav Sharma CLIST & REXX 6 Sat Jul 29, 2017 2:53 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us