This example shows the steps necessary to process keyed output from an API.
Refer to Example in OPM RPG: Using keys with List Spooled Files API for the original example.
F*************************************************************** F*************************************************************** F* F* Program: List Spooled Files for Current User F* F* Language: ILE RPG F* F* Description: This example shows the steps necessary to F* process keyed output from an API. F* F* APIs Used: QUSLSPL - List Spooled Files F* QUSCRTUS - Create User Space F* QUSPTRUS - Retrieve Pointer to User Space F* F*************************************************************** F*************************************************************** F* FQPRINT O F 132 PRINTER OFLIND(*INOF) D* D* Error Code parameter include D* D/COPY QSYSINC/QRPGLESRC,QUSEC (11) D* DSPC_NAME S 20 INZ('SPCNAME QTEMP ') DSPC_SIZE S 9B 0 INZ(2000) (2) DSPC_INIT S 1 INZ(X'00') DLSTPTR S * DLSTPTR2 S * DSPCPTR S * DARR S 1 BASED(LSTPTR) DIM(32767) D DS DPAGES# 1 4B 0 DPAGESA 1 4 DKEYS DS (7) D 9B 0 INZ(201) (8) D 9B 0 INZ(216) D 9B 0 INZ(211) DKEY# S 9B 0 INZ(3) D***************************************************************** D* D* The following QUSGEN include from QSYSINC is copied into (11) D* this program so that it can be declared as BASED on SPCPTR D* D***************************************************************** DQUSH0100 DS BASED(SPCPTR) D* Qus Generic Header 0100 D QUSUA 1 64 D* User Area D QUSSGH 65 68B 0 D* Size Generic Header D QUSSRL 69 72 D* Structure Release Level D QUSFN 73 80 D* Format Name D QUSAU 81 90 D* API Used D QUSDTC 91 103 D* Date Time Created D QUSIS 104 104 D* Information Status D QUSSUS 105 108B 0 D* Size User Space D QUSOIP 109 112B 0 D* Offset Input Parameter D QUSSIP 113 116B 0 D* Size Input Parameter D QUSOHS 117 120B 0 D* Offset Header Section D QUSSHS 121 124B 0 D* Size Header Section D QUSOLD 125 128B 0 D* Offset List Data D QUSSLD 129 132B 0 D* Size List Data D QUSNBRLE 133 136B 0 D* Number List Entries D QUSSEE 137 140B 0 D* Size Each Entry D QUSSIDLE 141 144B 0 D* CCSID List Ent D QUSCID 145 146 D* Country ID D QUSLID 147 149 D* Language ID D QUSSLI 150 150 D* Subset List Indicator D QUSERVED00 151 192 D* Reserved D***************************************************************** D* D* The following QUSLSPL include from QSYSINC is copied into D* this program so that it can be declared as BASED D* D***************************************************************** D****************************************************************** D*Prototype for calling List Spooled File API QUSLSPL D****************************************************************** D QUSLSPL C 'QUSLSPL' D****************************************************************** D*Type definition for the SPLF0200 format. D******* D*NOTE: The following type definition only defines the fixed D* portion of the format. Any varying length field will D* have to be defined by the user. D****************************************************************** DQUSSPLKI DS 100 BASED(LSTPTR2) D* Qus LSPL Key Info D QUSLFIR02 1 4B 0 D* Len Field Info Retd D QUSKFFFR00 5 8B 0 D* Key Field for Field Retd D QUSTOD02 9 9 D* Type of Data D QUSR300 10 12 D* Reserv3 D QUSDL02 13 16B 0 D* Data Length D*QUSDATA08 17 17 D* D* Varying length D*QUSERVED34 18 18 D* D* Varying length DQUSF0200 DS BASED(LSTPTR) D* Qus SPLF0200 D QUSNBRFR00 1 4B 0 D* Num Fields Retd D*QUSKI00 18 D* QUSLFIR03 5 8B 0 D* QUSKFFFR01 9 12B 0 D* QUSTOD03 13 13 D* QUSR301 14 16 D* QUSDL03 17 20B 0 D* QUSDATA09 21 21 D* QUSERVED35 22 22 D* D* Varying length C* C* Start of mainline C* C* C* Set Error Code structure to use exceptions C* C Z-ADD 0 QUSBPRV (1) C* C* Create a User Space for the List generated by QUSLSPL C* C CALL 'QUSCRTUS' (2) C PARM SPC_NAME C PARM 'QUSLSPL ' EXT_ATTR 10 C PARM SPC_SIZE C PARM SPC_INIT C PARM '*ALL' SPC_AUT 10 C PARM *BLANKS SPC_TEXT 50 C PARM '*YES' SPC_REPLAC 10 C PARM QUSEC C PARM '*USER' SPC_DOMAIN 10 C* C* Call QUSLSPL to get all spooled files for *CURRENT user C* C CALL 'QUSLSPL' (3) C PARM SPC_NAME C PARM 'SPLF0200' FORMAT 8 (4) C PARM '*CURRENT' USR_PRF 10 C PARM '*ALL' OUTQ 20 C PARM '*ALL' FORMTYP 10 C PARM '*ALL' USRDTA 10 C PARM QUSEC C PARM JOBNAM 26 C PARM KEYS (5) C PARM KEY# (6) C* C* Get a resolved pointer to the User Space for performance C* C CALL 'QUSPTRUS' (9) C PARM SPC_NAME C PARM SPCPTR C PARM QUSEC C* C* If valid information was returned C* C QUSSRL IFEQ '0100' (12) C QUSIS IFEQ 'C' (14) C QUSIS OREQ 'P' C* C* and list entries were found C* C QUSNBRLE IFGT 0 (16) C* C* set LSTPTR to the first byte of the User Space C* C EVAL LSTPTR = SPCPTR C* C* increment LSTPTR to the first List entry C* C EVAL LSTPTR = %ADDR(ARR(QUSOLD + 1)) (18) C* C* and process all of the entries C* C DO QUSNBRLE (20) C* C* set LSTPTR2 to the first variable length record for this entry C* C Z-ADD 5 X 9 0 C EVAL LSTPTR2 = %ADDR(ARR(X)) (22) C DO QUSNBRFR00 (23) C* C* process the data based on key type C* C QUSKFFFR00 CASEQ 201 FILNAM (24) C QUSKFFFR00 CASEQ 211 PAGES C QUSKFFFR00 CASEQ 216 AGE C CAS ERROR C END C* C* increment LSTPTR2 to next variable length record C* C ADD QUSLFIR02 X C EVAL LSTPTR2 = %ADDR(ARR(X)) C END C EXCEPT PRTLIN (26) C* C* after each entry, increment LSTPTR to the next entry C* C EVAL LSTPTR = %ADDR(ARR(QUSSEE + 1)) (27) C END C END C ELSE C EXCEPT LSTERR (15) C END C ELSE C EXCEPT HDRERR (13) C END C* C* Exit the program C* C EVAL *INLR = '1' (28) C RETURN C***************************************************************** C FILNAM BEGSR C* C* extract spooled file name for report C* C MOVE *BLANKS PRTFIL 10 C EVAL PRTFIL = %SUBST(QUSSPLKI:17:QUSDL02) (25) C ENDSR C***************************************************************** C PAGES BEGSR C* C* extract number of pages for report C* C EVAL PAGESA = %SUBST(QUSSPLKI:17:QUSDL02) (25) C ENDSR C***************************************************************** C AGE BEGSR C* C* extract age of spooled file for report C* C MOVE *BLANKS OPNDAT 7 C EVAL OPNDAT = %SUBST(QUSSPLKI:17:QUSDL02) (25) C ENDSR C***************************************************************** C ERROR BEGSR C QUSKFFFR00 DSPLY C EVAL *INLR = '1' C RETURN C ENDSR C***************************************************************** OQPRINT E PRTLIN 1 O PRTFIL 10 O PAGES# 25 O OPNDAT 40 OQPRINT E LSTERR 1 O 22 'List data not valid' OQPRINT E HDRERR 1 O 22 'Unknown Generic Header'