Associating Files with Input/Output Devices

The key element for all I/O operations on the i5/OS is the file. The system supports the following file types:

database files
allow storage of data permanently on system
device files
allow access to externally attached devices. Include display files, printer files, tape files, diskette files, and ICF files.
save files
used to store saved data on disk
DDM files
allow access to data files stored on remote systems.

Each I/O device has a corresponding file description of one of the above types which the program uses to access that device. The actual device association is made when the file is processed: the data is read from or written to the device when the file is used for processing.

RPG also allows access to files and devices not directly supported by the system, through the use of SPECIAL files. With a SPECIAL file, you must provide a program that handles the association of the name to the file, and the data management for the file. With other types of files, this is handled by RPG and the operating system.

To indicate to the operating system which file description(s) your program will use, you specify a file name in positions 7 through 16 of a file description specification for each file used. In positions 36 through 42 you specify an RPG device name. The device name defines which RPG operations can be used with the associated file. The device name can be one of: DISK, PRINTER, WORKSTN, SEQ, or SPECIAL. Figure 153 shows a file description specification for a display (WORKSTN) file FILEX.

Figure 153. Identifying a Display File in an RPG Program
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... *
FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++++++++++++++
FFILEX     CF   E             WORKSTN

Note that it is the file name, not the device name (specified in positions 36 through 42) which points to the IBM i file description that contains the specifications for the actual device.

The RPG device types correspond to the above file types as follows:

Table 43. Correlation of RPG Device Types with i5/OS File Types
RPG Device Type i5/OS File Type
DISK database, save, DDM files
PRINTER printer files
WORKSTN display, ICF files
SEQ tape, diskette, save, printer, database
SPECIAL N/A

Figure 154 illustrates the association of the RPG file name FILEX, as coded in Figure 153, with a system file description for a display file.

Figure 154. Associating a file name with a display file description

At compilation time, certain RPG operations are valid only for a specific RPG device name. In this respect, the RPG operation is device dependent. One example of device dependency is that the EXFMT operation code is valid only for a WORKSTN device.

Other operation codes are device independent, meaning that they can be used with any device type. For example, WRITE is a device-independent operation.

The SEQ Device

The device SEQ is an independent device type. Figure 155 illustrates the association of the RPG file name FILEY with a system file description for a sequential device. When the program is run, the actual I/O device is specified in the description of FILEY. For example, the device might be PRINTER.

Figure 155. Associating a file name with a display file description

Although the file name and file type are coded in the RPG program, in many cases you can change the type of file or the device used in a program without changing the program. To find out how, see Overriding and Redirecting File Input and Output.



[ Top of Page | Previous Page | Next Page | Contents | Index ]