Try OpenEdge Now
skip to main content
ABL Data Types Addenda
Arrays : Passing indeterminate arrays as parameters
 

Passing indeterminate arrays as parameters

An indeterminate array is useful in a reusable routine that can handle any size array.
Consider the following when passing indeterminate array parameters:
*You can pass a determinate array or a fixed indeterminate array to a routine whose corresponding parameter is a determinate array defined as an INPUT, INPUT-OUTPUT, or OUTPUT parameter with the same extent.
*You can pass an unfixed indeterminate array to a routine whose corresponding parameter is another unfixed indeterminate array defined as an INPUT, INPUT-OUTPUT, or OUTPUT parameter.
*You can pass a determinate array or an indeterminate array (fixed or unfixed) to a routine whose corresponding parameter is an unfixed indeterminate array. When passing a determinate or a fixed indeterminate array to an unfixed indeterminate array defined as either an INPUT or INPUT-OUTPUT parameter, the unfixed indeterminate array parameter inherits the fixed dimension from the calling routine (but its definition remains unfixed). When passing a fixed array to an unfixed indeterminate array defined as an OUTPUT parameter, the extents must match upon returning to the calling routine. In this case, the called routine must fix the extent by either applying the EXTENT statement or inheriting the fixed dimension from another called routine.
*You can pass an unfixed indeterminate array to a routine whose corresponding parameter is a determinate array defined as an OUTPUT or INPUT-OUTPUT parameter. In this case, the unfixed indeterminate array inherits the fixed dimension from the called routine. Likewise, an unfixed indeterminate array inherits the dimension of an indeterminate array parameter fixed using the EXTENT statement in the called routine. You cannot pass an unfixed indeterminate array to a routine whose corresponding parameter is a determinate array defined as an INPUT parameter.
*You cannot pass an unfixed indeterminate array to a COM object, DLL routine, or UNIX shared library routine.
The following example passes a determinate array as an input parameter to a routine that defines the parameter as an unfixed indeterminate array:
DEFINE VARIABLE x AS INTEGER EXTENT 3.

RUN foo (INPUT x).

PROCEDURE foo:
DEFINE INPUT PARAMETER x AS INTEGER EXTENT.
MESSAGE EXTENT(x). /* Returns 3 */
END.
In this case, the unfixed indeterminate array parameter inherits the fixed dimension from the calling routine (but its definition remains unfixed).
The following example passes an unfixed indeterminate array as an output parameter to a routine that defines the parameter as a determinate array:
DEFINE VARIABLE x AS INTEGER EXTENT.

MESSAGE EXTENT(x). /* Returns ? */
RUN foo (OUTPUT x).
MESSAGE EXTENT(x). /* Returns 4 */

PROCEDURE foo:
DEFINE OUTPUT PARAMETER x AS INTEGER EXTENT 4.
END.
In this case, the unfixed indeterminate array parameter inherits a fixed dimension from the called routine.
The following example passes an unfixed indeterminate array as an output parameter to a routine that also defines the parameter as an unfixed indeterminate array, but fixes the dimension of the array using the EXTENT statement:
DEFINE VARIABLE x AS INTEGER EXTENT.

MESSAGE EXTENT(x). /* Returns ? */
RUN foo (OUTPUT x).
MESSAGE EXTENT(x). /* Returns 4 */

PROCEDURE foo:
DEFINE OUTPUT PARAMETER x AS INTEGER EXTENT.
EXTENT(x) = 4. /* Fixes the extent to 4 */
END.
In this case, the unfixed indeterminate array parameter also inherits a fixed dimension from the called routine.