Previous Topic Next topic Print topic


TYPE

The TYPE attribute allows a declaration to inherit structure members and attributes from another declaration. It has the following format, where reference is a reference to a variable:

TYPE(reference)

or

TYPE reference

If, for example, a variable INTEGER is declared as fixed binary, another variable that needs to be declared as fixed binary can be declared as TYPE (INTEGER) instead. For example:

DECLARE INTEGER   FIXED BIN(31);    /* TYPE DEFINITION */
DECLARE CODE      TYPE(INTEGER);    /* TYPED VARIABLE */

In this example, Open PL/I copies the attributes from INTEGER to CODE, which makes the declaration of CODE become the following:

DECLARE CODE   FIXED BIN(31);

In the previous example, INTEGER is referred to as a type definition and CODE is referred to as a typed variable. A type definition is a normal variable declaration. It can be given the based storage class, because storage will not be allocated for the type definition.

In the following example, structure members are duplicated from one declaration to another by way of the TYPE attribute:

DECLARE 1 TEMPLATE BASED, /* TYPE DEFINITION */
   2 NAME CHAR(45),
   2 SALARY FIXED BIN(15), 
   2 EMP_NO FIXED BIN(15);
DECLARE EMPLOYEE_INFO TYPE TEMPLATE; /* TYPED VARIABLE */

Duplication of the members from TEMPLATE expands the declaration of EMPLOYEE_INFO, with the result that the declaration of EMPLOYEE_INFO is now:

DECLARE 1 EMPLOYEE_INFO
   2 NAME CHAR(45),
   2 SALARY FIXED BIN(15),
   2 EMP_NO FIXED BIN(15);

The TYPE attribute can be used in any of the following locations:

The following example illustrates all uses of the TYPE attribute:

/*----------- TYPE DEFINITION -----------*/
/* (LINE MAY ALSO BE USED AS A VARIABLE) */ 
DECLARE LINE CHAR(80) VARYING;
/*---------------------------------------*/
/* VARIABLE DECLARATION */ 
DECLARE FORMAT_LINE TYPE(LINE);

/* PARAMETER DECLARATION */ 
DECLARE PARAM TYPE(LINE);

/* PARAMETER DESCRIPTOR */
DECLARE WRITE_LINE ENTRY(TYPE(LINE));

/* RETURNS OPTION IN PROCEDURE STATEMENT */ 
GET_LINE: PROC RETURNS(TYPE(LINE));

/* RETURNS OPTION IN ENTRY STATEMENT */ 
READ_LINE: ENTRY RETURNS(TYPE(LINE));

/* RETURNS ATTRIBUTE IN DECLARE STATEMENT (USING ALTERNATE SYNTAX)*/ 
DECLARE GET_LINE ENTRY RETURNS(TYPE LINE);

A typed variable can inherit only the following attributes from its type definition (storage class is not inherited):

Previous Topic Next topic Print topic