Input and output
PL/I input and output statements (such as READ, WRITE, GET, PUT) let you transmit data between the main 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 called input. Transmission
of data from a program to a data set is called output. (If
you are using a terminal,
data set can also mean your terminal.)
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 is 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.
PL/I uses two types of data transmission: stream and record.
- Stream-oriented data transmission
organization of the data in the data set is ignored within the program,
and the data is treated as though it were a continuous stream of individual
data values in character form. Data is converted from character form
to internal form on input, and from internal form to character form
Stream-oriented data transmission can be used for processing input data prepared in character form and for producing readable output, where editing is required. Stream-oriented data transmission allows synchronized communication with the program at run time from a terminal, if the program is interactive.
Stream-oriented data transmission is more versatile than record-oriented data transmission in its data-formatting abilities, but is less efficient in terms of run time.
- Record-oriented data transmission
data set is a collection of discrete records. The record on the external
medium is generally an exact copy of the record as it exists in internal
storage. No data conversion takes place during record-oriented data
transmission. On input the data is transmitted exactly as it is recorded
in the data set, and on output it is transmitted exactly as it is
Record-oriented data transmission can be used for processing files that contain data in any representation, such as binary, decimal, or character.
Record-oriented data transmission is more versatile than stream-oriented data transmission, in both the manner in which data can be processed and the types of data sets that it can process. Because data is recorded in a data set exactly as it appears in main storage, any data type is acceptable. No conversions occur, but you must have a greater awareness of the data structure.
It is possible for the same data set to be processed at different times by either stream or record data transmission. However, all items in the data set must be in character form.
The following topics discuss the kinds of data sets, the attributes for describing files, and how you open and close files in order to transmit data. For more information about the types of data set organizations that PL/I recognizes, refer to the Programming Guide.