The FILE attribute specifies that the associated name is a file constant or file variable.
|
The FILE attribute can be implied for a file constant by any of the file description attributes. A name can be contextually declared as a file constant through its appearance in the FILE option of any input or output statement, or in an ON statement for any input/output condition.
Each data set processed by a PL/I program must be associated with a file constant.
The individual characteristics of each file constant are described with file description attributes. These attributes fall into two categories: alternative attributes and additive attributes.
An alternative attribute is one that is chosen from a group of attributes. If no explicit or implied attribute is given for one of the alternatives in a group and if one of the alternatives is required, a default attribute is used.
Table 29 lists the PL/I alternative file attributes.
|
Group Type |
Alternative Attributes |
Default Attribute |
|---|---|---|
|
Usage |
STREAM or RECORD |
STREAM |
|
Function |
INPUT or OUTPUT or UPDATE |
INPUT |
|
Access |
SEQUENTIAL or DIRECT |
SEQUENTIAL |
|
Buffering |
BUFFERED or UNBUFFERED |
BUFFERED (for SEQUENTIAL files); UNBUFFERED (for DIRECT files) |
|
Scope |
EXTERNAL or INTERNAL |
EXTERNAL |
An additive attribute is one that must be stated explicitly or is implied by another explicitly stated attribute. The additive attributes are ENVIRONMENT, KEYED and PRINT. The additive attribute KEYED is implied by the DIRECT attribute. The additive attribute PRINT can be implied by the output file name SYSPRINT.
Table 30 shows the attributes that apply to each type of data transmission.
| Type of transmission | Attribute |
|---|---|
| Stream-oriented | ENVIRONMENT |
| INPUT and OUTPUT | |
| STREAM | |
| Record-oriented | BUFFERED and UNBUFFERED |
| DIRECT and SEQUENTIAL | |
| ENVIRONMENT | |
| INPUT, OUTPUT, and UPDATE | |
| KEYED | |
| RECORD |
Table 31 shows the valid combinations of file attributes.
|
File Type |
S T R E A M |
RECORD |
Legend:
|
||||
|---|---|---|---|---|---|---|---|
|
SEQUENTIAL |
DIRECT |
||||||
|
Data Set Organization |
C o n s e c u t i v e |
C o n s e c u t i v e |
R e l a t i v e |
I n d e x e d |
R e l a t i v e |
I n d e x e d |
|
|
File Attributes |
Attributes Implied |
||||||
Scope is discussed in Scope of declarations.
The FILE attribute can be implied for a file constant by any of the file description attributes discussed in this chapter. A name can be contextually declared as a file constant through its appearance in the FILE option of any input or output statement, or in an ON statement for any input/output condition.
In the following example, the name Master is declared as a file constant:
declare Master file;
A file variable has the attributes FILE and VARIABLE. It cannot have any of the file constant description attributes. File constants can be assigned to file variables. After assignment, a reference to the file variable has the same significance as a reference to the assigned file constant.
The value of a file variable can be transmitted by record-oriented transmission statements. The value of the file variable on the data set might not be valid after transmission.
The VARIABLE attribute is implied under the circumstances described in VARIABLE attribute.
In the following declaration Account is declared as a file variable, and Acct1 and Acct2 are declared as file constants. The file constants can subsequently be assigned to the file variable.
declare Account file variable,
Acct1 file,
Acc2 file;
For syntax information, refer to VARIABLE attribute.
A file reference can be a file constant, a file variable, or a function reference which returns a value with the FILE attribute. It can be used in the following ways:
On-units can be established for a file constant through a file variable that represents its value (see ON-units for file variables). In the following example, the statements labelled L1 and L2 both specify null ON-units for the same file.
dcl F file,
G file variable;
G=F;
L1: on endfile(G);
L2: on endfile(F);