I have a Prog-A calling Prog-B. Inside this sub-program(Prog-B), I have a cursor and have fetched some values. Now, I want to go back to prog-A and do some processing and come back to Prog-B. When I come back to Prog-B, will the cursor that was opened during last call still be opened or closed?
If closed, is there any other way out for this problem...
If opened, will it point to the same record that it was during last call...
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
If you are actually returning from B to A and not doing a Call to A from B you will lose and memory that was used in B that wasn't passed back to A. This includes the opened cursor. You could pass some data back to A of where you left off then when you were exiting B. Then when you come back into B reopen the cursor at that point. However there is no guarentee that this new cursor will contain the same data as the previous run into B.
Call Prog B
Call Prog B
Joined: 20 Oct 2006 Posts: 6970 Location: porcelain throne
I don't think the OP is complaining about a problem that has occurred. I think he just does not know enough about COBOL.
OP said Pgm-A is CALLing Pgm-B.
As long as Pgm-A does not CANCEL Pgm-B before another CALL to Pgm-B
and Pgm-B does not have an INITIAL statement,
Pgm-B will reenter with the CURSOR where it belongs, as long as Pgm-B has logic to check a flag or two upon entry to determine what, where, how, and why.
Best thing is to set-up Pgm-B to react to function requests instead of too much logic trying to control everything. If Pgm-B is just doing DB2, then if it receives a request to OPEN and FETCH a CURSOR, it should do that. If the function request is to 'FETCH-NEXT' is should just do that and report any negative SQLCODES (or +100). If Pgm-B is too complicated, will be a bear to debug.
This of course talking about Batch. Does not really matter if it is Statically or Dynamically linked.