How to use multi-dimensional array in progress

sivakiran

New Member
hi everyone,
will u please tell me, how to use multi dimensional arrays in progress 4 gl,
if not possible how it will be overcome...
 
No idea if there's an official answer to this, but could you use arrays of comma/pipe delimited values?
 
thanks for reply.
i alredy tried keeing coma , space
it's not working..
see the example below which i got in forum..



define temp-table mdArray
field x as integer
field y as integer
field z as integer
field payload as decimal
index mdIdx is unique primary x y z
.

function new_mdArray returns logical ( input x as integer, input y as integer, input z as integer, input p_init as decimal ):

define variable i as integer no-undo.
define variable j as integer no-undo.
define variable k as integer no-undo.

do i = 0 to x:
do j = 0 to y:
do k = 0 to z:

find mdArray exclusive-lock where mdArray.x = i and mdArray.y = j and mdArray.z = k no-error.
if not available mdArray then create mdArray.

assign
mdArray.x = i
mdArray.y = j
mdArray.z = k
mdArray.payload = p_init
.

end.
end.
end.

return true.

end.

function set_mdArray returns logical ( input x as integer, input y as integer, input z as integer, input p as decimal ):

find mdArray exclusive-lock where mdArray.x = x and mdArray.y = y and mdArray.z = z no-error.
if not available mdArray then create mdArray.

assign
mdArray.x = x
mdArray.y = y
mdArray.z = z
mdArray.payload = p
.

return true.

end.

function get_mdArray returns decimal ( input x as integer, input y as integer, input z as integer ):

find mdArray no-lock where mdArray.x = x and mdArray.y = y and mdArray.z = x no-error.
return ( if available mdArray then mdArray.payload else ? ).

end.

set_mdArray( 0, 0, 0, 99.99 ).

display get_mdArray( 0, 0, 0 ).
 
You can use extents for single dimensional arrays. Then you can use a pipe delimited list to make it multi-dimensional.

Code:
DEFINE VARIABLE lvMultiArray AS CHARACTER EXTENT 10 FORMAT "X(30)". 

DEFINE VARIABLE lvi AS INTEGER     NO-UNDO.
DEFINE VARIABLE lvj AS INTEGER     NO-UNDO.
DEFINE VARIABLE lvTemp AS CHARACTER   NO-UNDO.


DO  lvi = 1 TO 10:
  lvTemp = "".
  DO lvj = 1 TO 10:
    lvTemp = lvTemp + MIN(lvTemp,",") + STRING(lvj).
  END.
  lvMultiArray[lvi] = lvTemp. 
END.


DISP lvMultiArray WITH 2 COL.
It's not a full solution, and only works for 2D arrays, but shows what I mean. You could extent to more dimensions using other delimiters, but might become complicated.
 
You got an error in your code:

Code:
function get_mdArray returns decimal ( input x as integer, input y as integer, input z as integer ):

  find mdArray no-lock where mdArray.x = x and mdArray.y = y and [U][B]mdArray.z = x[/B][/U] no-error.
  return ( if available mdArray then mdArray.payload else ? ).

end.

Your using the x var instead of z in your find .
 
Don't go for these delimited list solutions, just build a temp-table. Much simpler.
 
Back
Top