Files serve as the connecting link between a program and the device used for input and output. The actual device association is made at the time the file is opened. In some instances, this type of I/O control allows the user to change the attribute of the file (and, in some cases, change the device) used in a program without changing the program.
In the ILE COBOL language, the file name specified in the ASSIGNMENT-NAME entry of the ASSIGN clause of the file control entry is used to point to the file. This file name points to the system file description:
The ILE COBOL device name in the ASSIGN clause defines the ILE COBOL functions that can be processed on the selected file. At compilation time, certain ILE COBOL functions are valid only for a specific ILE COBOL device type; in this respect, ILE COBOL is device dependent. The following are examples of device dependency:
For example, assume that the file name FILEY is associated in the ILE COBOL program with the FORMATFILE device. The device FORMATFILE is an independent device type. Therefore, no line or page control specifications are valid so the ADVANCING phrase cannot be specified in the WRITE statement for a FORMATFILE file. When the program is run, the actual I/O device is specified in the description of FILEY. For example, the device might be a printer; only the default line and page control or those defined in the DDS would be used:
CL commands can be used to override a parameter in the specified file description or to redirect a file at compilation time or run time. File redirection allows the user to specify one file at compilation time and another file at run time:
In the preceding example, the Override to Diskette File (OVRDKTF) command allows the program to run with an entirely different device file than was specified at compilation time.
Not all file overrides are valid. At run time, checking occurs to ensure that the specifications within the ILE COBOL program are valid for the file being processed. If the specifications passed by the ILE COBOL program in the file control block and the I/O request are incorrect, the I/O operation will fail. The OS/400 operating system allows some file redirections even if device specifics are contained in the program. For example, if the ILE COBOL device name is PRINTER and the actual file the program uses is not a printer, the operating system ignores the ILE COBOL print spacing and skipping specifications.
There are other file redirections that the operating system does not allow and that may cause the file to become unusable. For example, if the ILE COBOL device name is DATABASE or DISK and a keyed READ operation is specified in the program, the file becomes unusable if the actual file the program uses is not a disk or database file.
The AS/400 system provides for the use of input and output spooling functions. Each AS/400 file description contains a spool attribute that determines whether spooling is used for the file at run time. The ILE COBOL program is not aware that spooling is being used. The actual physical device from which a file is read or to which a file is written is determined by the spool reader or the spool writer. For more detailed information on spooling, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site - http://publib.boulder.ibm.com/pubs/html/as400/infocenter.htm.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.