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:
For example, in the following program fragment, VAR1 is a type definition, and VAR2 is a corresponding typed variable. The BASED attribute and a REFER option are specified in the declaration of VAR1. Therefore, the BASED attribute must be specified in the VAR2 declaration.
DECLARE N FIXED BIN(15); /* TYPE DEFINITION: */ DECLARE 1 VAR1 BASED, 2 SIZE FIXED BIN(15), 2 ITEMS( N REFER(VAR1.SIZE) ) CHAR(80); DECLARE VAR2 TYPE(VAR1) BASED;
when expanded yields:
DECLARE 1 VAR2 BASED, 2 SIZE FIXED BIN(15), 2 ITEMS (N REFER (VAR2.SIZE)) CHAR(80);
For example, in the previous program fragment, VAR1.ITEMS cannot be used as a type definition.
For example, in the previous program fragment, VAR1.SIZE is the reference in the REFER option and must be a member of VAR1, the type definition. In addition, the expanded form of the VAR2 declaration contains a substitution of VAR2.SIZE for VAR1.SIZE as the REFER(reference).