|
I'm coding an RPG program that extracts data from a list API. In this
case, its QZLSLSTI to list share names on the system.
I'm very new to this, so I'm following an example where the author placed
all functions in an exported sub-procedure. His example used a file, so its
somewhat simpler than what I'd like to do. A UDTF function is called once
for the open, and then multiple times for the fetch, and one more time for
the close. Since I'm processing a list API, pointer data to the user space
is created during the "open", and then paged through using pointer offsets
during the "fetch", and finally the user space is deleted during the
"close".
I'm having some trouble with variables between the calls, I think. Since
everything is under the subprocedure definition, nothing is a global
variable or static. The pointers to the user space seem to need to be
"static", so I made them static, but my offset index counter does not seem
to need to be static for some reason. Sometimes if I execute the SQL to
read from this table more than once, I get no results, which I'm assuming
is because of static variable not being reset, because if I sign out and
back in, things work again.
How should I be managing the memory when coding this API to SQL UDTF?
ctl-opt option(*srcstmt:*nodebugio) nomain;
dcl-proc LSTSHR1 export;
dcl-ds USH likeds(QUSH0100_t) based(USH_P);
dcl-s USH_p pointer static;
dcl-ds ERRC0100 likeds(ERRC0100_t) INZ;
dcl-ds US likeds(UsrSpc_t) inz(*likeds);
dcl-s RtnLib char(10);
dcl-ds ZL likeds(ZLSL0100_t) based(ZL_p);
dcl-s ZL_p pointer static;
dcl-s idx1 uns(10);
dcl-pi *n;
iShare char(12);
iPath char(1000);
n_Share int(5);
n_Path int(5);
SQLSTT char(5);
Function varchar(517) const;
Specific varchar(128) const;
errorMsg varchar(70);
CallType int(10) const;
end-pi;
if CallType=call_open;
// Create user space
.......
// Call list server info API
.......
// Assign header pointer to user space
callp QUSPTRUS(US
:USH_p);
ZL_p=USH_p+USH.QUSOLD;
elseif CallType=call_fetch;
// Assign pointer to API data
idx1+=1;
// Return EOF if end of list
if idx1>=USH.QUSNBRLE;
SQLSTT='02000';
return;
else;
iPath=ZL.PathName;
iShare=ZL.ShareName;
ZL_p+=USH.QUSSEE;
endif;
elseif CallType=call_close;
callp QUSDLTUS(US
: errc0100);
clear USH;
clear ZL;
dealloc USH_p;
dealloc ZL_p;
clear idx1;
clear US;
*INLR=*on;
endif;
return;
end-proc;
___________________________________
Darren Strong
Dekko
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.