You can change the library list in a variety of ways.
For a running job, you can add entries to or remove entries from the library list by using the Add Library List Entry (ADDLIBLE) command or the Remove Library List Entry (RMVLIBLE) command, or you can change the libraries in the library list by using the CHGLIBL command or the EDTLIBL command. These commands change the user part of the library list, not the system part.
The current library may be added or changed using the Change Current Library (CHGCURLIB) or CHGLIBL command. The current library can also be changed in the user's user profile, at sign-on, or on the Submit Job (SBMJOB) command. The product libraries cannot be added using a CL command; these libraries are added by the system when a command or menu using them is run. The product libraries cannot be changed with a CL command; however, they can be changed with the Change Library List (QLICHGLL) API.
When you use these commands, the change to the library list affects only the job in which the command is run, and the change is effective only as long as the job is running, or until you change the job's library list again. When the library list is changed through the use of these commands, the libraries must exist when the command is run. A library cannot be deleted if it exists in your job's library list. If it exists in another job's library list, it cannot be deleted only if the system value QLIBLCKLVL is set to lock libraries in the library search list.
When a job is started, the user portion of the library list is determined by the values contained in the job description or by values specified on the Submit Job (SBMJOB) command. A value of *SYSVAL can be specified, which causes the libraries specified by the system value QUSRLIBL to become the user portion of the library list. If you have specified library names in both the job description and the Batch Job (BCHJOB) or Submit Job (SBMJOB) command, the library names specified in the BCHJOB or SBMJOB command override both the libraries specified in the job description and the system value QUSRLIBL.
The following shows the order in which the user part of the library list specified in QUSRLIBL is overridden by commands for individual jobs:
Instead of entering the CHGLIBL command each time you want to change the library list, you can place the command in a CL program:
PGM /* SETLIBL - Set library list */ CHGLIBL LIBL(APPDEVLIB QGPL QTEMP) ENDPGM
If you normally work with this library list, you could set up an initial program to establish the library list instead of calling the program each time:
PGM /* Initial program for QPGMR */ CHGLIBL LIBL(APPDEVLIB QGPL QTEMP) TFRCTL PGM(QPGMMENU) ENDPGM
This program must be created and the user profile to which it will apply changed to specify the new initial program. Control then transfers from this program to the QPGMMENU program, which displays the Programmer Menu.
If you occasionally need to add a library to the library list specified in your initial program, you can use the ADDLIBLE command to add that library to the library list. For example, the following command adds the library JONES to the end of the library list:
ADDLIBLE LIB(JONES) POSITION(*LAST)
If part of your job requires a different library list, you can write a CL program that saves the current library list and later restores it, such as the following program.
PGM DCL &LIBL *CHAR 2750 DCL &CMD *CHAR 2760 (1) RTVJOBA USRLIBL(&LIBL) (2) CHGLIBL (QGPL QTEMP) . . . (3) CHGVAR &CMD ('CHGLIBL (' *CAT &LIBL *TCAT ')') (4) CALL QCMDEXC (&CMD 2760) . . . ENDPGM