× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Since it is a regular cursor handling, the result set a multiple row fetch into an array data structure will do the job.
Here an example

DCL-S RsLCsrC01 SQLType(Result_Set_Locator);

DCL-DS DScsrC01 Qualified Dim(100) Inz;
CompanyNo Char(15);
CompanyName Char(35);
Street Char(35);
Country Char(4);
ZipCode Char(9);
City Char(35);
End-Ds;

DCL-S RowsCsrC01 Int(5) Inz(%Elem(DSCsrC01));
DCL-S SavSQLEr3 Like(SQLER3);
//---------------------------------------------------------------------------------------------
// M A I N P R O G R A M
//---------------------------------------------------------------------------------------------
*INLR = *On;

Monitor;

Exec SQL Call GetCompany('GmbH & Co');

Exec SQL Associate Result Set Locator (:RSLCsrC01)
with Procedure GetCompany(VarChar());

Exec SQL Allocate CsrC01 Cursor For Result Set :RSLCsrC01;

Exec SQL Fetch Next From CsrC01 For :RowsCsrC01 Rows
into :DSCsrC01;
SavSQLER3 = SQLER3;

If SavSQLER3 > *Zeros;
For Index = 1 to SavSQLER3;
Text = %Trim(DSCsrC01(Index).CompanyNo) +' ' +
%Trim(DSCsrC01(Index).CompanyName);
Dsply Text;
EndFor;
EndIf;

Exec SQL Close CsrC01;

On-Error;
Dsply PGMSDS.MsgText;
EndMon;

Mit freundlichen Grüßen / Best regards

Birgitta Hauser
Modernization – Education – Consulting on IBM i
Database and Software Architect
IBM Champion since 2020

"Shoot for the moon, even if you miss, you'll land among the stars." (Les Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them and keeping them!"
"Train people well enough so they can leave, treat them well enough so they don't want to. " (Richard Branson)
"Learning is experience … everything else is only information!" (Albert Einstein)

-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Vern Hamberg via MIDRANGE-L
Sent: Wednesday, 30 April 2025 20:03
To: midrange-l@xxxxxxxxxxxxxxxxxx
Cc: Vern Hamberg <vhamberg@xxxxxxxxxxxxxxx>
Subject: Re: SQL Procedure Result Sets Array Processing

OK, but how do any of these address the OPs question about returning into an RPG array? Except the one that returned several rows into a DS array?

*Regards*

*Vern Hamberg*

IBM Champion 2025 <cid:part1.1FRBb0SJ.L6Wg4YCb@centurylink.net> CAAC (COMMON Americas Advisory Council) IBM Influencer 2023

On 4/30/2025 11:06 AM, Charles Wilt wrote:
I'd second the recommendation for a UDTF...

Much more flexible than a SP returning a results set..

Charles

On Wed, Apr 30, 2025 at 9:55 AM Daniel Gross<daniel@xxxxxxxx> wrote:

Hi Buzz,

you can find some info in the Info Center:


https://www.ibm.com/docs/en/i/7.5.0?topic=procedures-returning-result
-sets-from-stored

But from a modern view of SQL I wouldn't recommend using a stored
procedure returning a result set.

IMHO a user defined table function is the better and more modern
"attack vector" as you can use the UDTF anywhere in any SQL query,
where a table is usable.


https://www.ibm.com/docs/en/i/7.5.0?topic=code-example-weather-table-
function

https://www.itjungle.com/2016/06/14/fhg061416-story03/

For external (RPG) UDTF Scott has created some very nice docs:

https://www.scottklement.com/udtf/

HTH and kind regards,
Daniel


Am 30.04.2025 um 17:05 schrieb Buzz Fenner via MIDRANGE-L <
midrange-l@xxxxxxxxxxxxxxxxxx>:
I've gotten the go-ahead to do a POC for creating SQL stored
procedures
that returns a result set(s) to an RPG-ILE array. My searches for
articles and code haven't turned up any "complete" articles (although
I've hit on snippets from Jon, Birgitta, etc.).
Anyone know of any good end-to-end articles that I can read to get
up to
speed?
--Buzz
--
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L)
mailing list To post a message email:MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:https://lists.midrange.com/mailman/listinfo/midrange-l
or email:MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
athttps://archive.midrange.com/midrange-l.

Please contactsupport@xxxxxxxxxxxxxxxxxxxx for any subscription
related questions.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2025 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.