IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need to close cursor in a called program from calling progra


IBM Mainframe Forums -> DB2
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
Keanehelp

New User


Joined: 27 May 2008
Posts: 71
Location: USA, CA.

PostPosted: Mon Oct 11, 2010 9:59 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Oct 11, 2010 10:31 pm
Reply with quote

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
View user's profile Send private message
Keanehelp

New User


Joined: 27 May 2008
Posts: 71
Location: USA, CA.

PostPosted: Tue Oct 12, 2010 9:57 am
Reply with quote

Thanks for your answer DBZ. Appreciated.
Back to top
View user's profile Send private message
Keanehelp

New User


Joined: 27 May 2008
Posts: 71
Location: USA, CA.

PostPosted: Tue Oct 12, 2010 10:38 am
Reply with quote

Hi,

One more question. Does CANCEL statement will close the cursors in subroutine or it will just refresh the variables?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Oct 12, 2010 1:38 pm
Reply with quote

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
View user's profile Send private message
anand jeyapaul

New User


Joined: 26 Oct 2017
Posts: 12
Location: india

PostPosted: Wed Nov 01, 2017 3:16 am
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Wed Nov 01, 2017 3:55 pm
Reply with quote

7 year old topic - closed
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Using API Gateway from CICS program CICS 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
No new posts Calling an Open C library function in... CICS 1
No new posts DB2 Event passed to the Application P... DB2 1
Search our Forums:

Back to Top