Natural for OpenVMS Version 6.3.12 for OpenVMS
 —  Statements  —

Initial/Constant Values for an Array

The array-init-definition option is used in the variable-definition option of DEFINE DATA LOCAL, DEFINE DATA INDEPENDENT, DEFINE DATA CONTEXT and DEFINE DATA OBJECT.

The array-init-definition option has the following syntax:

../graphics/sbo5.gif ALL           ../graphics/sbc5.gif

FULL LENGTH
LENGTH n

../graphics/cbc2.gif <character-s ...>

../graphics/dot3.gif
(

index[:index]
V

../graphics/cbc2.gif ,...3 )
<

constant
system-variable,...

>

This document covers the following topics:


Function

With an array-init-definition you 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 Defining Fields in the Programming Guide, particularly the following sections:

Top of page

Restriction

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

Top of page

Syntax Description

Syntax Element Description
ALL
ALL Option:

All occurrences in all dimensions of the array are initialized with the same value.

index
Index Option:

Only the array occurrences specified by the index are initialized.

If you specify index, you can only specify one value with constant; that is, all specified occurrences are initialized with the same value.

V
V Notation:

This notation is only relevant for multidimensional arrays if the occurrences of one dimension are to be initialized with different values.

V indicates an index range that comprises all occurrences of the dimension specified with V; that is, all occurrences in that dimension are initialized. Only one dimension per array may be specified with V. The occurrences are initialized occurrence by occurrence with the values specified for that dimension. The number of values must not exceed the number of occurrences of the dimension specified with V.

constant
Constant Value Option:

The constant (value) with which the array is to be initialized (INIT), or the constant to be assigned to the array (CONSTANT).

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

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

system-variable
System Variable Option:

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

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. A comma must not be used for this purpose, however, if the comma is defined as decimal character (with the session parameter DC).

FULL LENGTH

LENGTH n

Character/String Option:

As initial value, a variable can be filled, entirely or partially, with a specific single character or string of characters (only possible for variables of format A or U).

FULL LENGTH Option:

With FULL LENGTH, the entire array occurrence(s) are filled with the specified character or characters.

With LENGTH n, the first n positions of the array occurrence(s) are filled with the specified character or characters.

LENGTH Option:

A system-variable must not be specified with FULL LENGTH or LENGTH n.

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

Example of LENGTH n for Array:

In this example, the first 5 positions of each occurrence of the array will be filled with NONON.

DEFINE DATA LOCAL
1 #FIELD (A25/1:3) INIT ALL LENGTH 5 <'NO'> 
...
END-DEFINE

Numerous examples of assigning initial values to arrays are provided in Initial Values (and the RESET Statement) in the Programming Guide.

Top of page