# Software Engineers Handbook/Language Dictionary/PLI/arrays

Note: This article requires basic knowledge of PL/I which can be found in Software Engineers Handbook/Language Dictionary/PLI.

### Declaring Arrays

Simple arrays may be declared with the following syntax:
If lower bound is omitted it will get the default value 1.
Multi-dimension array are declared by separating the dimensions with commas.
Elements of an array may not only be simple types like numbers, strings or pointers but also entry variables, files, structures ...

### Initialising an Array

An array may be initialised by the use of the INITIAL (abbr: INIT) attribute. Initialisation has to be done for every array element individually. To specify a single element to be uninitialised an asterisk may be used.
In the examples below program left will be equivalent to program right.
For making it more comfortable to initialise a huge array an iteration-factor (prefix "(n)" meaning: use following value(s) n-times ) may be used.
Be aware: PL/I also offers iteration factors for strings, e.g. the expression "(4)X" is equivalent to "XXXX". So if an array of strings is initialised it must be clear whether an iteration factor is for the string or for the initialisation.

### Evaluation of Array Expressions

* An array expression may contain both arrays and single values
* All arrays in the expression must have the same structure, i.e. they must have the same number of dimensions, and corresponding dimensions must have identical bounds
* The result of the expression has the same structure as the contained array(s)
* The result of the expression may be assigned to an array variable having the same structure
In the examples below program left will be equivalent to program right.
All operations performed on arrays are done in an element-by-element-way, in right-to-left-dimension order.

### Cross Sections of Arrays Using Asterisks

Using asterisk notation a cross section of an array may be referred. The asterisk specifies that the entire extent for this dimension will be used.
In the examples below program left will be equivalent to program right.

### Re-Defining an Existing Array

A new declared array may be mapped to an existing "old" array by using the DEFINED (abbr: DEF) attribute.
In the examples below program left will be equivalent to program right.
To refer to designated elements of the old array the declaration of the new array may contain iSUB elements.
iSUB means: Whenever an access to the new array will be done the i-th index of this refer will be used to calculate the index(es) of the old array.
In the examples below program left will be equivalent to program right.

### Connected and Unconnected Storage

Arrays will be stored connected in an element-by-element-way, in right-to-left-dimension order.
References to a cross section of an array may refer to unconnected storage.
References to a structured element inside an array will refer to unconnected storage.
References to defined array may refer to unconnected storage.

### Builtin Array Functions

Common functions:
* LBOUND ( A , i ) returns the lower bound of the i-th dimension of array A
* HBOUND ( A , i ) returns the higher bound of the i-th dimension of array A
* DIM ( A , i ) returns the extent of the i-th dimension of array A, i.e. DIM ( A , i ) = HBOUND ( A , i ) - LBOUND ( A , i ) + 1
The array A must not be an array of structures.
Mathematical functions:
* SUM ( A ) returns the sum of all the elements in array A
* PROD ( A ) returns the product of all the elements in array A
Logical functions: The builtin functions ANY and ALL requires an array of bit strings as argument. They will be explained in Software_Engineers_Handbook/Language_Dictionary/PLI/bit_strings.

### Restrictions

In PL/I for MVS arrays are restricted to the following limits:
* The maximum number of dimensions is 15
* The minimum lower bound is - 2,147,483,648 = - 2$^{31}$
* The maximum higher bound is + 2,147,483,647 = + 2$^{31}$ - 1
* The maximum memory size is 2,147,483,648 bytes = 2$^{31}$ bytes