Square brackets ([ ]) enclose array subscripts ([1], [2], etc.), initial values (such as [1,2,3,4]), or ranges (such as, [1 FOR 4]). The following sections describe these uses in more detail.

Array subscripts

In ABL, the first element of the array has an index value of 1. The following example shows how to reference array elements using a subscript:
VAR INT[4] myArray = [10,11,12,13].
MESSAGE myArray[1] myArray[2].

Initial values

The notation [n,n,n...] is only allowed for the INITIAL value in a DEFINE VARIABLE statement or during the initialization of the variable in the VAR statement, as shown in the following example:
DEFINE VARIABLE myArray AS INTEGER EXTENT 4 NO-UNDO INITIAL [10,11,12,13].
VAR INT[3] myArray2 = [20,21,22].
If you need to assign the elements in the array outside of those two statements, you have to do it one at a time, if the values are different. For example:
myArray[1] = 1.
myArray[2] = 2.
However, if the value is the same for all elements, you can just assign the one value to the array:
myArray = 1.

Ranges

The range notation [n FOR m] causes ABL to start with the nth array element and to work with that and the next m elements. In a range, you can use a variable for the first element, but the second element must be a constant. The range notation can be used in a statement where array elements are expanded automatically, such as DISPLAY, UPDATE, SET, EXPORT, and IMPORT. The following example shows how to use a range in a DISPLAY statement:
DEFINE VARIABLE myArray AS INTEGER EXTENT 4 NO-UNDO INITIAL [10,11,12,13].

DISPLAY myArray[1 FOR 4].
In the example, the DISPLAY statement expands to DISPLAY myArray[1] myArray[2] myArray[3] myArray[4].

See also

Work with one-dimensional arrays