Return to the RPG Tips
Use the QWCRSVAL API
Basically, in the phrase CHAR(*), the * can be replaced with ANY number. You can pass a variable thats 20 chars long, or 1000 chars long... usually, as in this case, you tell the API the length of the field in a seperate parameter. The same goes for the phrase "ARRAY(*) of BINARY(4)" The number of things in that array vary... In the case, you're telling it the number of system values that you'd like the value returned for, so you'll know how many elements that array will have... The other confusing thing about this particular API is that different system values will return different data types that are of different lengths... The way that I deal with this issue is by creating a sub-proc that simply copies the value returned by the API to a pointer that's passed as a parameter. Then when I'm writing my program that uses the API, I pass the address of a variable thats of the correct type for the system value that I'm retrieving... Here's a quick sample program... good luck! D GetSysVal PR 10I 0 D peSysVal 10A Const D peRtnVal * Value D SerialNo S 8A D SysLibl S 10A DIM(15) D LogSize S 10I 0 D Msg S 40A C if GetSysVal('QHSTLOGSIZ':%addr(LogSize))>0 c eval Msg = 'History Log Size' c Msg dsply LogSize c endif C if GetSysVal('QSRLNBR':%addr(SerialNo))>0 c eval Msg = 'Serial number' c Msg dsply SerialNo c endif C if GetSysVal('QSYSLIBL':%addr(SysLibl))>0 c eval Msg = 'System Library List' c Msg dsply c do 15 X 2 0 c if SysLibl(X) <> *blanks c SysLibl(X) dsply c else c Leave c endif c enddo c dsply Pause 1 c endif c eval *INLR = *On P*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P* Retrieves a system value. P* Different system values return different data types, P* Please make sure you pass the correct type, and that P* It is long enough to contain the entire result... P* P* Returns 0 for failure, or 1 for success. P*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P GetSysVal B EXPORT D GetSysVal PI 10I 0 D peSysVal 10A Const D p_RtnVal * Value D peRcvVar S 1A DIM(1000) D peRtnVal S 984A BASED(p_RtnVal) D peRVarLen S 10I 0 D peNumVals S 10I 0 D p_Offset S * D wkOffset S 10I 0 BASED(p_Offset) D dsErrCode DS D dsBytesPrv 1 4I 0 D dsBytesAvl 5 8I 0 D dsExcpID 9 15 D dsReserved 16 16 D dsExcpData 17 256 D p_SV S * D dsSV ds BASED(p_SV) D dsSVSysVal 10A D dsSVDtaTyp 1A D dsSVDtaSts 1A D dsSVDtaLen 10I 0 D dsSVData 984A c eval dsBytesPrv = 256 c eval dsBytesAvl = 0 c eval peSysValNm = peSysVal C CALL 'QWCRSVAL' 99 C PARM peRcvVar C PARM 1000 peRVarLen c PARM 1 peNumVals c PARM peSysValNm 10 c PARM dsErrCode c if dsBytesAvl > 0 or *IN99 = *On c return 0 c endif c eval p_Offset = %addr(peRcvVar(5)) c eval p_SV = %addr(peRcvVar(wkOffset+1)) c eval %subst(peRtnVal:1:dsSVDtaLen) = c %subst(dsSVData:1:dsSVDtaLen) c return 1 P E
[report a broken link by clicking here]