Passing Arrays

To pass an array, use the following syntax in the calling procedure. Ensure that the array dimension in the calling statement matches the array dimension in the formal parameter list.

do PROC(.arrayName())

Example

The following example illustrates how to pass single and two-dimension arrays between procedures. When passing an array to a function, the syntax must match the type declaration syntax for both the formal parameters and the actual parameters. For example,

type RecordDEP dep() // Single dimension – dep(1), dep(2)

type RecordLN ln(,) // Two dimension - ln(1,2), ln(1,3)

 

set dep(CID1) = Db.getRecord("DEP","CID1")

set dep(CID2) = Db.getRecord("DEP","CID2")

do subr(.dep(),CID1,CID2)

subr(RecordDEP dep(),CID1,CID2)

quit

You can mix arrays of varying dimensions and named variables. However, every reference must be unique within the parameter list. For example,

type RecordDEP dep

type RecordDEP dep()

set dep = Db.getRecord("DEP",1)

set dep(CID1) = Db.getRecord("DEP","CID1")

set dep(CID2) = Db.getRecord("DEP","CID2")

do subr(dep,.dep(),CID1,CID2)

subr(RecordDEP dep, RecordDEP dep(),CID1,CID2)

quit