Beruflich Dokumente
Kultur Dokumente
DAY 3
Pl/I Training
INPUT / OUTPUT
I/O
PL/I input and output statements let you transmit data between the main
storage and auxiliary storage of a computer. A collection of data external to
a program is called a data set. Transmission of data from a data set to a
program is termed input. Transmission of data from a program to a data set
is called output.
PL/I input and output statements are concerned with the logical organization
of a data set and not with its physical characteristics. A program can be
designed without specific knowledge of the input/output devices that are
used when the program is executed. To allow a source program to deal
primarily with the logical aspects of data rather than with its physical
organization in a data set, PL/I employs models of data sets, called files. A
file can be associated with different data sets at different times during the
execution of a program.
I/O – Data Transmission
Data Transmission
Stream-Oriented Data-Oriented
I/O – Stream Oriented Data Transmission
The organization of a data set determines how data is recorded in a data set
and how the data is subsequently retrieved so that it can be transmitted to
the program. Records are stored in and retrieved from a data set either
sequentially on the basis of successive physical or logical positions, or
directly by the use of keys specified in data transmission statements.
These storage and retrieval methods provide PL/I with five data set
organizations:
CONSECUTIVE
INDEXED
REGIONAL
TP
VSAM
I/O - FILES
To allow a source program to deal primarily with the logical aspects of data
rather than with its physical organization in a data set, PL/I employs models
of data sets, called files.
These models determine how input and output statements access and
process the associated data set.
Unlike a data set, a file has significance only within the source program and
does not exist as a physical entity external to the program.
A name that represents a file has the FILE attribute.
I/O – FILE Attribute
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.
I/O – FILE Attribute
The attributes associated with a file constant 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.
An additive attribute is one that must be stated explicitly or is implied by
another explicitly stated attribute. The additive attribute KEYED is implied by
the DIRECT attribute. The additive attribute PRINT can be implied by the
output file name SYSPRINT.
I/O – Stream Oriented – List of Attributes
ENVIRONMENT
INPUT
OUTPUT
PRINT
STREAM
I/O – Record Oriented – List of Attributes
BACKWARDS
INPUT
SEQUENTIAL
BUFFERED
KEYED
TRANSIENT
DIRECT
OUTPUT
UNBUFFERED
ENVIRONMENT
RECORD
UPDATE
EXCLUSIVE
I/O – Example of a FILE Constant
A file variable has the attributes FILE and VARIABLE; it cannot have any of the
file 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 for a name with the FILE attribute if the name
is an element of an array or structure, or if any of the following attributes is
specified:
Storage class attribute
parameter
alignment attribute
DEFINED
INITIAL
I/O – File Variable Example
ON-units can be established for a file constant through a file variable that
represents its value
DCL F FILE,
G FILE VARIABLE;
G=F;
L1: ON ENDFILE(G);
L2: ON ENDFILE(F);
I/O – Alternative Attributes
Alternative Attributes
The RECORD and STREAM attributes specify the kind of data transmission
used for the file. STREAM indicates that the data of the file is a continuous
stream of data items, in character form, assigned from the stream to
variables, or from expressions into the stream. RECORD indicates that the
file consists of a collection of physically separate records, each of which
consists of one or more data items in any form. Each record is transmitted
as an entity to or from a variable.
STREAM
RECORD
I/O – RECORD / STREAM Attributes
A file with the STREAM attribute can be specified only in the OPEN,
CLOSE, GET, and PUT input/output statements.
A file with the RECORD attribute can be specified only in the OPEN,
CLOSE, READ, WRITE, REWRITE, LOCATE, UNLOCK, and DELETE
input/output statements.
Default attribute is STREAM.
I/O – INPUT, OUTPUT and UPDATE Attributes
The function attributes specify the direction of data transmission allowed for
a file.
INPUT specifies that data is transmitted from auxiliary storage to the
program.
OUTPUT specifies that data is transmitted from the program to auxiliary
storage, either to create a new data set or to extend an existing one.
UPDATE, which applies to RECORD files only, specifies that the data can
be transmitted in either direction.
That is, it allows records inserted into an existing data set and other records
already in that data set altered.
INPUT
OUTPUT
UPDATE
I/O – INPUT, OUTPUT and UPDATE Attributes
The access attributes apply only to RECORD files, and specify how the
records in the file are accessed.
DIRECT
SEQUENTIAL
TRANSIENT
The DIRECT attribute specifies that records in a data set can be accessed
in any order. The location of the record in the data set is determined by a
character-string key; therefore, the DIRECT attribute implies the KEYED
attribute. The associated data set must be on a direct-access volume.
I/O - SEQUENTIAL, DIRECT, and TRANSIENT
Attributes
BUFFERED
UNBUFFERED
Abbreviations: BUF for BUFFERED UNBUF for UNBUFFERED
The BUFFERED attribute specifies that, during transmission to and from
auxiliary storage, each record of a RECORD file must pass through
intermediate storage buffers. If BUFFERED is specified, data transmission
(in most cases) is overlapped with processing.
The UNBUFFERED attribute indicates that a record in a data set need not
pass through a buffer but can be transmitted directly to and from the main
storage associates with a variable. It does not, however, specify that
records cannot be buffered.
The default for SEQUENTIAL and TRANSIENT files is BUFFERED.
UNBUFFERED is the default for DIRECT files unless BUFFERED is
specified explicitly.
I/O – Additive Attributes
BACKWARDS
ENVIRONMENT
EXCLUSIVE
KEYED
PRINT
I/O – BACKWARDS Attribute
BACKWARDS
I/O – ENVIRONMENT Attribute
ENVIRONMENT (character-list)
Characteristic-List
EXCLUSIVE
EXL is an alias for EXCLUSIVE
The KEYED attribute applies only to RECORD files, and must be associated
with direct access devices or with a file with the TRANSIENT attribute. It
specifies that records in the file can be accessed using one of the key
options (KEY, KEYTO, or KEYFROM) of data transmission statements or of
the DELETE statement.
KEYED
The KEYED attribute need not be specified unless one of the key options is
used.
I/O – Opening and Closing
Syntax
Notes:
1. INPUT and OUTPUT are default attributes for READ and
WRITE statements only if UPDATE has not been
explicitly declared.
I/O – Implicit Opening
READ
WRITE
REWRITE
LOCATE
DELETE
UNLOCK
I/O – READ Statement
The READ statement can be used with any INPUT or UPDATE file. It
transmits a record from the data set to the program, either directly to a
variable or to a buffer. In blocked records, a READ statement with the
appropriate option transfers a record from a buffer to the variable or sets a
pointer to the record in a buffer. Consequently, not every READ statement
transmits data from an input device.
I/O – WRITE Statement
The WRITE statement can be used with any OUTPUT file or DIRECT
UPDATE file, and also with SEQUENTIAL UPDATE files associated with
VSAM data sets. It transmits a record from the program and adds it to the
data set. For unblocked records, transmission can be directly from a
variable or from a buffer. For blocked records, the WRITE statement places
a logical record into a buffer; only when the blocking of the records is
complete is there actual transmission of data to an output device.
I/O – REWRITE Statement
FILE
INTO
FROM
SET
IGNORE
KEY
KEYFROM
KEYTO
EVENT
NOLOCK
I/O – FILE Option
The INTO option specifies an element or aggregate variable into which the
logical record is read. The INTO option can be used in the READ statement
for any INPUT or UPDATE file.
The FROM option specifies the element or aggregate variable from which
the record is written. The FROM option must be used in the WRITE
statement for any OUTPUT or DIRECT UPDATE file. It can also be used in
the REWRITE statement for any UPDATE file.
The SET option specifies a pointer variable that is set to point to the location
in the buffer into which data has been moved during the READ operation, or
which has been allocated by the LOCATE statement.
The SET option can be used with a READ statement or a LOCATE
statement.
For the LOCATE statement, if the SET option is omitted, the pointer
declared with the record variable is set.
the value of the pointer variable P is set to the location in the buffer of the next
sequential record
I/O – IGNORE Option
The KEY option specifies a character or graphic key that identifies a record.
It can be used in a READ statement for an INPUT or UPDATE file, or in a
REWRITE statement for a DIRECT UPDATE file.
The KEY option applies only to KEYED files associated with data sets of
INDEXED, REGIONAL, or VSAM organization. The KEY option must
appear if the file has the DIRECT attribute.
The KEY option can also appear for a file having INDEXED or VSAM
organization and the SEQUENTIAL and KEYED attributes.
The expression in the KEY option is evaluated and, if not character or
graphic, is converted to a character value that represents a key. It is this
character or graphic value that determines which record is read.
String-handling
Arithmetic
Mathematical
Array-handling
Condition-handling
Storage control
Event
Multitasking
Input/Output
Miscellaneous
Built-In - String Handling Functions
ONSOURCE
Built-In - Storage Control Functions
The event built-in functions allow you to determine the current state of an
event.
COMPLETION STATUS
Built-In – I/O Built-In Functions
The input/output built-in functions allow you to determine the current state of
a file
COUNT
LINENO
SAMEKEY
Built-In - Miscellaneous Functions
PLICANC
PLIRETC
PLICKPT
PLISRTA
PLISRTB
PLISRTC
PLISRTD
PLIDUMP
PLITEST
PLIREST
PLIDUMP Example.doc
Built-In – Using Built-In Subroutine PLIDUMP
character-string-expression 2
is a user-identified character string up to 80 characters long that is printed
as the dump header.