Command reference / CL
DCL
Declare CL Variable
Defines the CL program variables used in a CL program or ILE CL procedure. Variables store and update data and can receive parameters on a call. A variable is known only within the program that declares it, and it is not included in the compiled program if it is never referred to. Each DCL command defines one variable. DCLF declares display and database file variables.
Allowed environments: *BPGM, *IPGM.
Use within a CL program.
Positional parameters: 4.
Restrictions
- DCL is valid only within a CL program or ILE CL procedure.
- All declare commands (DCL, COPYRIGHT, DCLF, and DCLPRCOPT) must follow the PGM command and come before all other commands. The four declare types can be mixed in any order.
Parameters
VAR
CL variable name
Names the CL variable to declare. The name must start with an ampersand (&). This parameter is required.
TYPE
Type
Specifies the type of value the variable holds. This parameter is required and cannot be supplied by a CL variable.
Allowed values:
*DEC, *CHAR, *LGL, *INT, *UINT, *PTR
*DEC- Decimal variable holding a packed decimal value.
*CHAR- Character variable holding a character string.
*LGL- Logical variable holding '1' or '0'.
*INT- Integer variable holding a signed binary value.
*UINT- Integer variable holding an unsigned binary value.
*PTR- Pointer variable holding an address.
STG
Storage
Specifies the storage type of the variable.
Allowed values:
*AUTO, *BASED, *DEFINED
*AUTO- Storage is allocated in automatic storage.
*BASED- Storage is based on the pointer named in BASPTR, which must hold a valid address before use.
*DEFINED- Storage is provided by the variable named in DEFVAR.
LEN
Length of variable
Specifies the length of the variable. For character or integer types this is bytes, and for decimal types the maximum digits, with optional decimal positions. Pointers have a fixed length of 16 bytes, so LEN cannot be specified with *PTR.
Elements in order
Length
Length
Decimal positions
Decimal positions
VALUE
Initial value
Specifies the value assigned when the variable is declared. If omitted, character variables are blanks, numeric variables are zero, and logical variables are '0'. Not allowed for *PTR variables or variables declared with *DEFINED or *BASED.
BASPTR
Basing pointer variable
Names the *PTR variable that is the basing pointer for a *BASED variable. Required when STG(*BASED) is specified.
DEFVAR
Defined on variable
Names the variable this variable is defined on, with an optional starting position (1 to 32767, default 1). Required when STG(*DEFINED) is specified. The defined variable cannot extend past the end of the variable it is defined on.
Elements in order
CL variable name
CL variable name
Position
Position
ADDRESS
Address
Specifies the initial address for a *PTR variable. Only allowed for a pointer declared with STG(*AUTO). Takes a CL variable name and an offset from 0 to 32766.
*NULL- The pointer is initialized to a null value.
Elements in order
CL variable name
CL variable name
Offset
Offset
Examples
DCL &ABLE *DEC LEN(5 2)
Declares a decimal variable that can hold up to 999.99, because LEN allows five digits with two to the right of the decimal point. Without VALUE it starts at zero.
DCL &SWITCH *LGL
Declares a one-character logical variable, initialized to '0'.
DCL &FILNAM *CHAR VALUE(FILEA)
Declares a character variable with the value FILEA. With no LEN, its length is taken from the initial value, five characters.
Generated from os/cl/catalog/DCL.json and os/cl/help/DCL.json.