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

open cursor in calling stored procedure


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 61
Location: San Diego

PostPosted: Fri Aug 28, 2009 11:31 am
Reply with quote

Hi,

Can i open a cursor in a calling stored procedure which is declared in a called stored procedure for a sql query. Basically i am calling a already existing stored procdure from a newly created one problem, the problem i am facing is that, i am not able to retreive the result set data by this methiod which is possible if i call the existing stored proc directly. All these stored procedures are written in SQL.

Thanks in advance for any tips
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Fri Sep 04, 2009 4:27 pm
Reply with quote

Hi

The requirement in too much confusing, can you just elaborate the requirement,
What lead to such system design ?
Back to top
View user's profile Send private message
ajeshrn

New User


Joined: 25 Mar 2009
Posts: 78
Location: India

PostPosted: Fri Sep 04, 2009 5:38 pm
Reply with quote

Hi rakesh,

Are you trying to get the results of a cursor which you have opened in the called program from the calling program??
Back to top
View user's profile Send private message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 61
Location: San Diego

PostPosted: Mon Sep 07, 2009 9:54 am
Reply with quote

to be more eloborate.. i have this stored procedure SP1 which earlier was displaying the results set when called directly from the client(DB2 connect) i use.. now i have a requirement to call this SP1 from another stored procedure SP2 and still display the same results of SP1.
Is this possible
by just calling SP1 from SP2 .SP1 has already the cursors declared and open when called. or is there any other way through this ??
Back to top
View user's profile Send private message
ajeshrn

New User


Joined: 25 Mar 2009
Posts: 78
Location: India

PostPosted: Mon Sep 07, 2009 1:08 pm
Reply with quote

Hi Rakesh,

Yes..You can call the Stored Procedure from another stored Procedure.

The step used to call is as below in the SP2:

CALL SYSPROC.SP1 (:INPUT1
,:INPUT2
,:OUTPUT1)

All the input and output parameters have to be listed out.

The output parameter results will be obtained directly from SP1 in SP2 through OUTPUT1 parameter.

If you are trying to get the Resultset of the cursor , then you will have to use ASSOCIATE cursors, ALLOCATE them and handle them using +466 SQLCODE.
Back to top
View user's profile Send private message
aryanpa1

New User


Joined: 26 May 2007
Posts: 45
Location: Chennai

PostPosted: Mon Sep 07, 2009 1:20 pm
Reply with quote

Hi Rakesh ,

This is possible to do. How are you handling the resultset coming from SP1 in SP2 and wat are the probelms you are facing.
Back to top
View user's profile Send private message
aryanpa1

New User


Joined: 26 May 2007
Posts: 45
Location: Chennai

PostPosted: Mon Sep 07, 2009 1:28 pm
Reply with quote

Hi Rakesh ,

Try this Code

Code:

01  WS-LOC USAGE SQL TYPE IS RESULT-SET-LOCATOR VARYING. 
:
:
CALL SYSPROC.SP1 (:INPUT1
,:INPUT2
,:OUTPUT1)
 EVALUATE SQLCODE                             
    WHEN 0                                     
    WHEN 466                                   
           EXEC SQL                           
                ASSOCIATE LOCATORS (:WS-LOC)   
                WITH PROCEDURE SP1       
           END-EXEC                           
           EXEC SQL                           
                ALLOCATE SP1_CSR CURSOR   
                FOR RESULT SET :WS-LOC         
           END-EXEC                           
          EXEC SQL                       
                FETCH   SP1_CSR       
                  INTO    :HOST-VAR1,
                             :HOST-VAR2     
           END-EXEC.                       
:
:
:
Back to top
View user's profile Send private message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 61
Location: San Diego

PostPosted: Mon Sep 07, 2009 3:46 pm
Reply with quote

thanks aryan and Pavan but what am looking for is stored procedures written in SQL language not COBOL..

currently what i have done is ..i have got the SQL statement formed in the called stored procedure, passed it back to the calling stored procedure via an output parameter and then back in SP1 the cursors are deployed to display the result set
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
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 Open VSAM File in IMS DC Region - DFS... IMS DB/DC 0
No new posts calling a JCl inside a JCL JCL & VSAM 3
Search our Forums:

Back to Top