Work with one-dimensional arrays
- Last Updated: February 2, 2026
- 5 minute read
- OpenEdge
- Version 12.8
- Documentation
Arrays are used in situations where you want multiple values for a variable. In ABL, there are only one-dimensional arrays. Unlike a list, which only applies to CHARACTER data, an array can be defined for any ABL data type. To define an array, you use the VAR statement or the DEFINE VARIABLE statement. You can optionally specify the size (extent) of the array, that is the number of elements the variable can hold. If you specify a size, then the variable is a determinate array. If no size is specified when defined, then the variable is an indeterminate array and its size can be set at runtime.
Define an array variable
VAR statement is:
|
DEFINE VARIABLE statement is:
|
name- The name of the variable.
type-name- An ABL data type.
size- An INTEGER value containing the maximum number of elements the array can hold. If size is specified, then the array is considered a determinate array and its size cannot change at run time. If size is not specified, then the array is considered an indeterminate array and its size can change at run time.
-
val1,...valn - An optional, comma-separated list of initial values for the variable. The values are enclosed in brackets. You are not required to initialize all elements of the array.
Example
|
Access an element of an array
In ABL, array elements are indexed. The first element of the array has an index value of 1. Unlike lists, you cannot efficiently look up an element in an array by value. To find a specific value, you must iterate all elements using an index. To access an element of an array, you enclose the index number in brackets.
|
|
For more information, see [ ] Array reference in the ABL Reference.
Determinate and indeterminate arrays
Whether the array is determinate (the size cannot change) or indeterminate (the size can change) depends on its definition.
To define a determinate array variable,
specify an integer value for size using either
the VAR or DEFINE
VARIABLE statement.
To define an indeterminate array
variable, do not specify a size in the variable definition statement. If initial
values are provided in the definition, then the initial size of the array will be
the number of values provided. If no initial values are provided, then the array
remains uninitialized and its size must be set at runtime before you can work with
it. The size of the indeterminate array can be set and reset at runtime using the
EXTENT statement.
|
An indeterminate array can be in one of two states: with a size (fixed) or without a size (unfixed). An indeterminate array does not have a size when first defined, unless initial values are provided. You can set the size of an indeterminate array with no size by:
- providing initial values. The size becomes the number of elements provided.
- setting the number of elements in the array using the
EXTENTstatement. - assigning an array with a size to the indeterminate array. The size becomes the size of the source array.
- passing array parameters to a procedure, user-defined function, or class-based method, so that the indeterminate array value is the target for the passing of a source array with a size. The array size becomes the size of the source array.
EXTENT function
?) is returned.
|
Running the code produces the output:
|
EXTENT statement
EXTENT statement:- Sets the number of elements for an indeterminate array variable or parameter
- Resizes an indeterminate array variable or parameter
EXTENT
statement on a determinate array; if you do, you get an error.The example code uses the EXTENT
statement to set the number of elements of an indeterminate array.
|
qtr1Sales array has ?
elements. |
Set the size: qtr1Sales
array has 4 elements. |
|
Assign a scalar value to all elements of an array
|
|
Assign an array to another array (deep copy)
You can assign one array to another (Deep copy arrays), provided it makes semantic sense to do so. When deep copying one array to another, the following rules apply:
- You can assign any array to an indeterminate array whose size is not set.
- You cannot assign an indeterminate array with no size to an array with a size (determinate or indeterminate)
- If either of the arrays are a determinate array, or an indeterminate array with a size, then the size must match. If the size does not match, then the AVM raises an error.
- You cannot assign a scalar value to an indeterminate array with no size.
The example code shows a determinate array assigned to another determinate array. They both have the same size.
|
Running the example code produces the output:
|