I had a problem recently where because of some old programs with built-in O-specs I didn’t really know what the name of the spool file generated is in CL. I found this API that can figure that out for you.
Here is how to use it. First declare your variables:
/* QSPRILSP Fields */ DCL VAR(&RCVVAR) TYPE(*CHAR) LEN(70) DCL VAR(&RCVVARLEN) TYPE(*CHAR) LEN(4) DCL VAR(&ERRCODE) TYPE(*CHAR) LEN(8) /* FIELDS FROM FORMAT SPRL0100 */ DCL VAR(&SPLFNAME) TYPE(*CHAR) LEN(10) DCL VAR(&JOBNAME) TYPE(*CHAR) LEN(10) DCL VAR(&USERNAME) TYPE(*CHAR) LEN(10) DCL VAR(&JOBNBR) TYPE(*CHAR) LEN(6) DCL VAR(&SPLFNBR) TYPE(*DEC) LEN(6 0)
Then you need to run this check.
/* &RCVVARLEN NEEDS TO BE SET TO THE SIZE OF &RCVVAR. + IF YOU CHANGE THE SIZE OF &RCVVAR, CHANGE IT ON THE + LINE BELOW AS WELL! (CL HAS NO %SIZE BIF!!) */ CHGVAR VAR(%BIN(&ERRCODE 1 4)) VALUE(0) /* End QSPRILSP Fields */
Then after your spool file is generated, run the following code:
/* Get the last spool file created information */ CALL PGM(QSPRILSP) PARM(&RCVVAR &RCVVARLEN + 'SPRL0100' &ERRCODE) /* SINCE CL HAS NO SUCH THING AS A DATA STRUCTURE, I'VE + PUT ALL OF THE FIELDS INTO ONE BIG &RCVVAR FIELD, + AND WILL SPLIT IT INTO SUBFIELDS BELOW: */ CHGVAR VAR(&SPLFNAME) VALUE(%SST(&RCVVAR 9 10)) CHGVAR VAR(&JOBNAME) VALUE(%SST(&RCVVAR 19 10)) CHGVAR VAR(&USERNAME) VALUE(%SST(&RCVVAR 29 10)) CHGVAR VAR(&JOBNBR) VALUE(%SST(&RCVVAR 39 6)) CHGVAR VAR(&SPLFNBR) VALUE(%BIN(&RCVVAR 45 4))
Note: I did not originally write this code, but is documented here for me to easily find in the future. It was from an article in System i Network.
No responses yet