CL Programming


Working with Variables

CL procedures consist of CL commands, and the commands themselves consist of the command statement, parameters, and parameter values. IBM provides online information that explains the syntax rules for writing commands. Refer to the CL section of the Programming category in the iSeries Information Center for the explanation.

Parameter values may be expressed as variables, constants, or expressions. A variable is a named changeable value that can be accessed or changed by referring to its name. Variables can be used as substitutes for most parameter values on CL commands. When a CL variable is specified as a parameter value and the command containing it is run, the value of the variable is used as the parameter value. Every time the command is run, a different value can be substituted for the variable. Variables and expressions can be used as parameter values only in CL procedures and programs.

Variables are not stored in libraries; they are not objects; and their values are destroyed when the procedure that contains them is no longer active. The use of variables as values gives CL programming a special flexibility, because this allows high-level manipulation of objects whose content may change by specific applications. You might, for instance, write a CL procedure to direct the processing of other programs or the operation of several work stations without specifying which programs or work stations are to be controlled. The system identifies these as variables in the CL procedure. You can define (specify) the value of the variables when running the CL procedure.

All variables must be declared (defined) to the CL procedure before they can be used by the procedure:

The declare commands must precede all other commands in the procedure (except the PGM command), but they can be intermixed in any order.

In addition to the uses discussed in this section, variables can be used to:

Variables cannot be used to change a command name or keyword or to specify a procedure name for the CALLPRC command. Command parameters, however, can be changed during the processing of a CL procedure through the use of the prompting function. See Allowing User Changes to CL Commands at Run Time for more information.

It is also possible to assemble the keywords and parameters for a command and process it using the QCAPCMD API or QCMDEXC API. See Using the QCAPCMD Program and Using the QCMDEXC Program for more information.


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