/free
// ensure cursor is not open...close as normal
exec sql close cursor1;
exec sql declare cursor1 cursor with return to caller for
SELECT * FROM file WHERE contract = :pContract;
// open as normal
exec sql open cursor1;
return;
Sample of SQL creating the cursor:
CREATE PROCEDURE SQLProcedure (
IN CONTRACT VARCHAR(10) )
DYNAMIC RESULT SETS 1
LANGUAGE SQL
SPECIFIC SQLProcedure
NOT DETERMINISTIC
READS SQL DATA
CALLED ON NULL INPUT
SET OPTION ALWBLK = *ALLREAD ,
ALWCPYDTA = *OPTIMIZE ,
COMMIT = *NONE ,
DECRESULT = (31, 31, 00) ,
DFTRDBCOL = C2DDTALIB ,
DYNDFTCOL = *NO ,
DYNUSRPRF = *USER ,
SRTSEQ = *HEX
BEGIN NOT ATOMIC
DECLARE ERROPEN SMALLINT ;
DECLARE CSRNOTOPEN CONDITION FOR '24501' ;
DECLARE CSRC01 CURSOR FOR
SELECT * FROM file WHERE contract = CONTRACT ;
DECLARE CONTINUE HANDLER FOR CSRNOTOPEN SET ERROPEN = 1 ;
SET CONTRACT = UPPER ( TRIM ( CONTRACT ) ) ;
CLOSE CSRC01 ;
OPEN CSRC01 ;
END ;
Sample of the caller that consumes the cursor:
dTESTSQLCU2 PR ExtPgm('TESTSQLCU2')
d pContract 10
d pSQLOrPgm 3
dTESTSQLCU2 PI
d pContract 10
d pSQLOrPgm 3
dTESTSQLCU3 PR ExtPgm('TESTSQLCU3')
d pContract 10
* cursor result set locators
d RSLCursor1 s sqltype(Result_Set_Locator)
d ResultIsReturned...
d c Const(466)
d NbrOfResultSet...
d s 10i 0
d text s 100
* the format of the data being returned in the external cursor
d cursordata ds
d field1 8p 0
d field2 6p 0
d field3 10
d field4 60
d field5 10
d field6 1
d field7 7p 0
/free
// cause cursor to be opened from called program
select;
when pSQLOrPgm = 'SQL';
exec sql call SQLProcedure (:pContract); // via SQL Stored Proc
// get the cursor's locator value
exec sql associate result set locator (:RSLCursor1)
with procedure getwbpage(varchar());
when pSQLOrPgm = 'RPG';
testsqlcu3 (pContract); // via called RPG pgm
other;
exec sql call testsqlcu3 (:pContract); // via called RPG pgm via stored proc
// get the cursor's locator value
exec sql associate result set locator (:RSLCursor1)
with procedure testsqlcu3(varchar());
endsl;
text = %trim('Result_Set_Locator: ' + %char(RSLCursor1));
dsply %subst(text:1:50);
// open the cursor by allocating it using the locator value
exec sql allocate cursor1 cursor for result set :RSLCursor1;
text = %trim('ResultIsReturned: ' + %char(ResultIsReturned));
dsply %subst(text:1:50);
text = %trim('NbrOfResultSet: ' + %char(NbrOfResultSet));
dsply %subst(text:1:50);
dou 1=0;
// process as normal
exec sql fetch next from cursor1 into :cursordata;
if sqlcod < 0 or sqlcod = 100;
leave;
endif;
text = %trim(field4);
dsply %subst(text:1:50);
enddo;
// close as normal
exec sql close cursor1;
*inlr = *on;
return;
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Needles,Stephen J
Sent: Thursday, July 21, 2011 9:03 AM
To: midrange-l@xxxxxxxxxxxx
Subject: SQL/RPG 7.1 Cursor Consumption from one RPG pgm to another
I am developing on 7.1 OS. I am experimenting with the 7.1 ability that allows a SQL cursor generated by a process to be consumed by a different RPG program.
I have succeeded in writing an RPG program that consume the cursor created by an SQL Stored Procedure written in SQL. But I have not been able to have an RPG program consume the cursor created by another RPG program. It does not appear to matter if the program that creates the cursor is executed as a stored procedure or an RPG program call of any type. The result is the same, I can't read the cursor if the cursor was created with a non-SQL stored procedure/process.
I can't find where this scenario is explicitly forbidden, so I figure I might be doing something wrong. Have any of you been able to do some testing along these lines?
Steve Needles
Northland Insurance
(651) 310-4203
==============================================================================
This communication, including attachments, is confidential, may be subject to legal privileges, and is intended for the sole use of the addressee. Any use, duplication, disclosure or dissemination of this communication, other than by the addressee, is prohibited. If you have received this communication in error, please notify the sender immediately and delete or destroy this communication and all copies.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.