DIM({*AUTO:|*CTDATA|*VAR:}numeric_constant)
DIM(numeric_constant)
DIM(*AUTO : numeric_constant)
DIM(*VAR : numeric_constant)
DIM(*CTDATA)
The DIM keyword defines the number of elements in an array, table, a prototyped parameter, array data structure, or a return value on a prototype or procedure-interface definition.
The numeric constant is required unless the first parameter is *CTDATA. It must have zero (0) decimal positions. It can be a literal, a named constant or a built-in function.
The constant value does not need to be known at the time the keyword is processed, but the value must be known at compile-time.
When DIM is specified on a data structure definition, the data
structure must be a qualified data structure, and subfields must be referenced
as fully qualified names, i.e. "dsname(x).subf
". Other array keywords,
such as CTDATA, FROMFILE, TOFILE, and PERRCD are not allowed with an array
data structure definition.
DIM(*CTDATA)
When the first parameter for the DIM keyword is *CTDATA, the dimension of the array or table is determined by the number of records in the compile-time data for the array or table. The CTDATA keyword is not required.
DCL-S arr CHAR(10) DIM(*CTDATA); // 1
**CTDATA arr 2
abc
def
ghi
- DIM(*CTDATA) is only valid for standalone arrays and tables.
- The compile-time data must have one element per record. If the PERRCD keyword is specified, the parameter must be 1.
- If there is an alternate array or table, it must also be defined with DIM(*CTDATA).
- The compile-time data must be indicated by **CTDATA.
- The compile-time data must precede all other data.
Varying-dimension arrays
When the first parameter for the DIM keyword is *AUTO or *VAR, the dimension of the array is variable.
The second parameter for the DIM keyword represents the maximum number of elements for the array.
The number of elements for the array is initialized to zero. Any initialization values for the array are used when the dimension of the array is increased.
See Varying-dimension arrays for more information about varying-dimension arrays.