Previous Topic Next topic Print topic


TYPE and Extent Expressions

Any extent expressions are inherited by a typed variable from that typed variable's type definition, as illustrated by the following example. A typed variable's dimensions and element lengths are dependent on the current values of the extent expressions.

/* TYPE DEFINITION */
DECLARE CHARX(N,N) CHAR( LENGTH(STRING) ) BASED, 
   N FIXED BINARY(15),
   STRING CHAR(80) VARYING;
/* TYPED VARIABLE */
DECLARE ARRAY TYPE(CHARX) BASED;

The evaluation of extents when the array is referenced follows the same rules that apply to the evaluation of based variables. In the following example, the variable array is declared in a different block from CHARX:

/*--------------------------------------------------*/
START:      PROCEDURE;
   DECLARE CHARX(N,N) CHAR( LENGTH(STRING) ) BASED, 
      N FIXED BINARY(15),
      STRING CHAR(80) VARYING;
      .
      .
      .
/*--------------------------------------------------*/
NEXT: PROCEDURE;
   DECLARE ARRAY TYPE(CHARX) BASED, 
      N FIXED BINARY(15),
      STRING CHAR(80) VARYING;
      .
      .
      .
END NEXT;
 
/*--------------------------------------------------*/
      .
      .
      .
END START;
/*--------------------------------------------------*/ 

In the preceding example, Open PL/I uses the declarations in procedure NEXT to evaluate the extent expressions of ARRAY. Declarations in the current block are always used to evaluate extent expressions, even for variables that have not been declared with the TYPE attribute. (In the preceding example, if procedure NEXT did not declare N and STRING, those variable declarations in procedure START would be used.)

If the REFER option is used in a type definition, the following are true:

Previous Topic Next topic Print topic