Declare Physical(PF), Logical(LF), Display(DSPF) and Printer(PRTF) Files in ILE RPG (RPG IV)
Files are indispensable in any interactive program. If you have to take user input then you will need Display Files. If you want to print these inputs, then you will require printer files. If you want to store the user input somewhere, you will require physical files. So, you see that files in ILE RPG programs are very important.
Comparison with Other databases.
The physical files in ILE RPG are very much similar to tables of other databases. The difference here is that in order to connect to a database in some other language you need connection object (eg. Using the mysql_Connect() function in PHP, jdbc:odbc bridge in java etc). In ILE RPG all the database files are directly avaialable to your program. You just have to declare a file (Physical File) in ILE RPG program and you're done. Once you have declared a file in your ILE RPG program, you can access it using OpCodes. You say READ, and the program reads the file! It's very simple. Isn't it?
File Declaration
In ILE RPG, We can declare files in input, output or update (meaning input+output) modes. So, before we are going to include any files we must decide beforehand the mode in which the files are to be used. Now we will learn how to declare files in different modes. The syntax to declare a file is given below.
FFilename++IPEASF.....L.....A.Device FFILE1 IF A E K Disk
The file declaration begins with specifying the File Specification on 6th position. Immediately after this We specify the file name. The file name as you must be knowing can take maximum of 10 characters.
After this We specify the mode of the file. In the example above, the mode has been taken as I - Input. Other valid modes are O for Output, U for input+output (Update).
Immediately after the mode declaration, comes the file designation. For all common files we will be dealing with, the valid values are 'F' - meaning full procedural file and blanks for a file declared in Output mode.
By the letter A we specify that records can be added to this file using the "Write" opcode.
The letter E denotes that the file is of external type. Actually in ILE RPG we can have two types of files Program Described File and External Files. All files which exist on the disk of the as400 machine are treated as external files. External to the ILE RPG program. Lastly the Device name. The Device name is disk for all database files.
Armed with the knowledge gained above, we can now declare the database files in other modes also. The database files have been declared in other modes(Update - Add, Output) below.
FFilename++IPEASF.....L.....A.Device FFILE2 UF A E K Disk FFILE3 O E K Disk
Declaration of a Display File
The display files are declared in a way very much similar to database files with minor differences. A typical display file would be declared in an ILE RPG program as below.
** Syntax to declare a display file FFilename++IPEASF.....L.....A.Device+ FFILE4 CF E WorkStn
The difference are explained as below.
The display files are used for display purpose only. They do not store any data. However with respect to an ILE RPG program, the display files are written in same way as database files to throw any screen. The diplay files are also read to take user inputs. Hence display files are always declared in
input+outmode. The letter to denote this is 'C' in this case however.
The device type of a display file workstn. Meaning that display files will be
used at the user end only.
Syntax to declare Printer Files in ILE RPG Program.
Printer files are output only files. Hence we declare a printer file as given in example below. The device type incase of a printer file is PRINTER.
FFilename++IPEASFRlen+LKlen+AIDevice+ FFILE4 O E PRINTER
- 6163 reads
