Access objects in CL programs

To access an object from a CL program, the object must be in the specified library when the command that refers to it runs.

Rules that refer to objects in CL program commands and procedures are the same as objects in commands that are processed individually (not within a program). Object names can be either qualified or unqualified. Locate an unqualified object name through a search of the library list.

Most objects referred to in CL procedures and programs are not accessed until the command referring to them is run. To qualify the name (library/name) of an object, it must be in the specified library when the command that refers to it runs. However, the object does not have to be in that library at the creation of the program. This means that most objects can be qualified in CL source statements that are simply based only on their run–time location.

You can avoid this run–time consideration for all objects if you do not qualify object names on CL source statements, but refer to the library list (*LIBL/name) instead. If you refer to the library list at compile time, the object can be in any library on the library list at command run time. This is possible providing you do not have duplicate-name objects in different libraries. If you use the library list, you can move the object to a different library between procedure creation and command processing.

Objects do not need to exist until the command that refers to them runs. Because of this, the CL program successfully compiles even though program PAYROLL does not exist at compile time:

   PGM /*TEST*/
   DCL...
   MONMSG...
   .
   .
   .
   CALL PGM(QGPL/PAYROLL)
   .
   .
   .
   ENDPGM
 

In fact, PAYROLL does not have to exist when activating the program TEST, but only when running the Call (CALL) command. This creates the called program within the calling program immediately prior to the Call (CALL command:

   PGM /*TEST*/
   DCL...
   .
   .
   .
   MONMSG
   .
   .
   .
   CRTCLPGM PGM(QGPL/PAYROLL)
   CALL PGM(QGPL/PAYROLL)
   .
   .
   .
   ENDPGM
 

Note that for create commands, such as Create CL Program (CRTCLPGM) or Create Data Area (CRTDTAARA), the object that is accessed at compile or run time is the create command definition, not the created object. If you are using a create command, the create command definition must be in the library that is used to qualify the command at compile time. (Alternately, it must be in a library on the library list if you used *LIBL.)

Related concepts
Parts of a CL procedure