CL Command Reference - DCL

CL Command List > DCL Reference

Description:

The Declare CL Variable (DCL) command defines the Control Language (CL) program variables that are used in CL procedures. CL variables are used to store and update data and to receive parameters from another program on a call. CL variables are known by name only within the program that declares them. They cannot be used outside a CL procedure except when they are referred to by some commands (such as the DSPPGMVAR command) used for debugging programs. However, the value in the variable can be passed to another program as a parameter. If a variable is declared, but not referred to by another command in a CL procedure, the variable is not included in the program when it is compiled. Each DCL command defines the attributes of one CL variable and declares its name in the program in which it is used.

Each CL variable in a program must be identified by one of the two declare commands. The Declare File (DCLF) command declares CL variables for display device files and database files. The DCL command declares all other CL variables.

Restrictions: The DCL command is valid only within a CL procedure. All declare commands (DCL, COPYRIGHT, DCLF, and DCLPRCOPT) must follow the PGM (Program) command and must precede all other commands in the program. The four types of declare commands can be intermixed in any order.


Examples:

Example 1: Specifying the CL Variable Length

DCL &ABLE *DEC LEN(5 2)

This command declares a CL variable named &ABLE that contains a decimal value. The value can never be greater than 999.99 because LEN specifies up to 5 digits, of which two are to the right of the decimal point. Because the VALUE parameter was not specified, and it is a numeric value, &ABLE is set to a value of zero (000.00).



Example 2: Specifying a Logical Value

DCL &SWITCH *LGL

This command declares a CL variable named &SWITCH to contain a logical value. Because the type parameter specifies logical, the variable is one character long and it is set to ¡¯0¡¯.



Example 3: Specifying Initial Value of CL Variable

DCL &FILNAM *CHAR VALUE(FILEA)

This command declares a CL variable named &FILNAM whose value is FILEA. Because the value contains 5 characters and the LEN parameter was not specified, the length of the variable is also 5 characters.



Example 4: Specifying Defined CL Variables

DCL &QUALOBJ *CHAR LEN(20)
DCL &OBJ *CHAR LEN(10) STG(*DEFINED) DEFVAR(&QUALOBJ 1)
DCL &LIB *CHAR LEN(10) STG(*DEFINED) DEFVAR(&QUALOBJ 11)

The first DCL command declares a 20-character variable in the program¡¯s automatic storage. The second DCL command declares a variable named &OBJ which refers to the first 10 characters of the &QUALOBJ variable. The last DCL command declares a variable named &LIB which can be used to reference the last 10 characters of the &QUALOBJ variable.



Example 5: Specifying Pointer CL Variables

DCL &CHAR *CHAR LEN(10)
DCL &PTR *PTR ADDRESS(&CHAR)

The second DCL command declares a pointer variable which is initialized to point to the &CHAR variable in the program¡¯s automatic storage.



Example 6: Specifying Based CL Variables

DCL &PTR *PTR
DCL &CHAR *CHAR LEN(10) STG(*BASED) BASPTR(&PTR)

The second DCL command declares a character variable which is found at the location addressed by the &PTR variable. Before the &CHAR variable can be used, the &PTR variable must be initialized to a valid address by using the %ADDRESS built-in function.



Example 7: Specifying Defined Pointer CL Variables

DCL &CHAR *CHAR LEN(48)
DCL &PTR *PTR STG(*DEFINED) DEFVAR(&CHAR 17)

The second DCL command declares a pointer variable in bytes 17 through 32 of the variable &CHAR.