A problem I encounter regularly is having to save and restore the library list in a CL program. I save the library list near the beginning of the program, then do CHGLIBL to replace the library list with what the program needs, and restore the old library list at the end. I save/restore the previous values so my "parent" calling program does not have its library list changed unexpectedly. It's good for modularity, too. I have two utilities to simplify this task.
Command PSHLIBL saves the current library list and current library. Command POPLIBL restores those values. They work like a "stack." PSHLIBL can be run multiple times before POPLIBL is run. Each POPLIBL will restore the most recently saved values.
PSHLIBL (Figures 6a and 6b) creates data queue STACKLIBL in library QTEMP in LIFO (last-in, first-out) sequence. It retrieves the current library list and current library using RTVJOBA, and sends that information to the data queue (as two separate items). POPLIBL (Figures 6c and 6d) retrieves the last two items from the data queue. It performs a call to QCMDEXC to run CHGLIBL, which resets the library list and current library.
TechTalk: Preserve Your Library List
Figure 6A Command PSHLIBL
PSHLIBL: CMD PROMPT('Push Library List')
TechTalk: Preserve Your Library List
Figure 6B CL program LIBL004CL
LIBL004CL: + PGM DCL VAR(&USRLIBL) TYPE(*CHAR) LEN(275) DCL VAR(&CURLIB) TYPE(*CHAR) LEN(10) /* Get current library list and current library */ RTVJOBA USRLIBL(&USRLIBL) CURLIB(&CURLIB) /* Create data queue, if it does not already exist */ CHKOBJ OBJ(QTEMP/STACKLIBL) OBJTYPE(*DTAQ) MONMSG MSGID(CPF9801) EXEC(CRTDTAQ DTAQ(QTEMP/STACKLIBL) + MAXLEN(275) SEQ(*LIFO)) /* Push data into stack (library list, then current library; + they will be retrieved in reverse order */ CALL PGM(QSNDDTAQ) PARM(STACKLIBL QTEMP X'00275F' &USRLIBL) CALL PGM(QSNDDTAQ) PARM(STACKLIBL QTEMP X'00010F' &CURLIB) ENDPGM
TechTalk: Preserve Your Library List
Figure 6C Command POPLIBL
POPLIBL: CMD PROMPT('Pop Library List')
TechTalk: Preserve Your Library List
Figure 6D CL program LIBL005CL
LIBL005CL: + PGM DCL VAR(&USRLIBL) TYPE(*CHAR) LEN(275) DCL VAR(&CURLIB) TYPE(*CHAR) LEN(10) DCL VAR(&CHGLIBL) TYPE(*CHAR) LEN(308) /* Make sure library list stack exists */ CHKOBJ OBJ(QTEMP/STACKLIBL) OBJTYPE(*DTAQ) MONMSG MSGID(CPF9801) EXEC(DO) SNDPGMMSG MSG('Data queue QTEMP/STACKLIBL does not exist. + PSHLIBL not executed.') MSGTYPE(*DIAG) SNDPGMMSG MSGID(CPF0002) MSGF(QCPFMSG) MSGTYPE(*ESCAPE) GOTO CMDLBL(ENDPGM) ENDDO /* Pop data from stack (current library, then library list) */ CALL PGM(QRCVDTAQ) PARM(STACKLIBL QTEMP X'00010F' &CURLIB + X'00000F') CALL PGM(QRCVDTAQ) PARM(STACKLIBL QTEMP X'00275F' &USRLIBL + X'00000F') IF COND(&CURLIB *EQ ' ') THEN(DO) SNDPGMMSG MSG('Data queue QTEMP/STACKLIBL is empty. No + matching PSHLIBL executed.') MSGTYPE(*DIAG) SNDPGMMSG MSGID(CPF0002) MSGF(QCPFMSG) MSGTYPE(*ESCAPE) GOTO CMDLBL(ENDPGM) ENDDO /* Restore user library list and current library */ IF COND(&CURLIB *EQ '*NONE') THEN(CHGVAR VAR(&CURLIB) + VALUE(*CRTDFT)) IF COND(&USRLIBL *EQ ' ') THEN(CHGVAR VAR(&USRLIBL) VALUE(*NONE)) CHGVAR VAR(&CHGLIBL) VALUE('CHGLIBL LIBL(' *CAT &USRLIBL *TCAT + ') CURLIB(' *CAT &CURLIB *TCAT ')') CALL PGM(QCMDEXC) PARM(&CHGLIBL 308) ENDPGM: + ENDPGM
LATEST COMMENTS
MC Press Online