TYPE Attribute Extensions

The TYPE attribute can be used to declare a function that returns an aggregate (that is, array or structure) result. For example:

/* TYPE DEFINITION */ 
DECLARE ARRAY(10) CHAR(80), 
   1 STRUCTURE,
      2 LEVEL1 BINARY(15)
      2 LEVEL2 BINARY(15)
DECLARE       FUNCTION1 ENTRY RETURNS(TYPE(ARRAY));
   FUNCTION2 ENTRY RETURNS(TYPE(STRUCTURE));
Note:

All extents in the type definition of the function must have constant values. For example, the dimension attribute of ARRAY (10) in the preceding declaration could not be a variable.

The TYPE attribute also allows an aggregate variable to be passed by value in one of the following two situations:

The parameter in the called routine must have the same TYPE attribute as the argument. In the above example, RTE's parameter has the attribute TYPE (XARR) (see the third line). This TYPE attribute is the same TYPE attribute that is used by the arguments in the subsequent calls to RTE (see the last 3 lines).

All extents in a type definition must have constant values when an aggregate variable is passed by value. For example, in the preceding program fragment, XARR. could not be declared as:

DECLARE N FIXED BINARY(31) INIT(10); 
DECLARE XARR(N) FIXED BIN(15),
      .
      .
      .

Dimensions (array bounds) can be specified on either the type definition or the typed variable, but not on both. For example, the following declaration of an array of arrays is invalid:

DECLARE XXX(10) CHAR(80), /* VALID */ 
   YYY TYPE( XXX ),
/* VALID */
   ZZZ(10) TYPE( XX );
/* INVALID -- ARRAY OF ARRAYS */