PGM (Program)
Purpose
The Program (PGM) command is used in a CL program source file to identify the start of a CL program that is to be compiled and to specify the parameters that are to be received by the program after it is compiled. If a PGM command is used, it must be the first command in the program source file; if a PGM command is not used, a PGM command without parameters is assumed. The name of the program is specified in the Create Control Language Program (CRTCLPGM) command that is used to create the CL program.
The PGM command also specifies any parameters that are passed to the program when it is called for processing by another program. For information about how constants are passed, see the PARM parameter description under the CALL command.
This program can be called by a Call (CALL) or Transfer Control (TFRCTL) command, or by a routing entry in a subsystem description. When the program is called by a CALL or TFRCTL command, the specified parameters can be passed to it.
Parameters defined in this command must be passed when the program is called. The parameters passed must be of the type, length, and order specified in this command. Each of the parameter values passed to this program can be a character string, a numeric value, or a CL variable. When received by this program, each value is given a different CL variable name. Each CL variable name must be defined in the CL source file by a separate DCL (Declare) command before the program is compiled. Up to 40 parameters can be passed.
ILE programs and procedures will not detect parameter mismatches between the calling programs or procedure and the called program or procedure. If the calling procedure passes more parameters than the called procedure expects, the called procedure will ignore the extra parameters. If the calling procedure passed fewer parameters than are specified on the called procedure PGM command, the result may be unexpected.
Restriction: This command is valid only in a CL program.
Optional Parameters
- PARM
- Specifies the names of one or more CL variables that are to receive the parameter values passed to this program. Specify a CL variable name for each of the values to be received from the calling program; the name must start with an ampersand (&). Null values, *N, cannot be specified for any parameter. The parameter values are associated with the variables in the PARM parameter in the order in which they were specified on the CALL or TFRCTL commands. The type and length of each value passed must have matching attributes in the calling and receiving programs. However, for character constants, the receiving program can specify a shorter length; when this is done, the character string passed is truncated to the length declared in the receiving program. For information on how each data type is passed, see the description of the PARM parameter in the CALL command.
Note: If a parameter value is to be changed by a CL program or specified as a variable on a CL command, it must be in writeable storage. For example, in C/400, strings may be read only. If a read only string is passed as a parameter to a CL program, and the CL program attempts to change the value of the variable or uses the variable on a CL command, the CL program will fail. Examples for PGM
Example 1: Program Containing No Parameters
PGM * * * ENDPGMThis PGM command is the first command in a CL program source file for a program that contains no parameters.
Example 2: Program Containing Two Parameters
PGM PARM(&X &Y)This is the first command in a program source file for a program that contains two parameters, &X and &Y, that have values passed to them from the calling program.
Example 3: Program Containing Two Parameters in Positional Form
PGM (&PARM1 &PARM2)This is the first command in a program source file for a program that specifies two parameters in positional form, &PARM1 and &PARM2. When this program is called, the calling program passes, through the CALL or TFRCTL command, the values to be assumed for &PARM1 and &PARM2.
Error messages for PGM