View previous topic :: View next topic
|
Author |
Message |
Keanehelp
New User
Joined: 27 May 2008 Posts: 71 Location: USA, CA.
|
|
|
|
Hi,
I am calling a subroutine statically. There is a cursor which opens in the subroutine.
Is there any way through which I can close that cursor from main program?
Also Please note that I can not use IS INITIAL. Will COMMIT work in such a case?
Please let me know if not clear, i'll provide more details.
Thanks
Nitin |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
cursor names are qualified by the module name.
you can have two modules with the same cursor name - but they are different cursors.
declare/open/fetch/close CURSOR has to be in same module.
normally, when the sql code for a fetch = +100 (or any non-zero)
you issue the CLOSE CURSOR.
So, a CALL to the subroutine for a fetch
would return no rows to the CALLing module
if the sqlcode for the fetch <> 0
and the CALLed submodule would have issued a close cursor,
thus no need to CLOSE Cursor from main/CALLing module.
and yes, a COMMIT issued from the main module
(actually any module in the Batch rununit)
would CLOSE any Cursor opened by any module in the run-unit
that has not been OPENed WITH HOLD. |
|
Back to top |
|
|
Keanehelp
New User
Joined: 27 May 2008 Posts: 71 Location: USA, CA.
|
|
|
|
Thanks for your answer DBZ. Appreciated. |
|
Back to top |
|
|
Keanehelp
New User
Joined: 27 May 2008 Posts: 71 Location: USA, CA.
|
|
|
|
Hi,
One more question. Does CANCEL statement will close the cursors in subroutine or it will just refresh the variables? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
honestly, do not know, but will make a guess:
Since a CANCEL in just a load module 'unload',
I would say no.
There would be no communication to db2
- a run unit ending, the op-sys communicates with db2
and any db2 associated with the run-unit (task) is terminated.
But a module CANCEL would not cause this communication to be established.
You would in effect have an open cursor that you can never explicitly close,
or access via fetch.
also, even read only cursors should be COMMITed.
Until the run-unit ends, you are going to have problems.
why CANCEL a module that you will CALL again?
and a CANCEL does not refresh anything.
what you probably mean by refreshing variables
would be accomplished via the CALL which would LOAD the module. |
|
Back to top |
|
|
anand jeyapaul
New User
Joined: 26 Oct 2017 Posts: 12 Location: india
|
|
|
|
Dick,
I have a question here. If a cursor in the calling program is declared with hold option how do I close it in the called program
Regards
Anand. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
7 year old topic - closed |
|
Back to top |
|
|
|