|Where allowed to run: All environments (*ALL)
The Save Library List (PUSH LIBL) (SAVLIBL) command allows you to save the current library list to a save area and then restore the library list using that same save area (via the RSTLIBL command). SAVLIBL copies the names of all portions of the library list to the save area. The save area is actually a user space that the command creates for you. The job can be changed back to a saved library list by running the RSTLIBL command.
SAVLIBL is a stack.
Each time SAVLIBL is run, the library list is copied to the end of the save area (user space). When it is restored, it is restored from the end of the save area and then removed from the save area. SAVLIBL and RSTLIBL work similar to the "PUSH" and "POP" function in computer science. The first SAVLIBL copies the names of the libraries on the library list to the user space. A second SAVLIBL to the save save area adds the current library list to that same user space, retaining the first library list. Thus, a SAVLIBL, SAVLIBL, SAVLIBL, followed by RSTLIBL, RSTLIBL saves the library list 3 times, and restores the two most recently saved versions. The original or first save is not restored since, in this example, only two RSTLIBL commands were issued.
|LIBL||Library List save area name||Qualified object name||Optional, Positional 1|
|Qualifier 1: Library List save area name||Name, *USER, *DFT, *JOB, *JOBNAME, *JOBNBR|
|Qualifier 2: Library||Name, *CURLIB, QTEMP|
|CLEAR||Clear library list save area||*YES, *NO||Optional, Positional 2|
Specifies the user space where the library list names are saved.
Qualifier 1: Library List save area name
Specifies whether or not to clear the user space (save area) before performing the SAVLIBL command. Doing so clears any existing data from the save area, including previously saved library lists.
Example 1: Simple Command Example
SAVLIBL CHGCURLIB APLUS ADDLIBLE FIXEDASSET CALL PGM0100E RSTLIBL
In this example, the initial SAVLIBL command saves the library list to the default save area. Then the library list is modified, and a legacy program is called. Upon returning from that call, the RSTLIBL command is run. It restores the library list to where is was when the original SAVLIBL command had been run.
Example 2: More Complex Command Example
SAVLIBL LIBL(QTEMP/THX01) CLEAR(*YES) CHGCURLIB APLUS ADDLIBLE FIXEDASSET CALL PGM0100E COZTOOLS/RSTLIBL LIBL(QTEMP/THX01)
In this example the same process is performed as in the first example. However, the SAVLIBL and RSTLIBL commands in this example include the LIBL(QTEMP/THX010) parameter. This forces the library list to be saved to the user space named THX01 in library QTEMP. Why do this? If once of the programs being called by PGM0100E also run SAVLIBL, but do not necessarily restore the library list by calling RSTLIBL, then upon returning to this program, the RSTLIBL could restore the incorrect library list. Using a unique save area on the LIBL parameter allows you to control where the library is saved to and restored from.
In addition, we've qualified the RSTLIBL command to the COZTOOLS library. Why do this? Because if the call to PGM0100E changes the library list to the point where the COZTOOLS library is no longer on the library list, the RSTLIBL could fail. By qualifying it we avoid that specific issue.