This module covers detailed explanation of using files in RPGLE programs. Handles different ways of reading the data from the database files and also covers manipulating data through Record and Window type screens.
File Handling:
Whenever a file is used in a program, it needs to be declared in the File specification. The program can use database files(PF and LF), display files or report files.
Files can be declared globally in the main source section or locally within a sub procedure.
File Types:
Externally-described – The description of the file(structure) is defined outside the program. The file has been created using DDS or SQL. The structure is defined only once and can be used in any program
Program-described – The file is available as a flat file outside without any proper structure. The structure gets described within each program which uses that file
File Handling methods:
Logic Cycle(Program Cycle) Method:
The compiler generates code for performing series of steps whenever a record is read. It simplifies the programmer’s code. The source program need not explicitly specify when a record to be read or written. It will be done by the compiler generated code. When a file is declared as a Primary and Secondary file(File Designation – P/S), it is said to be handled by program cycle method.
Fully Procedural Method:
The programmer codes the file access logic in the calculation specification. The Read and Write operations need to be explicitly coded in the calculation specification. It makes the program more readable as the complete logic will be visible. The files need to be declared as fully procedural file(File Designation – F).
Read Operation Codes:
READ, READP, READE, READPE, CHAIN
Positioning Operation Codes:
SETLL, SETGT
Data Manipulation Operation Codes:
WRITE, UPDATE, DELETE