CL Command Reference - CALL

CL Command List > CALL Reference

Description:

The Call (CALL) command calls the program named in the command, and passes control to it. Optionally, the program or user issuing the CALL command can pass parameters to the called program. The CALL command can be used in batch jobs, in interactive jobs, and in both compiled and interpreted control language (CL). When the called program finishes processing, it can return control to the calling program using the RETURN command.

If the CALL command is issued by a CL procedure, each parameter value passed to the called program can be a character string constant, a numeric constant, a logical constant, a floating-point constant, or a CL variable. If a floating-point constant is specified, the value is converted to double-precision format and passed to the called program. If parameters are passed, the value of the constant or variable is available to the program that is called. Parameters cannot be passed in any of the following forms: lists of values, qualified names, expressions, null parameters (that is, a parameter whose value is null, specified by *N), or keyword parameters. Up to 255 parameters can be passed to the called program.

If parameters are passed to a program using the CALL command, the values of the parameters are passed in the order in which they appear on the CALL command; this order must match the order in which they appear in the parameter list in the calling program.

Parameters in a called program can be used in place of its variables. However, no storage in the called program is associated with the variables it receives. Instead, if a variable is passed, the storage for the variable is in the program in which it was originally declared. If a constant is passed, a copy of the constant is made in the calling program and that copy is passed to the called program.

The result is that if a variable is passed, the called program can change its value and the change is reflected in the calling program. If a constant is passed, and its value is changed by the called program, the changed value is not known to the calling program. Therefore, if the calling program calls the same program again, the values of constants will be to their original values.

Restrictions:

. You must have object operational (*OBJOPR) and execute (*EXECUTE) authorities to the program to be called, and *EXECUTE authority to the library where the program is located.

. The CALL command is threadsafe, meaning that it can be used to call a program when the CALL command is run in a job with multiple threads. No checking is done whether or not the program to be called is threadsafe.


Examples:

Example 1: Calling a Program

CALL PGM(PAYROLL)

The program named PAYROLL is called with no parameters being passed to it. The library list is used to locate the called program.


Example 2: Passing a Character Constant

CALL PGM(PAYROLL) PARM(กฏ1กฏ)

The program named PAYROLL is called with a character constant passed as a quoted string. The program must declare a field of up to 32 characters to receive the constant. The library list is used to locate the called program.


Example 3: Passing Parameters

CALL PGM(LIB1/PAYROLL) PARM(CHICAGO 1234 &VAR1)

The program named PAYROLL located in library LIB1 is called. The calling program passes three parameters: a character string (CHICAGO), a decimal value (1234.00000), and the contents of the CL variable &VAR1. The attributes of the variable determine the attributes of the third parameter.


Example 4: Calling Program with Floating-Point Values

CALL PGM(PGM1) PARM(1.5E3 *INF)

The program named PGM1 is called with two double-precision floating-point values being passed to it.