INITIAL attribute
The INITIAL attribute specifies an initial value or values assigned to a variable at the time storage is allocated for it.
Only one initial value can be specified for an element variable. More than one can be specified for an array variable. A union variable can be initialized only by separate initialization of its elementary names, whether they are element or array variables. A variable that has a defined structure type can be initialized by using the VALUE type function together with the INITIAL attribute. The INITIAL attribute cannot be given to constants, defined data, noncontrolled parameters, and non-LIMITED static entry variables.
The INITIAL attribute has the following forms:
- The first form, INITIAL, specifies an initial constant, expression, or function reference, for which the value is assigned to a variable when storage is allocated to it.
- The second form, INITIAL CALL, specifies (with the CALL option) that a procedure is invoked to perform initialization. The variable is initialized by assignment during the execution of the called routine. (The routine is not invoked as a function that returns a value to the point of invocation.)
- The third form, INITIAL TO, specifies that the pointer (or array of pointers) is initialized with the address of the string specified in the INITIAL LIST. The string also has the attributes indicated by the TO keyword.
The INITIAL form is allowed on the elementary names of a DEFINE STRUCTURE statement, but the INITIAL CALL and INITIAL TO forms are not allowed. For more information about initializing the typed structure, see VALUE.
Abbreviations: INIT, INIT CALL, INIT TO
- *
- Specifies that the element is to be left uninitialized, except when the element is used as an iteration factor.
- iteration factor
- Specifies the number of
times the iteration item is to be repeated in the initialization of
elements of an array. The iteration factor can be an expression or an asterisk.
- An expression is converted to FIXED BINARY(31). For static variables, it must be a constant.
- An asterisk indicates that the remaining elements should be initialized to the specified value.
The use of an asterisk for both the iteration factor and the initial value is not allowed.
A negative or zero iteration factor specifies no initialization.
- constant
- reference
- expression
- These specify an initial value to be assigned to the initialized variable.
- INITIAL CALL
- For INITIAL CALL, the entry reference and argument
list passed must satisfy the condition stated for block activation
as discussed under Block activation.
INITIAL CALL cannot be used to initialize static data.
A to
'00'X without the need for the INITIAL attribute on each element:
dcl 1 A automatic,
2 …,
2 …,
2 * char(0) initial call plifill( addr(A), '00'X, stg(A) );An AUTOMATIC variable that has an INITIAL CALL attribute will be retained even if otherwise unused (in case the logic of your program requires that the call to be executed).
If the procedure invoked by the INITIAL CALL statement has been specified in a FETCH or RELEASE statement and it is not present in main storage, the INITIAL CALL statement initiates dynamic loading of the procedure. (For more information about dynamic loading, see Dynamic loading of an external procedure.)
- INITIAL TO
- Use only with static native pointers. Specifies that the pointer (or array of pointers) is initialized with the address of the string specified in the INITIAL LIST. Also specifies that the string has the attributes indicated by the TO keyword.
pdays is initialized
with the addresses of character varyingz strings
containing the names of the weekdays. dcl pdays(7) static ptr init to(varyingz)
('Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday' );pdays in the preceding example, the following
assignment is illegal: dcl x char(30) varz based;
pdays(1)->x = 'Sonntag';- INITACROSS
The INITACROSS attribute helps initialize one-dimensional arrays of structures where all the structure members are scalars in a way that makes it easy to add or delete elements to those arrays. The attribute specifies a series of comma lists of expressions where each comma list in turn specifies the set of initial values for a structure element in the array.
For example, consider the declaration:dcl 1 a(3) ,2 b char(2) init( 'DE', 'FR', 'SP' ) ,2 c char(40) var init( 'Germany', 'France', 'Spain' ) ;Using INITACROSS, you can simplify this declare by writing it as:dcl 1 a(3) initacross( ( 'DE', 'Germany' ) ,( 'FE', 'France' ) ,( 'SP', 'Spain' ) ) ,2 b char(2) ,2 c char(40) var ;Combined with DIMACROSS, it can become even easier to add elements to this declaration:dcl 1 a(*) dimacross initacross( ( 'DE', 'Germany' ) ,( 'FE', 'France' ) ,( 'SP', 'Spain' ) ) ,2 b char(2) ,2 c char(40) var ;Restrictions:- The INITACROSS and INITIAL attributes must not be specified for the same name.
- The INITACROSS attribute must be applied only to one-dimensional arrays of structures with no inherited dimensions.
- The INITACROSS structure members must all be scalars without the INITIAL attribute (since the INITACROSS attribute will give them an INITIAL attribute).
- The number of expressions in each comma list of expressions must match. The following is
invalid.
initacross( ( 'DE', 'Germany', 'Berlin' ) ,( 'FR', 'France', 'Paris' ) ,( 'SP', 'Spain' ) ) -
The explicit member count for an INITACROSSS structure must match the implicit member count defined by the number of elements in each of the INITACROSS comma lists. For example, in this (invalid) declare, the explicit member count for the structure is 2 (since A has the members B and C), but the implicit member count is 3 (since each expression comma list consists of 3 elements such as 'DE','Germany', and 'Berlin' ).
dcl 1 a(3) initacross( ( 'DE', 'Germany', 'Berlin' ) ,( 'FR', 'France', 'Paris' ) ,( 'SP', 'Spain', 'Madrid' ) ) ,2 b char(2) ,2 c char(40) var ;
