|
Nothing fancy, but here is an example using the Retrieve Language IDs API. This API retrieves a list of language identifiers and you really don't know for sure how many language identifiers there may be for any given release. So we call the API once to determine how many bytes of data are available, allocate that size of storage, call the API again, and then display each of the languages just to show we got there OK. Note that the real processing is done with Based data structures. Bruce DQLGRTVLI pr EXTPGM('QLGRTVLI') D 1 OPTIONS(*VARSIZE) D 10i 0 CONST D 8 CONST D 10i 0 CONST DBaseRcv ds D BytAvl 10i 0 D BytRtn 10i 0 DRealRcv ds based(RealRcvPtr) D RBytAvl 10i 0 D RBytRtn 10i 0 D NbrLng 10i 0 D TextCCSID 10i 0 D OffLngIDs 10i 0 DLngInfo ds based(OffPtr) D LngID 3 D LngText 40 DErrCod ds D BytPrv 10i 0 inz(0) DRealRcvPtr s * DOffPtr s * DLenRcv s 10i 0 DFormat s 8 inz('RTVL0100') C call 'QLGRTVLI' C parm BaseRcv C parm 8 LenRcv C parm Format C parm ErrCod C alloc BytAvl RealRcvPtr C call 'QLGRTVLI' C parm RealRcv C parm BytAvl LenRcv C parm Format C parm ErrCod C eval OffPtr = RealRcvPtr + OffLngIDs C do NbrLng C LngInfo dsply C eval OffPtr = OffPtr + 43 C enddo C eval *inlr = '1' C return > >The System API Programming manual for V4R1 suggests a technique for = >optimizing storage allocation when establishing receiver variable sizes = >as shown at the following address ... = >http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/QB3AVC00/2.7.1 >The following is an extract from that page of the manual ... >---QUOTE-----------------------------------------------------------------= > >Depending on the capabilities of your high-level language, some API = >users take advantage of the following technique to avoid guessing the = >appropriate size for the receiver variable:=20 > > 1.. Call the API with a receiver variable length of 8 bytes (that is, = >just enough for the bytes available and the bytes returned fields).=20 > 2.. Dynamically allocate an amount of storage equivalent to the bytes = >available.=20 > 3.. Set the length of receiver variable parameter to the amount of = >storage allocated.=20 > 4.. Pass the address of the storage allocated in step 2 by using pass = >by value (directly).=20 > > >This technique provides for highly flexible use of APIs that can return = >variable amounts of data.=20 >----END QUOTE = >---------------------------------------------------------------- >Step one is clear enough, however, steps 2,3,4 are not. Is this = >technique applicable to RPG/IV ? If not then what ? > +--- | This is the Midrange System Mailing List! | To submit a new message, send your mail to MIDRANGE-L@midrange.com. | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com. | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
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.