RPG Tutorial: Using Tables

Tables are used in RPG to store collections of related data.  Usually, but not always, tables are defined, loaded, and utilized in pairs.  The first table of a pair contains a list of arguments that is searched to obtain the location of both the argument element and the corresponding function element in the related table.  A simple example of a pair of tables is a list of department numbers and their related department names:

Department Number

Department Name

01 Art
02 Business
03 Biology
04 Chemistry
05 Economics

It is also possible to define and utilize a single table.  One use of such a table might be to validate a data field using a list of possible valid field contents.  The single table of department numbers could be used to validate that a department number field contained a valid entry, without the necessity of loading the corresponding department name table.

A table file is a collection of records that provides all of the table entries for a particular table.  Table files are associated with the tables for which they contain entries by utilizing the File Extension specification.  The organization of a table file must be sequential.  A table file is identified on the File specification by placing a T in the File Designation (column 16).  

Table files are loaded into main storage from the device on which they are stored, prior to reading the first record from any other input or update file defined.  The table files are loaded in the order in which they appear in the File Extension specifications.  Table files may reside on cards, tape, or disk files.  The rules for preparing table records are:

The information in tables may be updated by specifying the table element as the target of a calculation operation following a successful LOKUP operation.  The updated tables may then be written out at the conclusion of the RPG program by specifying a target file in the To File Name (columns 19-26) of the File Extension specification.  Although table entries may be updated, they may not be added.  Entries may be provided to allow for "expansion" in the table by including "dummy" elements which can be identified by the data they contain.  These "dummy" elements may be updated by the program, replacing the elements with valid data.  The files to receive the updated table elements must be defined on the File Description specifications as Output (O in column 15) and Table (T in column 16).

Return to Site Home Page 

This page was last updated on January 17, 2015.