Progress supports one dimensional arrays, but they are called EXTENTS
.
/* Define a character array with the length 5, and display it's length */
DEFINE VARIABLE a AS CHARACTER EXTENT 5 NO-UNDO.
DISPLAY EXTENT(a).
Individual positions i the array is accessed using "standard" c-style brackets. But the index starts at 1. The maximum size is 28000.
a[1] = "A".
a[2] = "B".
a[3] = "C".
a[4] = "D".
a[5] = "E".
DISPLAY a[5].
Result:
Index 0 will generate an error:
DISPLAY a[0].
Result:
You can also define a indeterminate array without a set length. The length (extent) can be set in run-time. But only once!
DEFINE VARIABLE a AS CHARACTER EXTENT NO-UNDO.
EXTENT(a) = 10.
EXTENT(a) = 1.
The third line will procude the following error:
You can use the INITIAL
option on the DEFINE VARIABLE
statement to set initial values.
DEFINE VARIABLE a AS CHARACTER EXTENT 3 INITIAL ["one","two","three"] NO-UNDO.
/* Some statements (like DISPLAY) can handle a whole array: */
DISPLAY a.
Result:
If you don't set all extents the remaining will get the last set value:
DEFINE VARIABLE a AS CHARACTER EXTENT 10 INITIAL ["one","two","three"] NO-UNDO.
DISPLAY a.
Result: