Link to home
Start Free TrialLog in
Avatar of Try2BeBetter
Try2BeBetter

asked on

How can I use one SQL Cursor between two RPG programs?

BACKGROUND:
  -Platform:  iSeries V5r4
  -Language:  RPG IV (using \free syntax)

Here is what i am trying to do:  
      The first RPG program declares and opens up a SQL cursor by means of "exec" statements.  It will then call the second RPG program.  The second program will try to access the SQL cursor that was opened by the first program.

According to IBM's website there is an option you can choose "*ENDSQL" and "*ENDJOB" for the parameter "CLOSQLCSR" that will keep SQL cursors open.

Question:  How can I get the called program to use the SQL cursor that should already exist in memory?
SOLUTION
Avatar of daveslater
daveslater
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Try2BeBetter
Try2BeBetter

ASKER

If I declare it in the 2nd program, i think it will erase the cursor that is in memory.
Avatar of Kent Olsen
Hi Try2,

Try to declare the cursor WITH HOLD.  That is generally unaffected by other cursors, commits, and other events that can void a cursor.


Kent
@Kdo:  That holds it in the memory, but what would be the RPG code that would retrieve it?  I tried to declare the same variable in the second program and it either created a new cursor or erased the other one.  Because when I went to "fetch" the data, it was blank.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The only way I can think of doing this is as a service program in a named activation group.
or
all the programs caouls be compiled with activation group *caller

Pgm 1 calls a procedure in the service program to open the cursor
pgm 2 calls a procedure to read the cursor and pass back a data structure

Dave
Yeah, dave's suggestion is probably as close as you can come.  

Found the relevant Info Center Reference.  Clearly says you can't access a cursor across program boundaries.  Read all the subtopics:

http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Frzajq%2Fretcurs.htm

- Gary Patterson
You could break the cursor out to have it generated and read by a third program. Your original two programs would then CALL the third program to have it perform any needed FETCHs.

Tom
Just a question,
Why should you like to do that?
what is the purpose of this methode?
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.