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 } [level] declaration [,[level] declaration, ...];
{ DCL }levelLevels are integral values that specify the relationship of members of structures. Specify the level first, before the rest of the declaration.
declarationDeclarations consist of identifiers and attributes. A declaration has the following format:
{identifier}[(bound-pair)] [attribute...] { (identifier, ...) }The format of the DECLARE statement varies according to the number and nature of the items being declared. You can declare a single identifier, optionally specifying a level,
bound-pairlist, and other attributes for that identifier. Or you can include, in parentheses, a list of declarations to which the level and all subsequent attributes apply. In this case you can specify simple identifiers or you can include attributes for individual identifiers.Use bound pairs to specify the dimensions of arrays. Bound pairs must be in parentheses and must immediately follow the identifier or the list of declarations.
The following sections describe various formats of the DECLARE statement.
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 1- to 31-character user-supplied name. 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 ($), underscores (_), pound sign (#) and at sign (@), but must begin with an alphabetic letter, dollar sign, underscore, pound sign or at sign.
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;
If you do not give a name specific attributes in a DECLARE statement or you reference an undeclared name, the name has the default attributes FIXED BINARY (31) AUTOMATIC. Note that the compiler issues a warning message whenever it gives default attributes to a name.
You can declare a variable outside any procedure. Any variable so declared is visible to all procedures contained by the
module. The format for declarations outside procedures is the same as for other declarations, however the
storage-class attribute cannot be AUTOMATIC. If you do not specify a
storage-class or you specify it as AUTOMATIC, the compiler issues a warning and supplies 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 example shows 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, place names that share common attributes in parentheses and separate them with commas. The attributes that follow the parenthetical list of names are applied to all the named identifiers.
The following examples show 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 attributes, within the parentheses, attributes that are unique to specific variable names within the parenthetical list. Use 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 a STREAM OUTPUT file.
You can nest parentheses, as shown in the following 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 }
{ * }Specify one bound pair 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 you omit the lower bound, the lower bound for that dimension is 1 by default.
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.
You can use an asterisk (*) as the bound pair when you declare arrays as parameters of a procedure. The asterisk indicates that the parameter can accept array arguments with any number of elements. If you specify one array dimension with an asterisk, you must specify all dimensions of that array with asterisks. See Section 7.5.1, “Rules for Specifying Parameters” for more information and examples.
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 [, level declaration ...];
{ 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] }{ INPUT }
{ STREAM }{ OUTPUT[PRINT] }
{ UPDATE }
{ DIRECT }
{ SEQUENTIAL }Entry Name Attributes
You can apply the following attributes to identifiers of entry points:
ENTRY[VARIABLE] [ OPTIONS [ (VARIABLE) ] ]
[ [ (C) ] ]
[RETURNS(returns-descriptor)]
[BUILTIN]Nondata 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 |
{ [UN]BUFFERED }
{ [UN]BUF } | Specifies whether records of a record file should or should not pass through intermediate storage buffers. (ibm dialect only) |
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 |
{ 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 |
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 | Indicates that a 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 }( | 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 |
PRINT | 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 |
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 or bit 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 ]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 EXT_ROUTINE ENTRY (ANY VALUE);
This statement identifies the procedure EXT_ROUTINE and indicates that the procedure accepts a single argument, of any data type, passed by value.
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. Endless Software Solutions 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 | GLOBALDEF | READONLY |
| CONTROLLED | GLOBALDEF | STATIC |
| DEFINED | PARAMETER | VALUE |
| EXTERNAL |
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.
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)] 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 floating-point value, the precision specifies the number of bits representing the mantissa of a floating-point number and must be in the range 1 through 53
The maximum floating-point binary precision is always 53. The default values applied to the BINARY attribute are listed in Table 2.2, “Default Values for BINARY Attribute”:
| Attributes Specified | dec Dialect | ibm Dialect | ansi Dialect |
|---|---|---|---|
| BINARY | FIXED (31) | FIXED (15) | FIXED (15) |
| BINARY FIXED | (31) | (15) | (15) |
| BINARY FLOAT | (24) | (21) | (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. BUFFERED and UNBUFFERED Attributes (IBM Dialect Only)
The BUFFERED and UNBUFFERED file description attributes specify whether or not each record of a RECORD file must pass through intermediate storage buffers during transmission to auxiliary storage. The format of the BUFFERED attribute is:
{ BUFFERED }
{ BUF }The format of the UNBUFFERED attribute is:
{ UNBUFFERED }
{ UNBUF }If you specify BUFFERED, data transmission is usually overlapped with processing. You must specify BUFFERED in a file description to use the LOCATE statement on that file.
If you specify UNBUFFERED, records in the file do not need to pass through a buffer. They may be transmitted directly to and from the main storage associated with the variable. However, buffers may still be used if the records in the file are variable-length. When you specify UNBUFFERED, data transmission is not overlapped with processing.
You can specify the BUFFERED or UNBUFFERED attribute in a DECLARE statement for a file constant.
Restriction
The BUFFERED attribute conflicts with the UNBUFFERED attribute. Buffering only applies to RECORD files.
2.2.9. 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 scope where you used the function's name as a variable name.
You can also use the BUILTIN attribute to invoke a built-in function that takes no arguments (such as the DATE function) without including 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, /* supersedes the variable */ (A,B,TEST) FIXED BIN(15); A = 10; B = 20; 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.10. CHARACTER Attribute
The CHARACTER attribute identifies a variable as a character-string variable. The format of the CHARACTER attribute is:
{ CHARACTER } [(length)]
{ CHAR }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.11. 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.12. 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.
2.2.13. 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 1 through 15.
The default values applied to the DECIMAL attribute are listed in Table 2.3, “Default Values for the DECIMAL Attribute.”.
Table 2.3. Default Values for the DECIMAL Attribute.Attributes Specified dec Dialect ibm Dialect ansi Dialect DECIMAL FIXED (10,0) FIXED (5,0) FIXED (10,0) DECIMAL FIXED (10,0) (5,0) (10,0) DECIMAL FIXED (n) (n,0) (n,0) (n,0) DECIMAL FLOAT (7) (6) (7)
Restrictions
The DECIMAL attribute conflicts with any other data-type attribute.
2.2.14. 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 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 ZIP CHARACTER(20), 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.
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 }(bound-pair, ...)
{ DIM }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 defaults to 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.
For a description of the attributes that are applied to files, see Section 9.1.3.3, “Establishing the File's 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 }) ] [ { C } ] [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) (dec and ansi dialects only)
Indicates 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.
OPTIONS(VARIABLE) conflicts with OPTIONS(C).
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 POSIX Systems User's Manual.
- OPTIONS (C)
Indicates that the called routine is written in C and should be called using the C language calling and return conventions. OPTIONS(C) conflicts with OPTIONS(VARIABLE).
- 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 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
F, FB, FS, or FBS (IBM Dialect Only)
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)
V, VB, VS, or VBS (IBM Dialect Only)
WORLD_PROTECTION(character-expression)
WRITE_BEHIND
The previous list of options to the ENVIRONMENT attribute are described in detail in the Endless PL/I for POSIX Systems User's 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.
Note that IBM's implementation of PL/I lets you specify the ENVIRONMENT option only in a DECLARE statement. Keep this in mind when using ENVIRONMENT options if you require compatibility with IBM's implementation of PL/I.
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.
For a description of the attributes that are applied to files, see Section 9.1.3.3, “Establishing the File's Attributes”.
2.2.19. EXTERNAL Attribute
The EXTERNAL attribute declares an external name, that is, a name whose value is known to blocks outside the block where it is declared. The format of the EXTERNAL attribute is:
{ EXTERNAL } [('name')]
{ 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.
- (`name')
The exact, case-sensitive, name of the external variable.
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.
For a description of the attributes that are applied to files, see Section 9.1.3.3, “Establishing the File's Attributes”.
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) define a variable that takes fixed-point binary integer values of up to a maximum of 31 bits. 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 use fixed-point binary data to represent integers. The precision of a fixed-point binary variable must be in the range 1 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 listed in Table 2.4, “Default Values for Unspecified FIXED Attributes”.
Table 2.4. Default Values for Unspecified FIXED AttributesAttributes Specified dec Dialect ibm Dialect ansi Dialect FIXED BINARY (31) DECIMAL (5,0) BINARY(15) FIXED BINARY (31) (15) (15) FIXED DECIMAL (10,0) (5,0) (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)]precisionThe 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 listed in Table 2.5, “Default Values for Unspecified FLOAT Attributes”.
Table 2.5. Default Values for Unspecified FLOAT AttributesAttributes Specified dec Dialect ibm Dialect ansi Dialect FLOAT BINARY (24) DECIMAL(6) BINARY(24) FLOAT BINARY (24) (21) (24) FLOAT DECIMAL (7) (6) (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 ($), pound signs (#), at signs (@), and underscores (_). The first character cannot be numeric (0 through 9).
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.
The following initial value is interpreted as a string replication factor, not an iteration factor, and cannot be used to initialize a whole array:
INITIAL ((10)'ABC')
- (*)
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-constantscalar-reference(
scalar-expression)(aggregate-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 can specify the INITIAL attribute for an automatic structure variable only if you initialize the structure through an aggregate valued function. For example:
DECLARE 1 TEST_STRUC, 2 FIRST_MEMBER CHARACTER (8), 2 SEC_MEMBER FIXED BINARY(15); DECLARE INIT_FUNCTION ENTRY(FIXED,FIXED) RETURNS(1 LIKE TEST_STRUC); DECLARE INPUT_STRUC LIKE TEST_STRUC INITIAL (INIT_FUNCTION(X,Y));
In this example, INIT_FUNCTION is an external function that returns a structure matching TEST_STRUC.
To initialize a structure without using an aggregate valued function, 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.
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.
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.32. 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.33. 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.
The OPTIONAL attribute indicates that an actual parameter need not be specified in a call. If the actual parameter is not specified, you must specify a placeholder for it. PL/I passes a longword zero as the actual parameter in that position. The format of the OPTIONAL attribute is:
OPTIONAL
Example
DCL E ENTRY (FIXED,FIXED OPTIONAL); CALL E(1,2); CALL E(1,);
2.2.35. 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).
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 more information.
2.2.37. 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.6.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.38. 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.39. 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.40. 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.41. 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.
For a description of the attributes that are applied to files, see Section 9.1.3.3, “Establishing the File's Attributes”.
Restriction
The PRINT attribute conflicts with the INPUT, RECORD, UPDATE, KEYED, SEQUENTIAL, and DIRECT attributes.
2.2.42. 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.43. 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.
For a description of the attributes that are applied to files, see Section 9.1.3.3, “Establishing the File's Attributes”.
Restriction
The RECORD attribute conflicts with the STREAM and PRINT attributes.
The REFER attribute defines dynamically self-defining structures. The format of the REFER attribute is:
refer-elementREFER (refer-object-reference)
See Section 4.2.6.3, “Using the REFER Option” for more information.
2.2.45. REFERENCE Attribute
The REFERENCE attribute is accepted by Endless PL/I for POSIX Systems, for compatibility with other implementations of PL/I, but is ignored. By default, asterisk (*) extent parameters are passed by descriptor, in compliance with the PL/I language standard, and cannot be passed by reference. All other parameters are passed by reference in Endless PL/I for POSIX Systems unless the VALUE attribute is specified. The format of the REFERENCE attribute is:
{ REFERENCE }
{ REF }Restriction
Note that you can only use the REFERENCE attribute in parameter descriptors.
2.2.46. RETURNS Attribute
The RETURNS attribute 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.47. 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.
For a description of the attributes that are applied to files, see Section 9.1.3.3, “Establishing the File's Attributes”.
Restriction
The SEQUENTIAL attribute conflicts with the DIRECT, STREAM, and PRINT attributes.
2.2.48. 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.49. 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.
For a description of the attributes that are applied to files, see Section 9.1.3.3, “Establishing the File's Attributes”.
Restriction
The STREAM attribute directly conflicts with the RECORD, KEYED, DIRECT, SEQUENTIAL, and UPDATE attributes.
You can optionally specify the STRUCTURE attribute in the declaration of a structure. The format of the STRUCTURE attribute is:
STRUCTURE
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] TYPEreferenceorlevel-numberidentifier[attributes] TYPE (reference)
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. You can optionally enclose this name in parentheses.
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
The following examples show circular declarations. Do not use these types of declarations.
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 */
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.
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.
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.
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-number{identifier} [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.
- *
You can specify an asterisk (*) in place of the identifier name.
storage-classThe storage class specified for the structure. You can specify the storage class only on level 1.
Example
The following example uses the UNION attribute to acquire a date from the DATE built-in function and display it as three separate variables containing the year, month, and day. The major structure uses an asterisk (*) in place of the identifier name.
MAIN PROCEDURE OPTIONS(MAIN); DECLARE 1 * UNION STATIC, 2 MC_DATE CHARACTER(6), 2 S_PARTS, 3 YEAR CHARACTER(2), 3 MONTH CHARACTER(2), 3 DAY CHARACTER(2); MC_DATE = DATE(); PUT SKIP LIST (YEAR, MONTH, DAY); END MAIN;
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 53
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 } { GLOBALDEF [(psect-name)] [INITIAL(value)] }
{ VAL } { GLOBALREF }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 bit-string, character-string, or graphic 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 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 POSIX Systems User's Manual for more information.
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).