how to define and use multi dimensional array (extent)

dayv2005

Member
yeah thats something i didnt like i think i posted this same post about a month or two ago too i was upset to hear that haha
 

TomBascom

Curmudgeon
Use a temp-table and some helper functions:

Code:
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 ).
 
Top