Working with Library Lists on IBM i

The library list provides an effective way for programs to locate objects on the system. The library list a list of system and user libraries. Library lists provide a means for the IBM i to search through designated libraries to find objects that we need.

Every job and user has an associated library list. When a user or program issues a command or names an object without specifying a library, the system uses the library list to find an object with a matching name. The library list can have a maximum of forty libraries and is scanned from top to bottom.

The library list is made up of four components, System Libraries, Product Libraries, the Current Library, and the User Library. The System Libraries section must exist and must at least contain the QSYS system library. It can have from one to fourteen other libraries. The system value QSYSLIBL contains this section. To display this value, issue the command DSPSYSVAL SYSVAL(QSYSLIBL).

The Product Libraries section is optional and can be temporary. The Product Libraries section comes into state when a menu or command is invoked that uses a product library. The Current Library section is optional as well. It contains the name of a single library that is considered to be current at the time.

The User Library section is required. This section will at least have the QTEMP library in it and can contain between 1 to 25 library names. Each user can have a different user library section. The system value QUSRLIBL contains the user portion of the library list. To display this value, issue the command DSPSYSVAL SYSVAL(QSYSLIBL).

We can view the commands associated with the library list by bringing up the Library List Command menu, which can be done by entering the command GO CMDLIBL. This menu lists six commands in total. The first is the Add Library List Entry command, ADDLIBLE. The second is the Change Library List command, CHGLIBL. The third command is the Change System Library List command, CHGSYSLIBL.

We can use the Display Library List command, DSPLIBL, to view the library list for the current interactive job. The libraries will be listed ordered by type and then alphabetically within the each type section.  This is the order that will be used to search for an object with an unqualified name. A search always begins with the library with the lowest sequence number, and goes up each sequence number until the object has been found. Note that the system libraries precede the user libraries.

On the screen brought up by the DSPLIBL command, the library name will be displayed, one library per line, along with the library’s type and the text description of the library. A system library is identified by SYS. A product library is identified by PRD. A user’s current library is identified by CUR, and the remaining user libraries are identified by USR. The DSPLIBL command offers one option; this option is option 5, which executes the DSPLIB command, allowing us to the view descriptions of the objects in the library.

Users can add libraries to or remove libraries from the user part of the library list, and can also change their sequence. There are three commands available for changing our library list, the Add Library List Entry command, ADDLIBLE, the Remove Library List Entry command, RMVLIBLE, and the Edit Library List command, EDTLIBL. The EDTLIBL command includes the functionality of both the ADDLIBLE and RMVLIBLE commands.

The Add Library command, ADDLIBLE, lets us add a library to the user portion of the library list. To start, let’s create an example library with the name TEMPLIB1 by executing the command CRTLIB LIB(TEMPLIB1). We can then add this new library to our library list with the command ADDLIBLE LIB(TEMPLIB1). Running the DSPLIBL command shows us that TEMPLIB1 has in fact been added to the library list.

The Add Library command, ADDLIBLE, has a POSITION parameter that enables us to specify where in the library list to add a new library. This parameter accepts the special values *FIRST, the default, *LAST, *BEFORE, *AFTER, and *REPLACE. The *BEFORE, *AFTER, and *REPLACE special values all use a reference library parameter for placing the new library relative to it. As an example, let’s create three new libraries, TEMPLIB2, TEMPLIB3, and TEMPLIB4 via the CRTLIB command. Next, let’s add TEMPLIB2 to our library list by issuing the command ADDLIBLE LIB(TEMPLIB2). If we then run the DISPLIBL command, we can see that TEMPLIB2 has been placed above TEMPLIB1, as *FIRST is the default position parameter. Next, let’s run the command ADDLIBLE LIB(TEMPLIB3) POSITION(*LAST). Executing the DSPLIBL command will show us that TEMPLIB3 has been added to the very end of the library list. Finally, let’s run the command ADDLIBLE LIB(TEMPLIB4) POSITION(*AFTER TEMPLIB2). Running the DISPLIBL command will then show us that TEMPLIB4 has been placed after TEMPLIB2, and before TEMPLIB1.

The Remove Library List Entry command, RMVLIBLE, requires only one parameter, the name of the library to be removed from the user portion of the library list. Let’s remove the library TEMPLIB1 from the library list by issuing the command RMVLIBLE LIB(TEMPLIB1).

One of the drawbacks of modifying the library list is that once we sign off the changes are lost. The next time we sign in the library list will be rebuilt with the libraries contained in the system values QSYSLIBL, for the system libraries, and QUSRLIBL, for the user libraries.

The Edit Library List command, EDTLIBL, provides the functions of both the ADDLIBLE and RMVLIBLE commands together. The EDTLIBL command doesn’t require any parameters, so we can just enter EDTLIBL and press Enter. Note that the EDTLIBL command can only be used in interactive mode, and it only displays the user portion of the library list.

The Change Library List command, CHGLIBL, allows us to change the user portion of the library list entirely. The LIBL paramter allows us to specify the names of the libraries to be placed in the user portion of the library list. For example, entering the command CHGLIBL LIBL(QGPL QTEMP) will replace the existing user portion of the list with the two libraries QGPL and QTEMP.

It’s also possible to alter our job’s copy of the system portion of the library list with the Change System Library List command, CHGSYSLBL. It only affects our job; it doesn’t affect other jobs on the system.The CHGSYSLIBL command lets us add a library at the very top of the system portion of the library list; we cannot control where in the system portion we are adding the library. For example, running the command CHGSYSLIBL LIB(TEMPLIB1) will add the library TEMPLIB1 to the top of the system library portion of the list. Running DSPLIBL will show that TEMPLIB1 is at the top of the list; unless the system value QSYSLIBL has been altered, this will place TEMPLIB1 above the library QSYS. We can remove a library from the system portion of the library list with the OPTION parameter; to remove the library TEMPLIB1 we would issue the command CHGSYSLIBL LIB(TEMPLIB1) OPTION(*REMOVE).

Instantly replace your tape backup with faster more reliable disk for IBM i and iSeries systems: http://laservault.com/lv-ubd/iseries-tapeless-backup-and-restore/

Advertisements
Working with Library Lists on IBM i