File constant

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 1 lists the PL/I alternative file attributes.


Table 1. 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 2 shows the attributes that apply to each type of data transmission.


Table 2. Attributes by data transmission type
Type of transmission Attribute
Stream-oriented ENVIRONMENT
  INPUT and OUTPUT
  PRINT
  STREAM
Record-oriented BUFFERED and UNBUFFERED
  DIRECT and SEQUENTIAL
  ENVIRONMENT
  INPUT, OUTPUT, and UPDATE
  KEYED
  RECORD

Table 3 shows the valid combinations of file attributes.

Table 3. Attributes of PL/I file declarations
File
Type
S
T
R
E
A
M
RECORD
Legend:
I
Must be specified or implied  
D
Default
O
Optional
S
Must be specified
-
Invalid
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
FILE
I
I
I
I
I
I
 
INPUT1
D
D
D
D
D
D
FILE
OUTPUT
O
O
O
O
O
O
FILE
ENVIRONMENT
O
O
O
O
O
O
FILE
STREAM
D
-
-
-
-
-
FILE
PRINT1
O
-
-
-
-
-
FILE STREAM OUTPUT
RECORD
-
I
I
I
I
I
FILE
UPDATE2
-
O
O
O
O
O
FILE RECORD
SEQUENTIAL
-
D
D
D
-
-
FILE RECORD
KEYED3
-
-
O
O
I
I
FILE RECORD
DIRECT
-
-
-
-
S
S
FILE RECORD KEYED
Notes:
  • 1 A file with the INPUT attribute cannot have the PRINT attribute
  • 2 UPDATE is invalid for tape files.
  • 3 KEYED is required for indexed and relative output

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 Sample is declared as a file constant:
  declare Sample file;