Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

INITIAL attribute

Initializing array variables
Initializing unions
Initializing static variables
Initializing automatic variables
Initializing based and controlled variables
Examples

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 structure or union variable can be initialized only by separate initialization of its elementary names, whether they are element or array variables. The INITIAL attribute cannot be given to constants, defined data, noncontrolled parameters, and non-LIMITED static entry variables.

The INITIAL attribute has three forms.

  1. 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.
  2. 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.)
  3. The third form, INITIAL TO, specifies that the pointer (or array of pointers) is initialized with the address of the character string specified in the INITIAL LIST. The string also has the attributes indicated by the TO keyword.

Read syntax diagramSkip visual syntax diagram               .-,--------.
               V          |
>>-INITIAL--(----| item |-+--)--| item: |----------------------->
 
>--+-*---------------------------+-----------------------------><
   +-| initial-constant |--------+
   +-reference-------------------+
   +-(expression)----------------+
   '-| iteration-specification |-'
 
iteration-specification:
 
|--(-+-iteration-factor-+-)--| iteration-item |-----------------|
     '-*----------------'
 
iteration-item:
 
|--+-*--------------------+-------------------------------------|
   +-| initial-constant |-+
   +-reference------------+
   |    .-,----.          |
   |    V      |          |
   '-(----item-+--)-------'
 
initial-constant:
 
|--+-+-----+--arithmetic-constant---------------------+---------|
   | +- + -+                                          |
   | '- - -'                                          |
   +-bit-constant-------------------------------------+
   +-character-constant-------------------------------+
   +-graphic-constant---------------------------------+
   +-entry-constant-----------------------------------+
   +-file-constant------------------------------------+
   +-label-constant-----------------------------------+
   '-+-----+-real-constant-+- + -+-imaginary-constant-'
     +- + -+               '- - -'
     '- - -'
 

and

Read syntax diagramSkip visual syntax diagram>>-INITIAL CALL--+-entry-reference-+--+------------------+-----><
                 +-generic-name----+  |   .-,--------.   |
                 '-built-in-name---'  |   V          |   |
                                      '-(---argument-+-)-'
 

Read syntax diagramSkip visual syntax diagram                                        .-,--------.
                                        V          |
>>-INITIAL TO--(--+-varying----+--)--(----| item |-+--)--------->
                  +-varyingz---+
                  '-nonvarying-'
 
>--| item: |----(see description under INITIAL)----------------><
 

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.

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.

The following example initializes all of the elements of A to X'00' 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 on dynamic loading, refer to 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 character string specified in the INITIAL LIST. Also specifies that the string has the attributes indicated by the TO keyword.

In the following example, 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'  );

You should not change a value identified by a pointer initialized with INITIAL TO. The value can be placed in read-only storage and an attempt to change it could result in a protection exception. Given the array pdays in the preceding example, then, the following assignment is illegal:

  dcl x char(30) varz based;

  pdays(1)->x = 'Sonntag';

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)