Chapter 2
Declarations
The declaration of a name in a PL/I program consists of a user-specified identifier and the attributes of the name. The attributes describe the following:
The data type of the name, that is, whether it is a computational data item (such as a number or a string) or noncomputational program data (such as a file constant or label)
The
storage-classto which the name belongs, that is, whether the compiler allocates storage for it, and how the storage is allocatedThe scope of the name, that is, whether the name is known only within the block in which it is declared and its contained blocks, or whether it is known in external blocks
A name is declared either explicitly in a DECLARE statement or implicitly by its appearance in a particular context. For example:
CALC: PROCEDURE;This statement is an implicit declaration of the name CALC as an entry constant.
This chapter describes the DECLARE statement and data attributes.
2.1. DECLARE Statement
The DECLARE statement specifies the attributes associated with names.
The format of the DECLARE statement is:
{ DECLARE } declaration [,declaration,...];
{ DCL }declarationOne or more declarations consisting of identifiers and attributes. A declaration has the following format:
[
level]declaration-itemlevelLevels are used to specify the relationship of members of structures; if a level is present in the declaration, it must be written first.
declaration-itemA
declaration-itemhas the following format:{identifier[(bound-pair,...)] } { (declaration-item,...) } { (identifier,...) [(bound-pair,...)] } [attribute...]
The format of the DECLARE statement varies according to the number and nature of the items being declared. The DECLARE
statement can list a single identifier, optionally specifying a level, bound-pair list, and other
attributes for that identifier. Alternatively, the statement can include, in parentheses, a list of declarations to which the
level and all subsequent attributes apply. The declarations in the second case can be simple identifiers or can include
attributes that are specific to individual identifiers.
Bound pairs are used to specify the dimensions of arrays. If bound pairs are present, they must be in parentheses and must immediately follow the identifier or the list of declarations. For example, (2:10), lower bound is 2 and upper bound is 10. Bounds can be any valid PL/I expression.
The various formats are described individually in the following sections.
2.1.1. Simple Declarations
A simple declaration defines a single name and describes its attributes. The format of a simple declaration is:
DECLAREidentifier[attribute...] ;
identifierA user-supplied name, containing a minimum of 1 character. On VAX the maximum number of characters is 31, while on Alpha the maximum number of characters is 64. The name must be unique within the current block.
An identifier can consist of any of the alphanumeric characters A through Z, a through z, 0 through 9, dollar signs ($), and underscores (_), but must begin with an alphabetic letter, dollar sign, or underscore. PL/I converts all lowercase letters to uppercase when it compiles a source program. The identifiers abc, ABC, Abc, and so on all refer to the same object.
attributeOne or more attributes of the name. Attribute keywords must be separated by spaces. They can appear in any order.
See Section 2.2, “Attributes” for a list of the valid attribute keywords and their meanings.
The following are examples of simple declarations:
DECLARE COUNTER FIXED BINARY (7); DECLARE TEXT_STRING CHARACTER (80) VARYING; DECLARE INFILE FILE;
Names that are not given specific attributes in a DECLARE statement or that are referenced without being declared, receive the default attributes FIXED BINARY (31,0) AUTOMATIC. Note that the compiler issues a warning message whenever it gives these default attributes to a name.
2.1.2. Declarations Outside Procedures
You can declare a variable outside any procedure. Any variable so declared will be visible within all procedures
contained by the module. The format for declarations outside procedures is the same as for other declarations, except that
the storage-class attribute cannot be AUTOMATIC. If a storage-class is
not specified or is specified as AUTOMATIC, the compiler will issue a warning and supply the STATIC attribute. The following
example shows the use of this type of declaration:
DECLARE A STATIC FIXED BINARY(31); . . . FIRST: PROCEDURE; DECLARE B FIXED BINARY(31); . . . END FIRST; SECOND: PROCEDURE; DECLARE C FIXED BINARY(31); . . . END SECOND;
In this example, variable A is visible in both the FIRST and SECOND procedures, but variables B and C are visible only in their containing procedures.
2.1.3. Multiple Simple Declarations
Multiple simple declarations define two or more names and their individual attributes. This format of the DECLARE statement is:
DECLAREidentifier[attribute...] [,identifier[attribute...]] ...;
When you specify more than one set of names and their attributes, separate each name and attribute set from the preceding set with a comma. A semicolon must follow the last name.
The following is an example of multiple declarations:
DECLARE COUNTER FIXED BINARY (7), TEXT_STRING CHARACTER (80) VARYING, Y FILE;
This DECLARE statement defines the variables COUNTER, TEXT_STRING, and Y. The attributes for each variable follow the name of the variable.
2.1.4. Factored Simple Declarations
When two or more names have common attributes, you can combine the declarations into a single, factored declaration. This format of the DECLARE statement is:
DECLARE (identifier[,identifier...]) [attribute...];
When you use this format, you must place names that share common attributes within parentheses and separate them with commas. The attributes that follow the parenthetical list of names are applied to all the named identifiers.
The following are examples of factored declarations:
DECLARE (COUNTER, RATE, INDEX) FIXED BINARY (7) INITIAL (0); DECLARE (INPUT_MESSAGE, OUTPUT_MESSAGE, PROMPT) CHARACTER (80) VARYING;
In these declarations, the variables COUNTER, RATE, and INDEX share the attributes FIXED BINARY (7) and are given the initial value of zero. The variables INPUT_MESSAGE, OUTPUT_MESSAGE, and PROMPT share the attributes CHARACTER (80) VARYING.
You can also specify, within the parentheses, attributes that are unique to specific variable names, using the following format:
DECLARE (declaration-item,declaration-item[,declaration-item])attribute...
For example:
DECLARE (INFILE INPUT RECORD, OUTFILE OUTPUT STREAM) FILE;
The DECLARE statement declares INFILE as a RECORD INPUT file and OUTFILE as an STREAM OUTPUT file.
The parentheses can be nested. For example:
DECLARE ( (INFILE INPUT, OUTFILE OUTPUT) RECORD, SYSFILE STREAM ) FILE;
The DECLARE statement declares INFILE as a RECORD INPUT file, OUTFILE as a RECORD OUTPUT file, and SYSFILE as a STREAM file.
2.1.5. Array Declarations
The declaration of an array specifies the dimensions of the array and the bounds of each dimension. This format of a DECLARE statement is:
DECLAREdeclaration(bound-pair,...) [attribute...];
where each bound pair has the following format:
{ [lower-bound:]upper-bound }
{ * }One bound pair is specified for each dimension of the array. The number of elements per dimension is defined by the bound pair. The extent of an array is the product of the numbers of elements in its dimensions. If the lower bound is omitted, the lower bound for that dimension is 1 by default.
You can use the asterisk (*) as the bound pair when arrays are declared as parameters of a procedure. The asterisk indicates that the parameter can accept array arguments with any number of elements. (If one dimension is specified with an asterisk, all must be specified with asterisks.)
For example:
DECLARE SALARIES(100) FIXED DECIMAL(7,2);
This statement declares a 100-element array with the identifier SALARIES. Each element is a fixed-point decimal number with a total of seven digits, two of which are fractional. The identifier in the statement can be replaced with a list of declarations, to declare several objects with the same attributes. For instance:
DECLARE (SALARIES,PAYMENTS) (100) FIXED DECIMAL(7,2);
This declares SALARIES and another array, PAYMENTS, with the same dimensions and other attributes.
For further details on how to specify the bounds of an array, and for examples of array declarations, see Section 4.1.1, “Array Declarations”.
2.1.6. Structure Declarations
The declaration of a structure defines the organization of the structure and the names of members at each level in the structure. This format of a DECLARE statement is:
{ DECLARE } level declaration-item [,level declaration-item ...];
{ DCL }Each declaration specifies a member of the structure and must be preceded by a level number. As shown in the following example, a single variable can be declared at a particular level; or the level can contain one or more complete declarations, including declarations of arrays or other structures. The major structure name is declared as structure level 1; minor members must be declared with level numbers greater than 1.
DECLARE 1 PAYROLL, 2 NAME, 3 LAST CHARACTER(80) VARYING, 3 FIRST CHARACTER(80) VARYING, 2 SALARY FIXED DECIMAL(7,2);
This statement declares a structure named PAYROLL.
Alternatively, because the last and first names have the same attributes, the same structure can be declared as follows:
DECLARE 1 PAYROLL, 2 NAME, 3 (LAST,FIRST) CHARACTER(80) VARYING, 2 SALARY FIXED DECIMAL(7,2);
For details and examples of structure declarations, see Section 4.2.1, “Structure Declarations and Attributes”.
2.2. Attributes
Attributes define and describe the characteristics of names used in a PL/I program. Each name in a PL/I program has a set of attributes associated with it. You can specify attributes in any of the following contexts:
In a DECLARE statement for an identifier. These attributes are specified either by keyword or by syntax. For example:
DECLARE SIGNAL CHARACTER (20);
In this declaration, the keyword attribute CHARACTER is associated with the identifier SIGNAL. The syntax length attribute of the variable is specified in parentheses following the CHARACTER keyword. In this manual, keyword attributes are shown in format lines in uppercase letters. Attributes given by syntax are shown in lowercase letters.
In an OPEN statement to describe a particular file. During the opening of a file, these attributes are merged with file description attributes specified in the declaration of the file.
Within the ENTRY attribute to describe the parameters of an external procedure. These attributes must match the attributes given to corresponding parameters specified in the PROCEDURE or ENTRY statements of the invoked subroutine or function.
Within the RETURNS attribute of a PROCEDURE or ENTRY statement to describe the value returned by a function.
Attributes can also be implied by the presence of other attributes. For example, if the RETURNS attribute is specified for an identifier, the compiler supplies the ENTRY attribute by default.
The entry for each attribute in this chapter gives its syntax and abbreviation (if any) and describes related and conflicting attributes. See Table 2.1, “Alphabetic Summary of PL/I Attributes” for a concise alphabetic summary of PL/I attributes.
Computational Data Type Attributes
The attributes that define arithmetic and string data are:
CHARACTER [ (length) ] [ VARYING ] [ NONVARYING ] BIT [ (length) ] [ ALIGNED ] [ UNALIGNED ] { FLOAT } { BINARY } [ [PRECISION] (precision[,scale-factor]) ] { FIXED } { DECIMAL } PICTURE 'picture'
You can specify these attributes for all elements of an array and for individual members of a structure.
Noncomputational Data Type Attributes
The following attributes apply to program data that is not used for computation:
AREA
CONDITION
ENTRY [VARIABLE]
FILE [VARIABLE]
LABEL
OFFSET
POINTER
Storage-Class and Scope Attributes
The following attributes control the allocation and use of storage for a computational variable and define the scope of the variable:
AUTOMATIC [INITIAL(
initial-element,...)]BASED [(pointer-reference)] [INITIAL(
initial-element,...)]CONTROLLED [INITIAL(
initial-element,...)]DEFINED(
variable-reference) [POSITION(expression)]STATIC [READONLY] [INITIAL(
initial-element,...)]PARAMETER
INTERNAL
EXTERNAL [ GLOBALDEF [(
psect-name)] {VALUE | READONLY} ] [ GLOBALREF ]
Member Attributes
You can apply the following attributes to the major or minor members of a structure:
LIKE
MEMBER
REFER
STRUCTURE
TYPE
UNION
File Description Attributes
You can apply the following attributes to file constants and used in OPEN statements:
ENVIRONMENT(option,...)
{ RECORD [KEYED] } { STREAM } { INPUT } { OUTPUT [PRINT] } { UPDATE }{ DIRECT } { SEQUENTIAL }
Entry Name Attributes
You can apply the following attributes to identifiers of entry points:
ENTRY [VARIABLE] [OPTIONS (VARIABLE)]
[RETURNS (returns-descriptor)]
BUILTINNondata Type Attributes
You can apply the following attributes to data declarations:
ALIGNED
DIMENSION
UNALIGNED
Table 2.1, “Alphabetic Summary of PL/I Attributes” lists the PL/I attributes. The sections following this table describe each attribute in detail.
| Attribute | Use |
|---|---|
| ALIGNED | Requests alignment of bit-string variables in storage |
| ANY | Indicates that a parameter (of an external procedure not written in PL/I) can have any data type |
| AREA [(extent)] | Defines an area of storage for the allocation of based variables |
{ AUTOMATIC }
{ AUTO }
| Requests dynamic allocation of storage for a variable |
| BASED [(pointer-reference)] | Indicates that a variable's storage is located by a pointer |
{ BINARY }[(
| Defines a binary base for arithmetic data |
| BIT [(length)] | Defines bit-string data |
| BUILTIN | Defines a built-in function name |
{ CHARACTER } [(
| Defines character-string data |
{ CONDITION } (
| Defines an identifier as a condition name |
{ CONTROLLED }
{ CTL }
| Defines a variable whose storage is allocated and freed in successive and fixed-sequence generations |
{ DECIMAL }[(
| Defines a decimal base for arithmetic data |
{ DEFINED } (
| Indicates that a variable will share the storage allocated for another variable |
{ DESCRIPTOR }
{ DESC }
| Requests that an argument be passed to an external non-PL/I procedure by descriptor |
{ DIMENSION } (
| Indicates that a variable is an array, and defines the number and extent of its dimensions |
| DIRECT | Specifies that a file will be only accessed randomly |
| ENTRY (descriptor,...) | Describes an external procedure and its parameters |
{ ENVIRONMENT } (
| Specifies system-dependent information about a file |
{ EXTERNAL }
{ EXT }
| Identifies the name of a variable whose storage is referenced or defined in other procedures |
| FILE | Identifies a PL/I file constant or file variable |
FIXED [(precision[,scale-factor])] | Defines a fixed-point arithmetic variable |
| FLOAT [(precision)] | Defines a floating-point arithmetic variable |
GLOBALDEF [(psect-name)] | Defines an external variable and optionally specifies the program section in which the variable will reside |
| GLOBALREF | Declares an external variable which is defined in an external procedure |
{ INITIAL } (
| Provides initial values for variables |
| INPUT | Specifies that a file will be used for input |
{ INTERNAL }
{ INT }
| Limits the scope of a variable to the block in which it is defined |
| KEYED | Specifies that a file can be accessed randomly by key |
| LABEL | Defines a label variable |
| LIKE structure-reference | Copies the declaration of a structure to another structure variable |
| LIST | Specifies that a parameter can accept a list of actual parameters, of arbitrary length |
| MEMBER | Specifies that an item is a member of a structure |
{ NONVARYING }
{ NONVAR }
| Specifies that the length of a string is nonvarying |
OFFSET [(area-reference)] | Defines an offset variable |
| OPTIONAL | Specifies, in the declaration of a formal parameter, that the actual parameter need not be specified in a call |
| OUTPUT | Specifies that a file will be used for output |
{ PARAMETER }
{ PARM }
| Indicates that a variable will be assigned a value when it is used as an argument to a procedure |
{ PICTURE } 'picture'
{ PIC }
| Specifies the format of numeric data stored in character form |
{ POINTER }
{ PTR }
| Defines a pointer variable |
{ POSITION }
{ POS }
| Specifies the position within a variable at which a defined variable begins |
{ PRECISION } [(
| Specifies the number of digits in an arithmetic variable and, with fixed-point data, the number of fractional digits |
| Specifies that a file is to be formatted for printing | |
| READONLY | Specifies that a static variable's value does not change during program execution |
| RECORD | Specifies that a file will be accessed by record I/O statements |
| REFER | Defines dynamically self-defining structures |
{ REFERENCE }
{ REF }
| Requests that an argument be passed to an external non-PL/I procedure by reference |
RETURNS (returns-descriptor) | Specifies that an external entry is a function and describes the value returned by it |
{ SEQUENTIAL }
{ SEQL }
| Specifies that a file can be accessed sequentially |
| STATIC | Requests static allocation of storage |
| STREAM | Specifies that a file will be accessed by stream I/O statements |
| STRUCTURE | Specifies that a variable is a structure variable |
| TRUNCATE | Specifies, in a declaration of a formal parameter, that the actual parameter list can be truncated at the point where this argument should occur |
| TYPE | Copies declarations of structures, scalars, and arrays to another variable |
{ UNALIGNED }
{ UNAL }
| Specifies nonalignment for bit-string variables in storage |
| UNION | Indicates that a variable will share the storage allocated for another variable |
| UPDATE | Specifies that records in a file can be rewritten or deleted |
{ VALUE }
{ VAL }
| Requests either that a global symbol be accessed by value rather than by reference, or that an argument be passed to a procedure by immediate value |
| VARIABLE | Defines variable entry and file data |
{ VARYING }
{ VAR }
| Defines a varying-length character string |
2.2.1. ALIGNED Attribute
The ALIGNED attribute controls the storage boundary of bit-string data in storage. The format of the ALIGNED attribute is:
ALIGNED
You can specify the ALIGNED attribute in conjunction with the BIT attribute in a DECLARE statement to request alignment of a bit-string variable on a byte boundary. If you specify ALIGNED for an array of bit-string variables, each element of the array is aligned.
You can specify ALIGNED in the declaration of a nonvarying character-string variable. Specifying ALIGNED is not recommended with character strings, as all character strings are byte-aligned.
Restriction
The ALIGNED attribute conflicts with the VARYING attribute and is invalid with all data-type attributes other than BIT and CHARACTER. You must specify either BIT or CHARACTER with the ALIGNED attribute.
2.2.2. ANY Attribute
The ANY attribute specifies that an entry's corresponding argument can be of any data type. This attribute is applicable only to the declaration of entry names denoting non-PL/I procedures. The format of the ANY attribute is:
ANY [ VALUE ] [ CHARACTER(*) ] [ REFERENCE ] [ DESCRIPTOR ]
Restrictions
If you specify ANY for a parameter, you cannot specify any data-type attributes for that parameter except CHARACTER(*). If ANY is used by itself, the parameter is passed by reference. If ANY is used with VALUE, the parameter is passed by immediate value. If ANY is used with CHARACTER(*), the parameter is passed by character descriptor.
Example
DECLARE SYS$SETEF ENTRY (ANY VALUE);
This statement identifies the system service procedure SYS$SETEF and indicates that the procedure accepts a single argument, which can be of any data type, to be passed by value. (Note that PLI$STARLET contains declarations for all system services, RTL routines, and utility routines.)
2.2.3. AREA Attribute
The AREA attribute defines an area variable. The format of the AREA attribute is:
AREA [(extent)]extentThe size of the area in bytes. The extent must be a nonnegative integer. The maximum size is 500 million bytes. The rules for specifying the extent are:
If AREA is specified for a static variable declaration, extent must be a restricted integer expression. A restricted integer expression is one that yields only integral results and has only integral operands. Such an expression can use only the addition (+), subtraction (-), and multiplication (*) operators.
If AREA is specified in the declaration of a parameter or in a parameter descriptor, you can specify extent as an integer constant or as an asterisk (*).
If AREA is specified for an automatic or based variable, you can specify extent as an integer constant or as an expression. For automatic variables, the extent expression must not contain any variables or functions declared in the same block, except for parameters.
If no extent is specified for the area, a default of 1024 bytes is provided. ESS recommends explicitly specifying a size, because the default varies considerably between PL/I implementations.
Restrictions
The AREA attribute is not allowed in a returns descriptor. The AREA attribute conflicts with all other data-type attributes.
2.2.4. AUTOMATIC Attribute
The AUTOMATIC attribute specifies, for one or more variables, that PL/I is to allocate storage only for the duration of a block. An automatic variable is not allocated storage until the block that declares it is activated. The storage is released when the block is deactivated. The format of the AUTOMATIC attribute is:
{ AUTOMATIC }
{ AUTO }AUTOMATIC explicitly defines the storage-class of a variable, array, or major structure in a
DECLARE statement. Because AUTOMATIC is the default for internal variables, you need not specify it.
Restriction
The AUTOMATIC attribute conflicts with the following attributes (the specification of which implies that storage allocation is not to be automatic):
| BASED | GLOBALREF |
| CONTROLLED | PARAMETER |
| DEFINED | READONLY |
| EXTERNAL | STATIC |
| GLOBALDEF |
The AUTOMATIC attribute cannot be applied to minor structures, members of structures, parameters, or descriptions in an ENTRY or RETURNS attribute.
For a discussion of PL/I storage allocation, see Chapter 5, Storage Classes.
2.2.5. BASED Attribute
The BASED attribute defines a based variable, that is, a variable whose actual storage will be denoted by a pointer or offset reference. The format of the BASED attribute is:
BASED [ (reference) ]referenceA reference to a pointer or offset variable or pointer-valued function. If the reference is to an offset variable, that variable must be declared with a base area. Each time a reference is made to a based variable without an explicit pointer or offset qualifier, the reference is evaluated to obtain the pointer or offset value.
Restriction
The following attributes conflict with the BASED attribute:
| AUTOMATIC | GLOBALREF |
| CONTROLLED | PARAMETER |
| DEFINED | READONLY |
| EXTERNAL | STATIC |
| GLOBALDEF | VALUE |
The BASED attribute cannot be applied to minor structures, members of structures, parameters, or descriptions in an ENTRY or RETURNS attribute.
See Section 5.5, “Based Variables” for more information on the BASED variable.
2.2.6. BINARY Attribute
The BINARY attribute specifies that an arithmetic variable has a binary base. The format of the BINARY attribute is:
{ BINARY }
{ BIN }When you specify the BINARY attribute for an identifier, you can also specify one of the following attributes to define the scale and precision of the data:
FIXED [(precision[,scale])] FLOAT [(precision)]
FIXED indicates a fixed-point binary value and FLOAT indicates a floating-point binary value.
For a fixed-point binary value, the precision specifies the number of bits representing an integer and must be in the range 1 through 31. For a fixed-point binary value, the scale factor represents the number of bits to the right of the binary point and must be in the range -31 through 31. The magnitude of the scale factor must be less than or equal to the specified precision.
For a floating-point value, the precision specifies the number of bits representing the mantissa of a floating-point number and must be in the range:
For OpenVMS VAX systems: 1 through 113
For OpenVMS Alpha systems: 1 through 53
For OpenVMS I64 systems: 1 through 53
For OpenVMS x86-64 systems: 1 through 53
The maximum floating-point binary precision is always 53 and 113 for OpenVMS VAX. The default values applied to the BINARY attribute are:
| Attributes Specified | Defaults Supplied |
|---|---|
| BINARY | FIXED (31,0) |
| BINARY FIXED | (31,0) |
| BINARY FLOAT | (24) |
Restrictions
The BINARY attribute directly conflicts with any other data-type attribute.
2.2.7. BIT Attribute
The BIT attribute identifies a variable as a bit-string variable. The format of the BIT attribute is:
BIT[(length)]lengthThe number of bits in the variable. If you do not specify a length, the default length is 1 bit. The length must be in the range 0 through 32,767.
The rules for specifying the length are:
If the attribute is specified for a static variable declaration or in a returns descriptor, length must be a restricted integer expression. A restricted integer expression is one that yields only integral results and has only integral operands. Such an expression can use only the addition (+), subtraction (-), and multiplication (*) operators.
If the attribute is specified in the declaration of a parameter or in a parameter descriptor, you can specify length as a restricted integer expression or as an asterisk (*).
If the attribute is specified for an automatic, based, controlled, or defined variable, you can specify length as an expression. In the case of automatic or defined variables, the expression must not contain any variables or functions that are declared in the same block except for parameters.
If specified, the length in parentheses must follow the keyword BIT.
If you give a variable the BIT attribute, you can also specify the ALIGNED attribute to request alignment of the variable on a byte boundary in storage.
Restriction
The BIT attribute directly conflicts with any other data-type attribute.
2.2.8. BUILTIN Attribute
The BUILTIN attribute indicates that the name declared is the name of a PL/I built-in function. Within the block in which the name is declared, all references to the name will be interpreted as references to the built-in function or pseudovariable of that name. The format of the BUILTIN attribute is:
BUILTIN
Use the BUILTIN attribute when you want to refer to a built-in function within a block in which the function's name has been used to declare a variable.
You also use the BUILTIN attribute when you want to invoke a built-in function that takes no arguments (such as the DATE function) and you do not want to include a null argument list.
Restriction
When you specify the BUILTIN attribute, you cannot specify any other attributes.
Examples
OUTER: PROCEDURE; DECLARE MAX FIXED BINARY STATIC INITIAL (10); . . . INNER: PROCEDURE; DECLARE MAX BUILTIN; TEST = MAX(A,B); . . . END INNER; END OUTER;
The keyword MAX is used here as a variable name. In the internal procedure INNER, the MAX built-in function is invoked. Because the scope of the name MAX includes the internal procedure, the function must be redeclared with BUILTIN.
You can also use the BUILTIN attribute to declare PL/I built-in functions that have no arguments, if you want to invoke them without the empty argument list. For example:
DECLARE DATE BUILTIN; PUT LIST(DATE);
Without the declaration, the PUT LIST statement would have to include an empty argument list for DATE:
PUT LIST(DATE());
2.2.9. CHARACTER Attribute
The CHARACTER attribute identifies a variable as a character-string variable. The format of the CHARACTER attribute is:
{ CHARACTER }
{ CHAR }
[(length)]lengthThe number of characters in a fixed-length string or the maximum length of a varying-length string. If not specified, a length of 1 is assumed. The length must be in the range 0 through 32,767 characters.
The rules for specifying the length are:
If the attribute is specified for a static variable declaration or in a returns descriptor, length must be a restricted integer expression.
If the attribute is specified in the declaration of a parameter or in a parameter descriptor, you can specify length as a restricted integer expression or as an asterisk (*).
If the attribute is specified for an automatic, based, or defined variable, you can specify length as an expression. In the case of automatic or defined variables, the expression must not contain any variables or functions that are declared in the same block except for parameters.
If specified, the length must immediately follow the keyword CHARACTER, and it must be enclosed in parentheses.
If you give a variable the CHARACTER attribute, you can also specify the attribute VARYING, NONVARYING, ALIGNED, or UNALIGNED.
2.2.10. CONDITION Attribute
You can optionally use the CONDITION attribute in a declaration to specify that the variable name is a condition name. You can specify INTERNAL or EXTERNAL scope attributes with the CONDITION attribute. The default scope is external. The format of the CONDITION attribute is:
{ CONDITION } (condition-name)
{ COND }condition-nameName used for ON units to handle programmer-defined conditions.
2.2.11. CONTROLLED Attribute
The CONTROLLED attribute causes a variable's actual storage to be allocated and freed dynamically in generations, only the most recent of which is accessible to the program. The format of the CONTROLLED attribute is:
{ CONTROLLED }
{ CTL }Restrictions
The following attributes conflict with the CONTROLLED attribute:
AUTOMATIC
BASED
DEFINED
GLOBALDEF
GLOBALREF
READONLY
STATIC
VALUE
PARAMETER
The CONTROLLED attribute cannot be applied to minor structures, members of structures, parameters, or descriptions in an ENTRY or RETURNS attribute.
See Section 5.6, “Controlled Variables” for more information on the CONTROLLED variable.
2.2.12. DECIMAL Attribute
The DECIMAL attribute specifies that an arithmetic variable has a decimal base. The format of the DECIMAL attribute is:
{ DECIMAL }
{ DEC }When you specify the DECIMAL attribute for a variable, you can also specify the following attributes to define the scale factor and precision of the data:
FIXED (precision[,scale-factor]) FLOAT (precision)
FIXED indicates a fixed-point value, and FLOAT indicates a floating-point decimal value.
- (
precision[,scale-factor]) The precision of a fixed-point decimal value is the total number of integral and fractional digits. The precision of a floating-point decimal value is the total number of digits in the mantissa. The precision for a fixed-point decimal value must be in the range 1 through 31; the scale factor, if specified, must be greater than or equal to 0 and less than or equal to the specified precision.
The precision for a floating-point decimal value must be in the range:
For OpenVMS VAX systems: 1 through 34
For OpenVMS Alpha systems: 1 through 15
For OpenVMS I64 systems: 1 through 15
For OpenVMS x86-64 systems: 1 through 15
The default values applied to the DECIMAL attribute are:
| Attributes Specified | Defaults Supplied |
|---|---|
| DECIMAL | FIXED (10,0) |
| DECIMAL FIXED | (10,0) |
| DECIMAL FIXED (n) | (n,0) |
| DECIMAL FLOAT | (7) |
Restrictions
The DECIMAL attribute conflicts with any other data-type attribute.
2.2.13. DEFINED Attribute
The DEFINED attribute indicates that PL/I is not to allocate storage for the variable, but is to map the description of the variable onto the storage of another base variable. The DEFINED attribute provides a way to access the same data using different names. The format of the DEFINED attribute is:
{ DEFINED }(variable-reference)
{ DEF }variable-referenceA reference to a variable that has storage associated with it. The variable must not have the BASED, CONTROLLED, or DEFINED attribute. The variable and the declared variable must satisfy the rules given for defined variables in Section 5.8, “Defined Variables”.
The DEFINED attribute can optionally specify a position within the referenced variable at which the definition begins. For example:
DECLARE ZONE CHARACTER(10) DEFINED(ZIP) POSITION(4);
Restrictions
The following attributes conflict with the DEFINED attribute:
| AUTOMATIC | BASED | CONTROLLED |
| EXTERNAL | GLOBALDEF | GLOBALREF |
| INITIAL | PARAMETER | READONLY |
| STATIC | UNION | VALUE |
The DEFINED attribute cannot be applied to minor structures, members of structures, parameters, or descriptions in an ENTRY or RETURNS attribute.
See Section 5.8, “Defined Variables” for more information on defined variables.
2.2.14. DESCRIPTOR Attribute
The DESCRIPTOR attribute forces a parameter to be passed by descriptor to a non-PL/I procedure.
The format of the DESCRIPTOR attribute is:
{ DESCRIPTOR }
{ DESC }Restriction
You can use the DESCRIPTOR attribute only in parameter descriptors
See Section 7.5.1, “Rules for Specifying Parameters” for more information on rules for specifying parameters.
2.2.15. DIMENSION Attribute
The DIMENSION attribute defines a variable as an array. It specifies the number of dimensions of the array and the bounds of each dimension. The format of the DIMENSION attribute is:
[ DIMENSION ]
[ DIM ]
(bound-pair,...)bound-pairOne or two expressions that indicate the number of elements in a single dimension of the array. You must specify the list of bound pairs immediately following the name of the identifier in the array declaration if the optional keyword DIMENSION or DIM is omitted; otherwise, you must specify the list of bound pairs immediately following the keyword DIMENSION or DIM. See the following examples.
The maximum number of dimensions allowed is eight.
A bound pair can be specified:
[lowerbound:]upperbound
This format of a bound pair specifies the minimum and maximum subscripts that can be used for the dimension. The number of elements is:
(upperbound - lowerbound) + 1
If the lower bound is omitted, it is assumed to be 1.
*
This format of a bound pair, when used to define a parameter for a procedure or function, indicates that the bounds are to be determined from the associated argument. If one bound pair is specified as an asterisk, all bound pairs must be specified as asterisks.
The following two declarations are exactly equivalent:
DECLARE A(10) FIXED BIN; DECLARE A FIXED BIN DIMENSION(10);
The following two declarations are also equivalent:
DECLARE B(1:5,1:5) FLOAT DEC; DECLARE B DIM(1:5,1:5) FLOAT DEC;
2.2.16. DIRECT Attribute
The DIRECT file description attribute indicates that a file will be accessed only in a nonsequential manner, that is, by key or by relative record number.
The format of the DIRECT attribute is:
DIRECT
The DIRECT attribute implies the RECORD and KEYED attributes.
Specify the DIRECT attribute on a DECLARE statement for a file constant or on an OPEN statement to access the file. A file declared with the DIRECT attribute must be one of the following:
A relative file
An indexed sequential file
A sequential disk file with fixed-length records
A sequential file opened with ENVIRONMENT(BLOCK_ID)
To access a file both randomly and sequentially, use the SEQUENTIAL attribute instead of DIRECT.
Restriction
The DIRECT attribute conflicts with the SEQUENTIAL, STREAM, and PRINT attributes.
2.2.17. ENTRY Attribute
The ENTRY attribute declares a constant or variable whose value is an entry point and describes the attributes of the parameters (if any) that are declared for the entry point. The format of the ENTRY attribute is:
ENTRY [ (parameter-descriptor, ...) ] [ OPTIONS (VARIABLE) ] [ RETURNS (returns-descriptor) ]
parameter-descriptorA set of attributes describing a parameter of the entry. Attributes describing a single parameter must be separated by spaces; sets of attributes (each set describing a different parameter) must be separated by commas. Parameter descriptors are not allowed if the ENTRY attribute is within a RETURNS descriptor.
The following rules apply to the specification of a parameter descriptor for an array or structure:
If the parameter is a structure, the level number must precede the attributes for each member.
You must specify extents for a parameter using only integer constants, restricted integer expressions, or asterisks (×).
You cannot specify
storage-classattributes.
- OPTIONS (VARIABLE)
An option indicating that you can invoke the specified external procedure with a variable number of arguments. At least one parameter descriptor must be specified following the ENTRY keyword if OPTIONS(VARIABLE) is specified.
This option is provided for use in calling non-PL/I procedures. For complete details on using OPTIONS (VARIABLE), see the Endless PL/I for OpenVMS User Manual.
- RETURNS (
returns-descriptor) For an entry that is invoked as a function reference, an option giving the data type attributes of the function value returned. For entry points that are invoked by function references, the RETURNS attribute is required; for procedures that are invoked by CALL statements, the RETURNS attribute is invalid.
The ENTRY attribute without the VARIABLE attribute implies the EXTERNAL attribute (and implies that the declared item is a constant), unless the ENTRY attribute is used to declare a parameter.
You must declare all external entry constants with the ENTRY attribute.
Restrictions
You cannot declare internal entry constants with the ENTRY attribute in the procedure to which they are internal. Internal entry constants are declared implicitly by the labels on the PROCEDURE or ENTRY statements of an internal procedure.
The ENTRY attribute conflicts with all other data-type attributes.
Example
DECLARE COPYSTRING ENTRY (CHARACTER (40) VARYING, FIXED BINARY(7)) RETURNS (CHARACTER(*));
This declaration describes the external entry COPYSTRING. This entry has two parameters: a varying-length character string with a maximum length of 40 and a fixed-point binary value. The RETURNS attribute indicates that COPYSTRING is invoked as a function and that it returns a character string of any length.
2.2.18. ENVIRONMENT Attribute
The ENVIRONMENT file description attribute is used in DECLARE, OPEN, and CLOSE statements to specify options that define file characteristics specific to the OpenVMS file system and options that request special processing not available in the standard PL/I language. The format of the ENVIRONMENT attribute is:
{ ENVIRONMENT }(option,...)
{ ENV }option,...One or more keyword options separated by commas.
Summary of Options
The following items with asterisks (*) are options you can specify in a CLOSE statement.
| APPEND | |
BACKUP_DATE(variable-reference) | |
| BATCH* | |
| BLOCK_BOUNDARY_FORMAT | |
| BLOCK_IO | |
| BLOCK_SIZE(expression) | |
| BUCKET_SIZE(expression) | |
| CARRIAGE_RETURN_FORMAT | |
| CONTIGUOUS | |
| CONTIGUOUS_BEST_TRY | |
CREATION_DATE(variable-reference) | |
| CURRENT_POSITION | |
DEFAULT_FILE_NAME(character-expression) | |
| DEFERRED_WRITE | |
| DELETE* | |
EXPIRATION_DATE(variable-reference) | |
| EXTENSION_SIZE(expression) | |
FILE_ID(variable-reference) | |
FILE_ID_TO(variable-reference) | |
| FILE_SIZE(expression) | |
| FIXED_CONTROL_SIZE(expression) | |
FIXED_CONTROL_SIZE_TO(variable-reference) | |
| FIXED_LENGTH_RECORDS | |
GROUP_PROTECTION(character-expression) | |
| IGNORE_LINE_MARKS | |
| INDEX_NUMBER | |
| INITIAL_FILL | |
| MAXIMUM_RECORD_NUMBER(expression) | |
| MAXIMUM_RECORD_SIZE(expression) | |
| MULTIBLOCK_COUNT(expression) | |
| MULTIBUFFER_COUNT(expression) | |
| NO_SHARE | |
| OWNER_GROUP(expression) | |
| OWNER_ID(expression) | |
| OWNER_MEMBER(expression) | |
OWNER_PROTECTION(character-expression) | |
| PRINTER_FORMAT | |
| READ_AHEAD | |
| READ_CHECK | |
| RECORD_ID_ACCESS | |
| RETRIEVAL_POINTERS(expression) | |
REVISION_DATE(variable-reference)* | |
| REWIND_ON_CLOSE* | |
| REWIND_ON_OPEN | |
| SCALARVARYING | |
| SHARED_READ | |
| SHARED_WRITE | |
| SPOOL* | |
| SUPERSEDE | |
SYSTEM_PROTECTION(character-expression) | |
| TEMPORARY | |
| TRUNCATE | |
USER_OPEN(entry-name) | |
WORLD_PROTECTION(character-expression) | |
| WRITE_BEHIND | |
| WRITE_CHECK |
The previous list of options to the ENVIRONMENT attribute are described in detail in the Endless PL/I for OpenVMS User Manual.
You can specify all ENVIRONMENT options in OPEN statements. You can also specify all ENVIRONMENT options except those that require variable references in DECLARE statements. Certain disposition options (noted in the list) can be specified in CLOSE statements.
Some ENVIRONMENT options require you to specify a value. In a DECLARE statement, you must use a literal constant to supply the value required. In OPEN and CLOSE statements, however, you can use expressions (including but not limited to literal constants) to supply the values.
Any option that does not require a value can optionally be specified with a Boolean expression that indicates whether the option is to be enabled (if true) or disabled (if false). For example:
DECLARE IFDELETE BIT(1); ⋮ OPEN FILE (XYZ) ENVIRONMENT(DELETE(IFDELETE));
This DELETE option specifies a Boolean variable whose value can be true or false at run time. Boolean values must be specified as constants in DECLARE statements. You can specify Boolean values as expressions (including constants) in OPEN statements and CLOSE statements.
2.2.19. EXTERNAL Attribute
The EXTERNAL attribute declares an external name, that is, a name whose value can be known to blocks outside the block in which it is declared. The format of the EXTERNAL attribute is:
{ EXTERNAL }
{ EXT }The EXTERNAL attribute is implied by the FILE, GLOBALDEF, and GLOBALREF attributes. EXTERNAL is also implied by declarations of entry constants (declarations that contain the ENTRY attribute but not the VARIABLE attribute). For variables, the EXTERNAL attribute implies the STATIC attribute.
Restrictions
The EXTERNAL attribute directly conflicts with the AUTOMATIC, BASED, and DEFINED attributes.
The EXTERNAL attribute cannot be applied to minor structures, members of structures, parameters, or descriptions in an ENTRY or RETURNS attribute.
The EXTERNAL attribute is invalid for variables that are the parameters of a procedure.
If a variable is declared as EXTERNAL STATIC INITIAL:
All blocks that declare the variable must initialize the variable with the same value.
2.2.20. FILE Attribute
The FILE attribute declares a file constant or file variable. The format of the FILE attribute is:
FILE
The FILE attribute is implied by any of the following file description attributes:
| DIRECT | OUTPUT | SEQUENTIAL |
| ENVIRONMENT | STREAM | |
| INPUT | RECORD | UPDATE |
| KEYED |
See Table 9.2, “Summary of File Description Attributes” for definitions of these file description attributes.
If the VARIABLE attribute is not specified, the FILE attribute declares a file constant. If the INTERNAL attribute is not specified, the file has the EXTERNAL attribute by default. All external declarations of a file constant are associated with the same file.
Restrictions
The FILE attribute conflicts with all other data-type attributes. If the FILE attribute is used to declare a variable
or parameter, no file description attributes may be specified. If the VARIABLE attribute is not specified, no
storage-class attributes are allowed.
2.2.21. FIXED Attribute
The FIXED attribute indicates that the variable so declared is arithmetic with a fixed number of fractional digits. Such variables are called fixed-point (as opposed to floating-point) variables because the decimal point and binary point are fixed relative to the representation of the value. The format of the FIXED attribute is:
FIXED [(precision[,scale-factor])]
precisionThe precision is the number of decimal or binary digits used to represent values of the variable.
scale-factorScale factor indicates how much of the precision is to be used for fractional digits.
When you specify the FIXED attribute in a DECLARE statement, you can specify either the BINARY or the DECIMAL attribute to indicate a binary or decimal fixed-point variable. For example, the attributes FIXED BINARY(31,5) define a variable that takes fixed-point binary values of up to a maximum of 31 bits, 5 of which are fractional. The attributes FIXED DECIMAL(10,2) define a variable that takes fixed-point decimal values of up to 10 decimal digits, 2 of which are fractional. PL/I supplies default attributes for attributes that you do not specify (as shown in the following table).
You normally use fixed-point binary data to represent integers. The precision of a fixed-point binary variable must be in the range 1 through 31. The scale factor can be in the range -31 through 31.
You can also use fixed-point decimal data, which can represent larger absolute values. You use fixed-point data whenever arithmetic values must be precise to a specified number of fractional digits. For a fixed-point decimal value, the precision must be in the range 1 through 31 (decimal digits). The scale factor, if specified, must be greater than or equal to zero and less than or equal to the specified precision.
If the scale factor is omitted, zero is used (that is, an integer variable is declared).
The default values given for unspecified related attributes are:
| Attributes Specified | Defaults Supplied |
|---|---|
| FIXED | BINARY (31,0) |
| FIXED BINARY | (31,0) |
| FIXED DECIMAL | (10,0) |
Restriction
The FIXED attribute directly conflicts with all data-type attributes except BINARY and DECIMAL.
2.2.22. FLOAT Attribute
The FLOAT attribute indicates that a variable is a floating-point arithmetic item. The format of the FLOAT attribute is:
FLOAT [(precision)]precisionYou can specify the precision within the following ranges:
For OpenVMS VAX systems: the range for a floating-point binary variable is 1 through 113. The range for a floating-point decimal variable is 1 through 34.
For OpenVMS Alpha, I64 and x86-64 systems: the range for a floating-point binary variable is 1 through 53. The range for a floating-point decimal variable is 1 through 15.
When you specify the FLOAT attribute in a DECLARE statement, you can specify either the BINARY or the DECIMAL attribute. The default values given for unspecified related attributes are:
| Attributes Specified | Defaults Supplied |
|---|---|
| FLOAT | BINARY (24) |
| FLOAT BINARY | (24) |
| FLOAT DECIMAL | (7) |
Restriction
The FLOAT attribute directly conflicts with all data-type attributes except BINARY and DECIMAL.
2.2.23. GLOBALDEF Attribute
The GLOBALDEF attribute declares an external variable or an external file constant. It can optionally control the program section in which the data is allocated. The format of the GLOBALDEF attribute is:
GLOBALDEF [ (psect-name) ]psect-nameThe name of a program section. A program section name can have up to 31 characters, which can consist of the alphanumeric characters, dollar signs ($), and underscores (_). The first character cannot be numeric (0 through 9). PL/I converts all lowercase letters to uppercase when it compiles a source program. The names abc, ABC, Abc, and so on all refer to the same program section.
If you do not specify a program section name, PL/I places the definition for the name in the default program section associated with the variable.
The GLOBALDEF attribute implies the EXTERNAL attribute. The GLOBALDEF attribute also implies STATIC except when used for file constants.
Restrictions
The GLOBALDEF attribute conflicts with the GLOBALREF and INTERNAL attributes. GLOBALDEF cannot be used with ENTRY constants.
Only one procedure in a program can declare a particular external variable with the GLOBALDEF attribute.
For complete details on using the GLOBALDEF attribute to declare global external symbols, see Section 5.4, “External Variables”.
2.2.24. GLOBALREF Attribute
The GLOBALREF attribute indicates that the declared name is a global symbol defined in an external procedure. The format of the GLOBALREF attribute is:
GLOBALREF
The GLOBALREF attribute implies the EXTERNAL attribute. The corresponding name must be declared in another procedure with the GLOBALDEF attribute or, if the external procedure is written in another programming language, with its equivalent in that language.
Restriction
The GLOBALREF attribute conflicts with the INITIAL, GLOBALDEF, and INTERNAL attributes. If GLOBALREF is specified with the FILE attribute, you cannot specify any other file description attributes.
See Section 5.4, “External Variables” for information about using this attribute.
2.2.25. INITIAL Attribute
The INITIAL attribute provides an initial value for a declared variable. The format of the INITIAL attribute is:
{ INITIAL } { (initial-element[,initial-element...]) }
{ INIT } { ((*) valid-expression) }initial-elementA construct that supplies a value for the initialized variable. The value must be valid for assignment to the initialized variable. If the initialized variable is an array, a list of initial elements separated by commas is used to initialize individual elements. The number of initial elements must be 1 for a scalar variable and must not exceed the number of elements of an array variable. Each initial element must have one of the following forms:
string-constant
(replication-factor) string-constant
(
iteration-factor) (string-constant)(
iteration-factor) ((replication-factor) string-constant)[(
iteration-factor)] arithmetic-constant[(
iteration-factor)] scalar-reference[(
iteration-factor)] (scalar-expression)[(
iteration-factor)] ×
The iteration factors are nonnegative integer-valued expressions that specify the number of successive array elements to be initialized with the following value.
An asterisk (×) following the iteration factor specifies that the corresponding array elements are to be skipped during the initialization.
You can use a replication factor in combination with an iteration factor in initializing a string constant. For example, the following two statements are equivalent:
INITIAL ((10)('ABCABC')) INITIAL ((10)((2)'ABC'))
The first statement uses an iteration factor exclusively; the second statement combines an iteration factor of 10 with a replication factor of 2.
A string constant must be parenthesized if it is used with an iteration factor, because this set of parentheses prevents the iteration factor from being interpreted as a string replication factor.
INITIAL ((10)'ABC')
For example, the initial value is interpreted as a string replication factor, not an iteration factor, and cannot be used to initialize a whole array.
- (*)
valid-expression A construct that initializes all elements of an array to the same value by means of the asterisk iteration factor. The expression must evaluate to a value that is valid for assignment to the initialized array. If the expression is a string constant, it must be parenthesized so that the asterisk iteration factor is not interpreted as a string replication factor. The possible expressions are:
(string-constant)
((replication-factor) string-constant)
arithmetic-constant
scalar-reference
(scalar-expression)
*
An asterisk following the asterisk iteration factor results in no initializations being performed.
Examples
The following are examples of declarations that include the INITIAL attribute:
DECLARE RATE FIXED DECIMAL (2,2) STATIC INITIAL (.04); DECLARE SWITCH BINARY STATIC INITIAL ('1'B); DECLARE BELL_CHAR BINARY STATIC INITIAL ('07'B4); DECLARE OUTPUT_MESSAGE CHARACTER(20) STATIC INITIAL ('GOOD MORNING'); DECLARE (A INITIAL ('A'), B INITIAL ('B'), C INITIAL ('C')) STATIC CHARACTER; DECLARE QUEUE_END POINTER STATIC INITIAL(NULL()); DECLARE X(10,5) FIXED BIN(31) INITIAL ((*) -2); /* Initializes all 50 elements to -2 */ DECLARE 1 A(10), 2 B(10), 3 C(10) FIXED BIN(31) INITIAL ((*) 4); /* Initializes all 1000 elements to 4 */ DECLARE A(10) FIXED INIT ((5) 1,(5) 2); /* Initializes the first 5 elements to 1 and the second 5 elements to 2 */
The following declaration is not valid, because the asterisk iteration factor cannot be used to initialize part of an array; it can only be used to initialize all elements of the array to the same value:
DECLARE A(10) FIXED INIT ((5) 1,(*)2); /* Invalid use of asterisk iteration factor */
Restrictions
You cannot specify the INITIAL attribute for a structure variable. You must individually initialize the members of the structure.
You cannot specify the INITIAL attribute for a variable or member of a structure that has any of the following attributes:
DEFINED
ENTRY
FILE
LABEL
PARAMETER
UNION
If the initialized variable is STATIC, only constants, restricted expressions, and references to the NULL or EMPTY built-in functions are allowed. You can use these initial values with a constant iteration factor.
Variables and functions (except for parameters) occurring in an initial element (for automatic variables) must not be declared in the same block as the variable being initialized.
2.2.26. INPUT Attribute
The INPUT file description attribute indicates that the associated file is to be an input file. The format of the INPUT attribute is:
INPUT
Specify the INPUT attribute on a DECLARE statement for a file constant or on an OPEN statement to access the file for reading.
You can specify the INPUT attribute with either the STREAM or the RECORD attribute. For a stream file, INPUT indicates that the file will be accessed with GET statements. For a record file, INPUT indicates that the file will be accessed only with READ statements.
For example:
DECLARE INFILE RECORD INPUT; OPEN FILE(INFILE); READ FILE(INFILE) INTO(RECORD_BUFFER);
These statements declare, open, and access the first record in the input file INFILE.
For a description of the attributes that can be applied to files, see Table 9.2, “Summary of File Description Attributes”.
The INPUT attribute can be supplied by default for a file, depending on the context of its opening. See Section 9.1.3.3, “Establishing the File's Attributes” for more information.
Restriction
The INPUT attribute conflicts with the OUTPUT, UPDATE, and PRINT attributes and with any data-type attribute other than FILE.
2.2.27. INTERNAL Attribute
The INTERNAL attribute limits the scope of an identifier to the block in which the identifier is declared and its dynamic descendents.
The format of the INTERNAL attribute is:
{ INTERNAL }
{ INT }You only need to use the INTERNAL attribute to explicitly declare the scope of a file constant as internal. File constants, by default, have the EXTERNAL attribute.
Restriction
The INTERNAL attribute directly conflicts with the EXTERNAL, GLOBALDEF, and GLOBALREF attributes.
2.2.28. KEYED Attribute
The KEYED file description attribute indicates that you can randomly access records in the specified file. The KEYED attribute implies the RECORD attribute.
Specify KEYED in a DECLARE statement to identify a file or in an OPEN statement to open the file. For a description of the attributes that can be applied to files, see Table 9.2, “Summary of File Description Attributes”.
Restriction
The KEYED attribute conflicts with the STREAM attribute and with any data-type attributes other than FILE.
2.2.29. LABEL Attribute
The LABEL attribute declares a label variable; it indicates that values given to the variable will be statement labels. The format of the LABEL attribute is:
LABEL
Restriction
You cannot specify the LABEL attribute with any other data-type attribute, the INITIAL attribute, or any file description attributes.
2.2.30. LIKE Attribute
The LIKE attribute copies the member declarations contained within a major or minor structure declaration into the structure variable to which it is applied. The format of the LIKE attribute is:
level-numberidentifier[attributes] LIKEreference
level-numberThe level number to which the declarations in the reference are copied.
identifierThe variable to which the declarations in the reference are to be copied. The identifier must be preceded by a level number.
attributesStorage class or dimensions appropriate for the level number. You can specify a storage class and dimensions with a major structure, or you can specify dimensions with a minor structure.
referenceThe name of a major or minor structure that is known in the current block.
The LIKE attribute causes the structuring and member declarations of its reference to be copied, but not the name, storage class, or dimensioning (if any) of the reference. The exception to this rule is that the UNION attribute is propagated in a LIKE declaration. While logical structuring is copied, the level numbers themselves are not copied.
You can use the LIKE attribute on a structure already containing the LIKE attribute.
2.2.31. LIST Attribute
The LIST attribute is used in the declaration of a formal parameter to indicate that the parameter can accept a list of actual parameters of arbitrary length. This list must contain at least one argument. To allow a list of zero or more arguments, you must declare the formal parameter with both the TRUNCATE attribute and the LIST attribute. The format of the LIST attribute is:
LIST
The LIST attribute is valid only on formal parameters of external procedures. It is not supported for PL/I procedures. (To simulate list parameters in PL/I, use asterisk-extent arrays.)
You can only use the LIST attribute for the last formal parameter in an argument list.
Examples
DCL NUMBER FIXED BINARY; DCL LIST_PROC1 ENTRY (FIXED BINARY,FIXED BINARY LIST); DCL LIST_PROC2 ENTRY (FIXED BINARY,FIXED BINARY LIST TRUNCATE); CALL LIST_PROC1 (NUMBER,NUMBER); CALL LIST_PROC1 (NUMBER,NUMBER,NUMBER); CALL LIST_PROC2 (NUMBER); CALL LIST_PROC2 (NUMBER,NUMBER,NUMBER,NUMBER);
2.2.32. MEMBER Attribute
You can optionally specify the MEMBER attribute in the declaration of a structure member (minor structure). A structure member has the MEMBER attribute implicitly. The format of the MEMBER attribute is:
MEMBER
2.2.33. NONVARYING Attribute
The NONVARYING attribute keyword explicitly states that a bit-string or character-string variable has a fixed length, not a varying length. Because NONVARYING is the default for bit and character strings, it need not be specified. The format of the NONVARYING attribute is:
{ NONVARYING }
{ NONVAR }2.2.34. OFFSET Attribute
The OFFSET attribute declares a variable that will be used to reference a based variable within an area. The format of the OFFSET attribute is:
OFFSET [(area-reference)]area-referenceThe name of a variable with the AREA attribute. The value of the offset variable will be interpreted as an offset within the specified area.
Examples
DECLARE MAP_SPACE AREA (40960), MAP_START OFFSET (MAP_SPACE), MAP_LIST(100) CHARACTER(80) BASED (MAP_START);
These declarations define an area named MAP_SPACE, an offset variable that will contain offset values within that area, and a based variable whose storage is located by the value of the offset variable MAP_START.
Restriction
The area reference must be omitted if the OFFSET attribute is specified within a returns descriptor, parameter declaration, or a parameter descriptor. The OFFSET attribute conflicts with all other data-type attributes.
2.2.35. OPTIONAL Attribute
The OPTIONAL attribute indicates that an actual parameter need not be specified in a call. If the actual parameter is not specified, a placeholder for it must be specified, and PL/I will pass a longword zero as the actual parameter in that position. There is an exception if there are no further actual parameters that are being supplied in the call. For that case, the programmer does not need to supply commas, although she may choose to do so to make the program more readable by humans. The format of the OPTIONAL attribute is:
OPTIONAL
Example
DCL E ENTRY (FIXED,FIXED OPTIONAL); CALL E(1,2); CALL E(1,); CALL E(1);
2.2.36. OUTPUT Attribute
The OUTPUT file description attribute indicates that data is to be written to, and not read from, the associated external device or file. The format of the OUTPUT attribute is:
OUTPUT
Specify the OUTPUT attribute on a DECLARE statement for a file constant or on an OPEN statement to access the file for writing. You can specify the OUTPUT attribute with either the STREAM or the RECORD attribute. For a stream file, OUTPUT indicates that the file will be accessed with PUT statements. For a record file, OUTPUT indicates that the file will be accessed with only WRITE statements.
Examples
DECLARE OUTFILE RECORD OUTPUT; OPEN FILE(OUTFILE); WRITE FILE(OUTFILE) FROM(RECORD_BUFFER);
These statements declare, open, and write a record to the output file OUTFILE.
For a description of the attributes that you can apply to files and the effects of combinations of these attributes, see Chapter 9, Input and Output.
Restriction
The OUTPUT attribute conflicts with the INPUT and UPDATE attributes and with any data-type attributes other than FILE. The OUTPUT attribute also conflicts with ENVIRONMENT(INDEXED).
2.2.37. PARAMETER Attribute
A variable occurring in the parameter list of a PROCEDURE or ENTRY statement has the PARAMETER attribute implicitly. You can optionally use the PARAMETER keyword in the declaration of a variable name to state explicitly that it is a parameter. The format of the PARAMETER attribute is:
{ PARAMETER }
{ PARM }Example
The following example uses the PARAMETER keyword:
TEST: PROC( A, B ); DCL A CHAR(*) PARAMETER; DCL B FIXED BIN PARM; . . .
Refer to Section 7.5, “Parameters and Arguments” for a discussion on parameters.
2.2.38. PICTURE Attribute
The PICTURE attribute is used to declare a pictured variable. Pictured variables have fixed-point decimal attributes, but values of the variable are stored internally as character strings. The character string contains decimal digits representing the numeric value of the variable, plus special editing symbols described in the picture. The format of the PICTURE attribute is:
{ PICTURE } 'picture'
{ PIC }pictureA string of picture characters that define the representation of the variable.
See Section 3.2.5.1, “Picture Characters” for detailed information about picture characters, syntax, and examples.
Restriction
The PICTURE attribute conflicts with all other data-type attributes.
2.2.39. POINTER Attribute
The POINTER attribute indicates that the associated variable will be used to identify locations of data. The format of the POINTER attribute is:
{ POINTER }
{ PTR }Restriction
The POINTER attribute conflicts with all other data-type attributes.
2.2.40. POSITION Attribute
The POSITION attribute specifies the character or bit position in a defined variable's base at which the defined variable begins. The format of the POSITION attribute is:
{ POSITION }(expression)
{ POS }expressionAn integer expression that specifies a position in the base. A value of 1 indicates the first character or bit.
Restriction
You can specify the POSITION attribute only in connection with DEFINED and only when the defined variable satisfies the rules for string overlay defining (see Section 5.8.2, “Rules for Overlay Defining”).
2.2.41. PRECISION Attribute
The PRECISION attribute specifies the maximum number of decimal or binary digits in a number. You can specify the precision of an arithmetic variable in any of the following formats, depending on the numeric base of the data item. The formats of the PRECISION attribute are:
BINARY [ FIXED ] [ [PRECISION] (precision[,
scale-factor]) ][BINARY] FLOAT [ [PRECISION] (precision) ]
DECIMAL [ FIXED ] [ [PRECISION] (precision[,
scale-factor]) ]DECIMAL FLOAT [ [PRECISION] (precision) ]
precisionYou can abbreviate the keyword PRECISION to PREC, or you can omit it entirely. If you use the keyword, the precision (and scale factor, if used) must immediately follow the keyword, which can be placed before or after any other attributes in the declaration. If you omit the keyword, the precision (and scale factor, if used) must follow the other attributes. For example, the following declarations are equivalent:
DCL A FIXED BIN(31); DCL A FIXED BIN PRECISION(31); DCL B FLOAT BIN(53); DCL B PREC(53) FLOAT BIN; DCL C FIXED DEC(5,2); DCL C FIXED DEC PREC(5,2);
The precision of a floating-point data item is the number of decimal or binary digits in the mantissa of the floating-point representation.
scale-factorThe scale factor is the number of digits to the right of the decimal or binary point in fixed-point decimal or binary data. If no scale factor is specified with fixed-point data, the default is zero.
The ranges of values you can specify for the precision of each arithmetic data-type, and the defaults applied if you do not specify a precision, are summarized Section 3.2.1, “Precision and Scale of Arithmetic Data Types”.
2.2.42. PRINT Attribute
The PRINT attribute is used to declare a print file. The file SYSPRINT, used as the default output by PUT statements, is a print file. The format of the PRINT attribute is:
Print files are stream output files with special formatting characteristics. The PRINT attribute implies the OUTPUT and STREAM attributes.
Restriction
The PRINT attribute conflicts with the INPUT, RECORD, UPDATE, KEYED, SEQUENTIAL, and DIRECT attributes.
2.2.43. READONLY Attribute
You can apply the READONLY attribute to any static computational variable whose value does not change during program execution. The format for the READONLY attribute is:
READONLY
When you specify READONLY in conjunction with the declaration of a static variable, the PL/I compiler allocates storage for the variable based on the fact that its value does not change. A static variable with the READONLY attribute is given an initial value with the INITIAL attribute.
Restrictions
You can apply the READONLY attribute only to static computational variables. You must declare the variables with the EXTERNAL, STATIC, GLOBALREF, or GLOBALDEF attribute.
The value of a variable with the READONLY attribute cannot be modified. An attempt to modify a variable declared with the READONLY attribute will result in a run-time error.
The READONLY attribute conflicts with the ENTRY, FILE, LABEL, POINTER, and VALUE attributes.
2.2.44. RECORD Attribute
The RECORD file description attribute indicates that data in an input or output file consists of separate records and that the file will be processed by record I/O statements. The format of the RECORD attribute is:
RECORD
The RECORD attribute is implied by the DIRECT, SEQUENTIAL, KEYED, and UPDATE attributes.
You can specify this attribute in a DECLARE statement for a file constant or in the OPEN statement that accesses the file.
Restriction
The RECORD attribute conflicts with the STREAM and PRINT attributes.
2.2.45. REFER Attribute
The REFER attribute defines dynamically self-defining structures. The format of the REFER attribute is:
REFER
See Section 4.2.6.3, “Using the REFER Option” for more information on the REFER option.
2.2.46. REFERENCE Attribute
The REFERENCE attribute forces a parameter to be passed by reference. The format of the REFERENCE attribute is:
{ REFERENCE }
{ REF }By default, most parameters are passed by reference in PL/I. However, the REFERENCE attribute is needed for passing an asterisk-extent array or character string by reference, because asterisk-extent parameters are passed by descriptor by default.
Example
DECLARE E ENTRY((*) FIXED BIN(31) REFERENCE, FIXED BIN(31));
This is a declaration of a non-PL/I entry point that takes an asterisk-extent parameter by reference. The first parameter of the external procedure is an arbitrarily large array of longwords, and the second parameter is the size of the array. The external procedure should have some method of determining the size of the array being passed.
Restriction
Note that you can only use the REFERENCE attribute in parameter descriptors.
2.2.47. RETURNS Attribute
The RETURNS option must be specified on the PROCEDURE or ENTRY statement if the corresponding entry point is invoked as a function. The RETURNS attribute is specified with the ENTRY attribute to give the data-type of a value returned by an external function. The format of the RETURNS option and attribute is:
RETURNS (returns-descriptor...)returns-descriptorOne or more attributes that describe the value returned by the function to its point of invocation. The returned value becomes the value of the function reference in the invoking procedure. The attributes must be separated by spaces, except for attributes (the precision, for example) that are enclosed in parentheses.
Restrictions
The data types you can specify for a returns descriptor are restricted to scalar elements of either computational or noncomputational types. Areas are not allowed.
You can specify the extent of a character-string value as an asterisk (*) to indicate that the string can have any length. Otherwise, extents must be specified with restricted expressions.
You cannot use the RETURNS option or the RETURNS attribute for procedures that are invoked by the CALL statement.
The attributes specified in a returns descriptor in a RETURNS attribute must correspond to those specified in the RETURNS option of the PROCEDURE statement or ENTRY statements in the corresponding procedure. For example:
CALLER: PROCEDURE OPTIONS (MAIN); DECLARE COMPUTER ENTRY (FIXED BINARY) RETURNS (FIXED BINARY); /* RETURNS attribute */ DECLARE TOTAL FIXED BINARY; . . . TOTAL = COMPUTER (A+B);
The first DECLARE statement declares an entry constant named COMPUTER. COMPUTER will be used in a function reference to invoke an external procedure, and the function reference must supply a fixed-point binary argument. The invoked function returns a fixed-point binary value, which then becomes the value of the function reference.
The function COMPUTER contains the following:
COMPUTER: PROCEDURE (X) RETURNS (FIXED BINARY); /* RETURNS option */ DECLARE (X, VALUE) FIXED BINARY; . . . RETURN (VALUE); /* RETURN statement */
In the PROCEDURE statement, COMPUTER is declared as an external entry constant, and the RETURNS option specifies that the procedure return a fixed-point binary value to the point of invocation. The RETURN statement specifies that the value of the variable VALUE be returned by COMPUTER. If the data-type of the returned value does not match the data-type specified in the RETURNS option, PL/I converts the value to the correct data-type according to the rules given under Section 6.4, “Data Type Conversion of Operands and Expressions”.
2.2.48. SEQUENTIAL Attribute
The SEQUENTIAL file description attribute indicates that records in the file will be accessed in a sequential manner. The format of the SEQUENTIAL attribute is:
{ SEQUENTIAL }
{ SEQL }If you specify SEQUENTIAL, the RECORD attribute is implied.
Specify the SEQUENTIAL attribute in a DECLARE statement for a file constant or in the OPEN statement that accesses the file.
You can apply the SEQUENTIAL attribute to files with sequential, relative, or indexed sequential file organizations.
Restriction
The SEQUENTIAL attribute conflicts with the DIRECT, STREAM, and PRINT attributes.
2.2.49. STATIC Attribute
The STATIC attribute specifies the way that PL/I is to allocate storage for a variable. The format of the STATIC attribute is:
STATIC
The STATIC attribute is implied by the EXTERNAL attribute. For more information on STATIC and on other
storage-class attributes, see Chapter 5, Storage Classes.
Restriction
The STATIC attribute directly conflicts with the BASED, CONTROLLED, DEFINED, and parameter attributes. The STATIC attribute cannot be applied to members of structures, parameters, or descriptions in an ENTRY or RETURNS attribute.
2.2.50. STREAM Attribute
The STREAM file description attribute indicates that the file consists of ASCII characters and that it will be processed using GET and PUT statements. The format of the STREAM attribute is:
STREAM
The STREAM attribute is implied by the PRINT attribute. It is also supplied by default for a file that is implicitly opened with a GET or PUT statement.
Specify the STREAM attribute in a DECLARE statement for a file identifier or in the OPEN statement that opens the file.
Restriction
The STREAM attribute directly conflicts with the RECORD, KEYED, DIRECT, SEQUENTIAL, and UPDATE attributes.
2.2.51. STRUCTURE Attribute
You can optionally specify the STRUCTURE attribute in the declaration of a structure. The format of the STRUCTURE attribute is:
STRUCTURE
2.2.52. TYPE Attribute
The TYPE attribute copies the declarations contained within the type declaration to the variable to which it is applied. The format of the TYPE attribute is:
level-numberidentifier[attributes] TYPEreference
level-numberThe level number to which the declarations in the reference are copied.
identifierThe variable to which the declarations in the reference are to be copied. The identifier must be preceded by a level number.
attributesStorage class or dimensions appropriate for the level number. You can specify a storage class and dimensions with a major structure, or you can specify dimensions with a minor structure.
referenceThe name of a type declaration that is known in the current block.
The TYPE attribute causes the declaration of its reference to be copied, but not the name, storage class, or dimensioning (if any) of the reference. The exception to this rule is that the UNION attribute is propagated in a TYPE declaration. While logical structuring is copied, the level numbers themselves are not copied.
You can use the TYPE attribute on a declaration already containing the TYPE attribute.
Restrictions
A TYPE definition cannot be:
A pointer-qualified variable
A subscripted variable
An entry variable
A variable declaration that leads to direct or indirect circular declarations
Examples of circular declarations that should not be used are:
DECLARE 1 S11, 2 F1 CHARACTER(10), 2 F2 TYPE(S11); /* Direct circular */ DECLARE V1 TYPE(V2); /* Indirect circular */ DECLARE V2 TYPE(V3); DECLARE V3 TYPE(V1); DECLARE A1(10) TYPE(A2); /* Indirect circular */ DECLARE A2(10) TYPE(A3); DECLARE A3(10) TYPE(A1); DECLARE 1 S31, 2 F1 CHARACTER(10), 2 F2 TYPE(S32); /* Indirect circular */ DECLARE 1 S32, 2 F1 CHARACTER(10), 2 F2 TYPE(S33); DECLARE 1 S33, 2 F1 CHARACTER(10), 2 F2 TYPE(S31);
A structure variable with the BASED attribute and declarations with the REFER option if the TYPE variable does not have a BASED attribute. For example:
DECLARE N FIXED BINARY; DECLARE 1 VARIABLE_X BASED, 2 SIZE FIXED BINARY(15), 2 ITEMS (N REFER (VARIABLE_X.SIZE)) CHARACTER(80); DECLARE VARIABLE_Y TYPE (VARIABLE_X); /* Error - VARIABLE_Y not BASED */
2.2.53. TRUNCATE Attribute
The TRUNCATE attribute is used in the declaration of a formal parameter to indicate that the actual parameter list can be truncated at the point where this argument should occur. The format of the TRUNCATE attribute is:
TRUNCATE
When the actual call is made, the actual parameter list can stop at the parameter before the one declared with the TRUNCATE attribute. It is possible to pass an actual parameter in a position with the TRUNCATE attribute. Note that in this case, all remaining parameters must also be specified unless they have the TRUNCATE attribute.
A subtle difference between trailing formal parameters for which the TRUNCATE attribute is specified and trailing formal parameters for which the OPTIONAL attribute is specified is that when no actual parameters are specified, the compiler will automatically fill out the minimum argument vector length requires (such as by certain VMS system services) in the OPTIONAL case, but not if only TRUNCATE is specified.
Example
DCL E ENTRY (FIXED,FIXED TRUNCATE,FIXED); CALL E(1); CALL E(1,2,3);
The following call, however, will be invalid:
CALL E(1,2);
This call is invalid because the second parameter has the TRUNCATE attribute, so the third parameter must be specified.
2.2.54. UNALIGNED Attribute
The UNALIGNED attribute is used in conjunction with the BIT attribute to specify that a bit-string variable should not be aligned on a byte boundary. Because UNALIGNED is the default for bit strings, it need not be specified. The format of the UNALIGNED attribute is:
{ UNALIGNED }
{ UNAL }You can use the UNALIGNED attribute in the declaration of character strings. All character strings are aligned on byte boundaries; therefore, the UNALIGNED attribute has no effect on the actual storage of a character string.
Restriction
The UNALIGNED attribute conflicts with all data-type attributes other than BIT and CHARACTER.
2.2.55. UNION Attribute
The UNION attribute, which can be used only in conjunction with a level number in a structure declaration, signifies that all immediate members of the major or minor structure so designated occupy the same storage. Immediate members are those members having a level number 1 higher than the major or minor structure with the UNION attribute. For example, if the UNION attribute were associated with level n, then all members or minor structures at level n+1 up to the next member at level n would be immediate members and would occupy the same storage. The format for the UNION attribute is:
level-numberidentifier[storage-class] UNION
level-numberThe level number of the variable with which the declarations in the reference share storage.
identifierNames the variable with which the declarations in the reference share storage. A variable declared with the UNION attribute must be a major or minor structure.
storage-classThe storage class specified for the structure. You can specify the storage class only on level 1.
2.2.56. UPDATE Attribute
The UPDATE attribute is a file description attribute indicating that the associated file is to be used for both input and output. You can apply the UPDATE attribute to relative files, indexed files, and sequential disk files with fixed-length records. The format of the UPDATE attribute is:
UPDATE
Specify the UPDATE attribute on a DECLARE statement for a file constant or on an OPEN statement to access the file for update. The UPDATE attribute implies the RECORD attribute.
For a description of the attributes that are applied to files, see Section 9.1.3.3, “Establishing the File's Attributes”.
Restriction
The UPDATE attribute directly conflicts with the INPUT, OUTPUT, STREAM, and PRINT attributes and with any data-type attribute other than FILE.
2.2.57. VALUE Attribute
The VALUE attribute is provided for passing parameters by value rather than by reference, or it can be used to specify a global constant value. The format of the VALUE attribute is:
{ VALUE }
{ VAL }The VALUE attribute serves two purposes:
In a parameter descriptor in an ENTRY declaration, it specifies that the corresponding argument is to be passed using the hardware-specific convention for passing arguments by value. For this usage, VALUE must be specified in conjunction with one of the following attributes:
ANY
FIXED BINARY(m) where m is less than or equal to 31
FLOAT BINARY(n) where n is less than or equal to 24
BIT(o) ALIGNED where o is less than or equal to 32
ENTRY
OFFSET
POINTER
In conjunction with the GLOBALREF or GLOBALDEF attributes, it specifies that a global external variable has a constant value for which no storage is allocated. The compiler can use this value as an immediate value in generating instructions. With the global external variables, the format is:
{ VALUE } { VAL } { GLOBALDEF INITIAL(value) } { GLOBALREF }Note
The compiler will accept a parenthesized program section name following the GLOBALDEF keyword, but that program section name will be ignored.
The VALUE attribute, when specified with the BIT attribute, implies the ALIGNED attribute.
2.2.58. VARIABLE Attribute
The VARIABLE attribute indicates that the associated identifier is a variable. VARIABLE is implied by all computational data-type attributes and by all noncomputational attributes except FILE and ENTRY. The format of the VARIABLE attribute is:
VARIABLE
If you specify the FILE or ENTRY attribute in a DECLARE statement without the VARIABLE attribute, the defined object is assumed to be a file or entry constant.
The VARIABLE attribute is implied by the LABEL attribute. You can declare label constants only by using the label identifier in the program; you cannot define a label constant in a DECLARE statement.
Restriction
The VARIABLE attribute is not valid in a returns descriptor or in a parameter descriptor.
2.2.59. VARYING Attribute
The VARYING attribute indicates that a character-string variable does not have a fixed length, but that its length changes according to its current value. The format of the VARYING attribute is:
{ VARYING }
{ VAR }You must specify a length attribute in conjunction with VARYING by giving the maximum length allowed for the variable. The current length is stored with the value and can be determined at any time with the LENGTH built-in function. If you need to determine the maximum declared length of a varying- length character string, use the MAXLENGTH built-in function.
The value of an uninitialized CHARACTER VARYING variable is undefined.
Special rules apply to reading and writing record files into and from variables that have the VARYING attribute. See the Endless PL/I for OpenVMS User Manual.
Restriction
The VARYING attribute directly conflicts with any data-type attribute other than CHARACTER.
Examples
DECLARE STRING CHARACTER(80) VARYING;
A variable named STRING is declared as a varying-length character string with a maximum length of 80 characters.
S: PROCEDURE OPTIONS(MAIN); DECLARE STRING CHARACTER(80) VARYING; STRING = 'PIE'; PUT LIST (LENGTH(STRING)); PUT LIST (MAXLENGTH(STRING)); PUT LIST (SIZE(STRING)); END;
The value returned by the built-in function LENGTH is 3, the length of the current value of the string. The value returned by the built-in function MAXLENGTH is 80, the maximum declared length. The value returned by the built-in function SIZE is 82, the maximum declared length plus two (for the two bytes that hold the value of the current length).