
2 Dimensional Arrays in Progress
Progress does not have 2 dimensional arrays. Many people have done this many different ways. This way was the easiest for me to follow and understand. It may not be the fastest, but it works really well for me. I came up with this idea back in 1996, Progress v6. There might be a better way to do it now.
Your array looks something like this:
tVALUE EXTENT 9
| [1] | [2] | [3] | [4] | [5] | [6] | [7] | [8] | [9] |
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
1 | | | | | | | | | |
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
t 2 | | | | | | | | | |
R -----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
O 3 | | | | | | | | | |
W -----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
4 | | | | | | | | | |
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
5 | | | | | | | | | |
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
Normally, a 2 dim array is ARRAY[X,Y]. Here, the X is replaced by the field tRow, and the Y is the field tValue with an extent of 9. To display the array element ARRAY[4,6] you would find the temp-table record where tRow = 4 and display tValue[6].
/** DEFINE TEMP-TABLE **/
DEF TEMP-TABLE ttArray NO-UNDO
FIELD tRow AS INT
FIELD tValue AS CHAR EXTENT 9.
DEF VAR i AS INT NO-UNDO.
DEF VAR j AS INT NO-UNDO.
/** PUT SOME DATA IN TEMP-TABLE SO WE CAN SEE HOW THIS WORKS **/
DO i = 1 TO 10:
CREATE ttArray.
DO j = 1 TO 9:
ASSIGN ttArray.tRow = i
ttArray.tValue[i] = STRING(j).
END.
END.
/** NOW USE THE TEMP-TABLE LIKE A 2 DIM ARRAY **/
FIND FIRST ttArray NO-LOCK
WHERE ttArray.tRow EQ 4
NO-ERROR.
IF AVAIL(ttArray) THEN
DISP ttArray.tValue[6].
That's all there is to it! Hope this was helpful. :)