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

Parameters

VAR CL variable name

Names the CL variable to declare. The name must start with an ampersand (&). This parameter is required.

Type
*VARNAME
Required
Yes
Length
10
Case
Uppercase

TYPE Type

Specifies the type of value the variable holds. This parameter is required and cannot be supplied by a CL variable.

Type
*CHAR
Required
Yes
Length
5
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*AUTO
Length
8
Case
Uppercase

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.

Type
*ELEM
Required
No
Case
Uppercase
Elements in order

Length Length

Type
*INT4
Required
No
Case
Uppercase

Decimal positions Decimal positions

Type
*INT4
Required
No
Case
Uppercase

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.

Type
*CHAR
Required
No
Length
50
Case
Uppercase

BASPTR Basing pointer variable

Names the *PTR variable that is the basing pointer for a *BASED variable. Required when STG(*BASED) is specified.

Type
*VARNAME
Required
No
Length
10
Case
Uppercase

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.

Type
*ELEM
Required
No
Case
Uppercase
Elements in order

CL variable name CL variable name

Type
*VARNAME
Required
No
Length
10
Case
Uppercase

Position Position

Type
*UINT2
Required
No
Default
1
Range
1 to 32767
Case
Uppercase

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.

Type
*ELEM
Required
No
Case
Uppercase
*NULL
The pointer is initialized to a null value.
Elements in order

CL variable name CL variable name

Type
*VARNAME
Required
No
Length
10
Case
Uppercase

Offset Offset

Type
*UINT2
Required
No
Default
0
Range
0 to 32766
Case
Uppercase

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.

IBM command documentation

Generated from os/cl/catalog/DCL.json and os/cl/help/DCL.json.