The File I/O Library subroutines help you read and write ASCII or EBCDIC files to and from your ESL programs. Some of the tasks you can perform with the File I/O subroutines are:
Create a file.
Append to a file.
Read lines from a file sequentially.
Access any specified line in a file.
Read a single line into a single string variable.
Read a single line into a combination of string, integer, and float variables according to a specification called a record.
Write a single string to a file.
Write a record containing a combination of string, integer, and float variables.
Control parameters that enable tradeoffs between program speed and size.
Obtain the time and date when the file was last modified.
Files are processed as follows:
1. To prepare a file for processing, the file is opened with specific parameters that identify the file (the file identifier and the filename), and that specify whether the file is to be read, written, or appended (the access mode).
2. The file is then processed by calling one or more of the Input or Output subroutines, depending on whether you are reading or writing to the file.
3. After processing is complete, the file is closed.
The Input and Output subroutines treat files as if they are composed of lines. They enable you to read or write lines of the file sequentially or randomly, or as a combination of both methods. Files consisting of fields of fixed size in fixed locations can be mapped into separate variables by using an appropriate record definition. Records can also be written, so that files can be created in a specific fixed format.
The fields of the record are defined in the record definition statement, which must be declared before file processing begins. The record name is then used as a parameter for certain Input and Output subroutines that read or write records.
The parameter types that are passed to any of the File I/O subroutines are specific to that subroutine, with the exception of the fileid, which is an integer parameter type. It is used as the unique identifier for files in all I/O subroutines. Parameters can be either input or output. Input parameters already have values when the subroutine is called, whereas output parameters have a value assigned during the execution of the subroutine.
If a File I/O Library subroutine encounters an error, errorlevel is set to the number of the error found. errorlevel contains a value of zero when no errors are detected. The GetError( ) subroutine sets a string variable to the error message associated with the errorlevel number passed to it.