Initial/Constant Values for an Array

For selected occurrences:

../graphics/cbo4.gif

(

index[:index]
V

, ../graphics/dot3.gif3 )

../graphics/cbo4.gif

 

FULL LENGTH
LENGTH n

<character-string, ../graphics/dot3.gif >

../graphics/cbc4.gif

../graphics/cbc4.gif

 
<

constant
system-variable

, ../graphics/dot3.gif >  

../graphics/dot3.gif

For all occurrences:

ALL

../graphics/cbo5.gif

 

FULL LENGTH
LENGTH n

<character-string>

../graphics/cbc6.gif

<

constant
system-variable

>

For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.

The array-init-definition option is used to define the initial/constant values for an array.

Note:
If, in the variable-definition option, the keyword INIT was used for the initialization, the value may be modified by any statement that affects the content of a variable. If the keyword CONST was used for the initialization, any attempt to change the value will be rejected by the compiler.

See also Field Definitions in the Programming Guide, particularly the following sections:

This section covers the following topics:


Restriction

For a redefined field, an array-init-definition is not permitted.

Syntax Description

Syntax Element Description
ALL
ALL Option:

All occurrences of the array are initialized with the same value.

The ALL option cannot be combined with any other initialization definitions.

index
Index Option:

The array occurrences specified by index are initialized.

If a single index or an index range is used, you can only specify a unique value (constant or system-variable) which is assigned to all occurrences.

Examples:

DEFINE DATA LOCAL
1 #FLD1 (A4/1:4)     INIT (1:3) <'A'>  /* A fills occurrences (1:3)
1 #FLD2 (A4/1:4)     INIT (*)   <'B'>  /* B fills all occurrences
1 #FLD3 (A4/1:2,1:4) INIT (2,3) <'C'>  /* C fills occurrence (2,3)
END-DEFINE
V
Index Notation V:

The special index notation V is used to fill a consecutive sequence of array occurrences with individual values (constant or system-variable).

You can specify the V notation for one dimension of an array only. The number of values provided must not exceed the number of occurrences of the specified dimension.

You can omit the V notation for a one-dimensional array because the V index is then used by default.

Example showing which values fill which occurrences when V is used:

DEFINE DATA LOCAL
1 #FLD4 (A4/1:3)     INIT (V)   <'A','B'>     /* A fills (1) B fills (2)
1 #FLD5 (A4/1:2,1:3) INIT (1,V) <'C','D'>     /* C, D fill (1,1:2)
                          (2,V) <'F','G','H'> /* F, G, H fill (2,1:3)
END-DEFINE
constant
Constant Value Option:

The constant (value) with which the array is to be initialized.

Occurrences for which no values are specified, are initialized with a default value.

In a list of consecutive occurrences, you can skip single occurrences by specifying commas (,) only. However, you must end the list with a particular value for the last occurrence.

For further information, see User-Defined Constants in the Programming Guide.

Note:
Multiple constant values/system variables must be separated either by the input delimiter character (as specified with the session parameter ID) or by a comma. If numbers are provided in the value list and a comma is defined as the decimal character (with the session parameter DC), either separate the comma from the value with an extra blank character or use the input delimiter character.

Example with ID=; and DC=, delimiter settings:

DEFINE DATA LOCAL
1 #FLD1 (A4/1:3)   INIT <'A',,'C'>
1 #NUM1 (N4,2/1:3) INIT <1 , 2 , 3>
1 #NUM2 (N4,2/1:3) INIT <1;2;3>
END-DEFINE
system-variable
System Variable Option:

The initial value for an array can also be the value of a Natural system variable.

See also the Note for constant.

FULL LENGTH <character-string>

LENGTH n <character-string>

Character String Option for Alphanumeric/Unicode Variables:

For a variable of the Natural data format A or U, a character-string (for example, 'ABC') can be used as an initial value which fills all or part of the variable field.

A character-string is a constant of the Natural data format A or U as described in Alphanumeric Constants and Unicode Constants in the Programming Guide.

FULL LENGTH Option:

With the FULL LENGTH option, a particular character-string is repeatedly moved to the specified array occurrence until the occurrence is completely filled.

LENGTH Option:

With the LENGTH n option, a particular character-string is repeatedly moved to the specified array occurrence until the first n positions of the occurrence are filled.

Example showing which values fill which occurrences:

DEFINE DATA LOCAL
1 #FLD1 (A6/1:3) INIT ALL FULL LENGTH <'X'>    /* XXXXXX in all occ.
1 #FLD2 (A6/1:3) INIT ALL   LENGTH 5  <'NO'>   /* NONON in all occ.
1 #FLD3 (A6/1:3) INIT (1:2) LENGTH 4  <'AB'>   /* ABAB in occ (1:2)
1 #FLD4 (A6/1:3) INIT (V) FULL LENGTH <'X','Y'>/* XXXXXX in occ. (1),
                                               /* YYYYYY in occ. (2)
END-DEFINE

Within one array-init-definition, only FULL LENGTH or LENGTH n can be specified; both notations must not be mixed.

Note:
For further example definitions of assigning initial values to arrays, see Example 2 - DEFINE DATA (Array Definition/Initialization).