|Library in AS400
AS/400 system is an object-oriented system which means that everything on AS/400 system is an object. Now the question arises in our mind that where actually these objects reside in the AS/400 system. Any guess?
The answer to your question is the Library. A library is a collection of objects and itself an object of type *LIB.
The library contains database files, programs, etc. Also, It is used as a system directory(*DIR) to keep track of the other objects.
We can move or copy the objects of one library to the other library at any time we want. To locate an object we must qualify that object with its library for example LIB1/OBJECT1. The CL language commands are used to move or copy objects from one library to other.
As we come to know the library is in itself an object and contains other objects of different types except for libraries objects(*LIB) but what about the library where it gets stored?
In simple terms, we say library objects reside in a library whose name is QSYS library. Does It mean a library can store another library?
Oh no! this gonna create confusion among us but don't get confused with this. QSYS is the only library that stores other library objects but no other library can store a library object in itself.
You can every library object that appears to be inside QSYS even the QSYS itself as shown below. So it's a root library where all the system and user-defined, product libraries get created.
- Library Objects in QSYS
Therefore, whatever library you create that gets created inside root library QSYS. For example in my case, my library name starts with EASYCLASS* gets created inside the QSYS library as shown below.
|Library objects inside QSYS
In general, all the libraries created by IBM for OS use begin with the letter 'Q' such as QSYS (System root library), QSYS2 (System library for CPI's,
QGPL (General purpose library)
(Job/session-specific temporary library created when the Job/session starts or deleted when the Job/session ends), etc. QTEMP is a TEST library while others are PROD libraries. You will get detailed information about TEST or PROD libraries type in the below blog.
The product library is supplied with IBM products and gets added to the library list automatically when any IBM product is used internally and removed from the library list when the product Job finished. For example, I am going to use the IBM product Code Coverage explicitly and IBM provided the product library QDEVTOOLS for that purpose so I need to add the QDEVTOOLS library to the library list before using the IBM Code Coverage product in my Job.
|QDEVTOOLS, a product library
Libraries are created by users using the CL command CRTLIB. You need to specify the library name its type and text etc.
|CRTLIB command prompt
We can provide the Library Type above as either *PROD or *TEST which is displayed on the above CRTLIB screenshot. Now, what each value means let's discuss them one by one.
During library creation using CRTLIB command the default value for the Library type is *PROD i.e. production library. If we create a library of type *PROD then it specifies that whether or not database files in a production library can be opened for updating records, or for adding new records, while the job is in DEBUG mode.
If we specify *NO in the update production files (UPDPROD) parameter on the Start Debug (STRDBG) command then Database files in production libraries cannot be updated while the job is in debug mode. Database files can be opened for reading purposes only.
|STRDBG command, UPDPROD parameter
All the objects present inside the Test libraries can be updated during testing even if UPDPROD is specified as *NO on the Start Debug (STRDBG) command.
We heard the term library list in the above blog, so let's discuss the concept of a library list. To find an object we need to provide its path, so here we must qualify an object with the library name for its searching, for example, LIB1/FILE1 which means we are pointing to an object named FILE1 in library LIB1.
What about when we do not qualify the objects with their library name or we do not provide the path where to find that object then how the system decides where to look for that object the answer is an object called a library list (*LIBL) in AS400 which is similar to PATH in Unix and MS-DOS.
This library list specifies which libraries will get searched and in what order for an object. A default library list is automatically created by the operating system of the AS400 system for each job being started. Your default library i.e. same name as the User profile automatically added to the library list.
Display Library List (DSPLIBL)
For your information, we can have a maximum of up to 15 system libraries and 250 user libraries in the library list.
Now let's discuss the Types of libraries in brief in the library list.
A Job/session library list consists of four sections namely, SYS, PROD, CUR, and USR.
- System portion
The system libraries are always present at the top of the library list such as QSYS, QSYS2, QHLPSYS, QUSRSYS as shown in the above DSPLIBL screenshot. There can max 15 System libraries present on the library list.
Please note that the default system libraries portion on the library list is specified in the system value QSYSLIBL.
To see the content of the system value QSYSLIBL use the following command on the command line.
System part of the library list
- Product portion
When any CL command got executed then the product library for that CL command gets added to the library list and removed once that command ends.
- Current Library
This is a special library that is associated with the User profile so once users log in this library is added to the library list automatically and there can be only one current library at a time on the library list. In our case, the current library is EASYCLASS1 if you refer above DSPLIBL screenshot.
You can change the current library at any time using the CL command CHGCURLIB on the command line.
- User portion
This comes at the last of the library list that contains all the user-specified application libraries. Some user libraries are QTEMP, QGPL, etc. Users can add the library to the library list, edit the library list, change the library list and remove the library from the library list as follows.
The user portion of the library for any Job can be stored in JOBD (Job Description) so that when a Job starts it will use the library list specified on the JOBD. But Job descriptions can have a value of *SYSVAL which means that library list information must be looked into the system value QUSRLIBL.
- DSPSYSVAL QUSRLIBL
- DSPSYSVAL QUSRLIBL
ADDLIBLE (Add library list entry)
RMVLIBLE (Remove Library List Entry)