Before a file can be used for data transmission, by input or output statements, it must be associated with a data set. Opening a file associates the file with a data set and involves checking for the availability of external media, positioning the media, and allocating required operating system support. When processing is completed, the file must be closed. Closing a file dissociates the file from the data set.
PL/I provides two statements, OPEN and CLOSE, to perform these functions. However, use of these statements is optional. If an OPEN statement is not executed for a file, the file is opened implicitly during the execution of first data transmission statement for that file. In this case, the file opening uses information about the file as specified in a DECLARE statement (and defaults derived from the transmission statement). Similarly, if a file has not been closed before PL/I termination, PL/I will close it during the termination process.
When a file for stream input, sequential input, or sequential update is opened, the associated data set is positioned at the first record.