CL Programming


CL Programming

The focus of this chapter is ILE rather than OPM. For this reason, 'procedure' is used rather than 'program' for this chapter. However, when the discussion is about CL commands in general, the word 'program' may still be used.

A CL procedure is a group of CL commands that tells the system where to get input, how to process it, and where to place the results. The procedure is assigned a name by which it can then be called by other procedures or bound into a program and called. As with other kinds of procedures, you must enter CL procedure source statements, compile, and bind them before you can run the procedure.

When you enter CL commands individually (from the Command Entry display, for instance, or as individual commands in an input stream), each command is separately processed. When you enter CL commands as source statements for a CL procedure, the source remains for later modification if you choose, and the commands are compiled into a module. This module remains as a permanent system object that can be bound into other programs and run. Thus, CL is actually a high-level programming language for system functions. CL procedures ensure consistent processing of groups of commands. You can perform functions with a CL procedure that you cannot perform by entering commands individually, and the CL program or procedure provides better performance at run time than the processing of several separate commands.

CL procedures can be used in batch or interactive processing. Certain commands or functions are restricted to either batch or interactive jobs.

CL source statements consist of CL commands. You cannot use all CL commands as CL source statements, and you can use some of them only in CL procedures or OPM programs. You can determine what restrictions you want placed on the use of CL commands. You can do this by checking the box in the upper right-hand corner of the syntax diagram of a command. An example that uses the Program (PGM) command is shown below:
Pgm: B,I

                                                 (2)
>>-PGM--+--------------------------------------+---------------><
        |        .------------------------.    |
        |        V                   (1)  |    |
        '-PARM(----&CL-variable-name------+--)-'
 
 

Notes:

  1. A maximum of 40 repetitions.

  2. All parameters preceding this point can be specified positionally.

You can find the syntax diagrams in the CL section of the Programming category in the iSeries Information Center.

The Pgm: B,I in the syntax diagram for the PGM command shows that this command can be used in either batch or interactive jobs, but can be used only within a CL program or procedure.

The commands that you can use only as source statements in CL programs and procedures will have Pgm: in the box. If the box does not contain this indicator, you cannot use the command as source for a CL program or procedure. IBM has online information about how to read a syntax diagram. Refer to the CL section of the Programming category in the iSeries Information Center.

CL source statements can be entered in a database source member either interactively from a work station or in a batch job input stream from a device. To create a program using CL source statements, you must enter the source statements into a database source member. You can then create an ILE program by compiling the source member into a module and binding the module into a program object.

CL procedures can be written for many purposes, including:

There are many advantages in using CL procedures for an application. For example:

You cannot use CL procedures to:


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]