Question New to PROGRESS

tomer

New Member
hi,
I wanted to know how do I get an array to a function?


FUNCTION avgint RETURNS INTEGER (INPUT arr AS INTEGER ):
 

TomBascom

Curmudgeon
Arrays are not usually a good idea but:

Code:
function x returns integer ( input a as integer extent 5 ):
  define variable i as integer no-undo.
  define variable z as integer no-undo.
  do i = 1 to 5:
  z = z + a[i].
  end.
  return z.
end.

define variable y as integer extent 5 initial [ 1, 2, 3, 4, 5 ].

display x( y ).
 

Cecil

19+ years progress programming and still learning.
Depending on the version of OpenEdge (10.1B I think), you can also use unassigned extents where the size of the extent has not been assigned a constant. The size of the extent defined at runtime making the function more dynamic in handling variable size extens.

As Tom said, try and avoid using extents/arrays. The alternative to arrays are temp-tables which can be a bit of a mine twist if you are coming from JAVA or PHP programming background.

Code:
function x returns integer ( input a as integer extent  ):
  define variable i as integer no-undo.
  define variable z as integer no-undo.
  do i = 1 to EXTENT(a): /** EXTENT function returns the size of the extent/array.**/
  z = z + a[i].
  end.
  return z.
end.
define variable y as integer extent.

EXTENT( Y ) = 5.

y[1] = 2.
y[2] = 4.
y[3] = 6.
y[4] = 8.
y[5] = 10.

display x( y ).
 
Top