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?
-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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Try to declare the cursor WITH HOLD. That is generally unaffected by other cursors, commits, and other events that can void a cursor.
Kent
ASKER
@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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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
Tom
Just a question,
Why should you like to do that?
what is the purpose of this methode?
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.
ASKER