Arrays

Crittar

Member
Progress, unfortunately, does not support multi-dimensional arrays.

One work round to create the effect of a two diminsional array is to use a temp-table:

Code:
DEFINE TEMP-TABLE mytable NO-UNDO
  FIELD rec-num AS INTEGER /* functions as the array subscript */
  FIELD myarray AS CHARACTER EXTENT 10 /* substitute appropriate values */
  INDEX idx AS PRIMARY rec-num.

This approach is a little fiddly but does work. I haven't as yet come up with a work round for three dimensional arrays or above.

Hope this helps a little.
 

erich

New Member
For a 3 dimensional array, couldn't you also use a temp-table? It might be a bit clumsy, but I assume this would work...

def var v-x-counter as int no-undo.
def var v-y-counter as int no-undo.
def var v-z-counter as int no-undo.

Def TEMP-TABLE my-table
field v-x as int
field v-y as int
field v-z as int
field v-value as int. /*or char or whatever you want to store*/
/*then an index of your choosing*/

Now, create the table, say a 3x3x3 array
do v-x-counter = 1 to 3:
do v-y-counter = 1 to 3:
do v-z-counter = 1 to 3:
create my-table.
assign my-table.v-x = v-x-counter
my-table.v-y = v-y-counter
my-table.v-z = v-z-counter.
/*can assign array value here too, if you know them and wish to*/
end.
end.
end.

Now, you just do a FIND or FOR EACH to find the "array value" that you want.

Hope that helps, even if it's not the most elegant solution.
(sorry about the bad indenting, not sure how to get it to display nicely)
 
Hi,

We have got 1 dimensional array but unfortunately we dont have multi-dimensional arrays in Progress...

Some have told that we can go for temp table instead, that seems to be a nice idea but i have got another idea... Jus think logically, in any language we don have a thing like multi-dimensional array. Every multi-dimensional array is actually a single dimensional array(when getting stored). This could be clearly understood if u have got clear ideas on Pointers in C and C++...

So we can achieve 2 dimensional array in Progress jus by using basic mathemetical calculations...
 
Simulating a 2 Dimensional Array in Progress:

Hi,

The following code is a simulation of 2 Dimensional Array. Here i have used a single dimensional array as a 2 Dimensional Array, this is the way how lot of languages like C, C++, JAVA, Fortran uses 2 Dimensional Array...

Try something like this, so that u get a multi-dimensional array even in this manner. The important thing jus needed here is that, u need to know basic mathematical calculations and some logical thoughts....

******************************************************
/* This defines the total size of the array */
/* but must be less than 28000 which is the */
/* maximum size of the single dimensional array. */
/* U can specify the same through the parameter file */
&SCOPED-DEFINE maxi-size 1000

DEFINE VARIABLE array AS INTEGER EXTENT {&maxi-size} NO-UNDO.
DEFINE VARIABLE array-size AS INTEGER INITIAL 0 NO-UNDO.
DEFINE VARIABLE flag AS INTEGER INITIAL 0 NO-UNDO.
DEFINE VARIABLE rows AS INTEGER INITIAL 1 NO-UNDO.
DEFINE VARIABLE cols AS INTEGER INITIAL 1 NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE j AS INTEGER NO-UNDO.

/* Accepting values of rows and columns during run-time */
SET rows cols.

array-size = rows * cols.

/* check for array-size, as it should not exceed the */
/* size which u have specified as the maximum size */
IF array-size <= {&maxi-size} THEN
DO:
/* populating the values into the array as if using rows and cols */
DO i = 0 TO rows - 1:
DO j = 0 TO cols - 1:
array[(i * cols + j) + 1] = i * cols + j.
END.
END.
/* retrieving the stored values as if retrieving from a 2 dimensional array */
DO i = 0 TO rows - 1:
DO j = 0 TO cols - 1:
MESSAGE array[(i * cols + j) + 1]
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
END.
END.
ELSE
flag = 1.

IF flag = 1 THEN
MESSAGE "Array Index Out of Bound"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
*******************************************************

Thanks u...
 
Top