TechTalk: Preserve Your Library List

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: