While researching a problem I encountered writing the example programs for this tutorial, I read something that leads me to believe that the capability to create, update, and access Indexed-Sequential files with RPG programs became available around the time that the RPG compiler included with OS/360 MVT 21.8f. This may explain why a bug that I experienced in the RPG compiler included with DOS 26 in 1973-1975 is also present in the MVT 21.8f compiler. I state this to explain why some of the Indexed-Sequential processing with RPG I is rather primitive and limited.
The additional entries required on the File specification for an output Indexed-Sequential file (as compared to an ordinary sequential output file) are:
The records written to the Indexed-Sequential file being built must be written in ascending key sequence. If an attempt is made to write a record with a key equal to or less than the key of the record previously written to the file, H0 will be set on and the program will terminate abnormally.
There are no additional entries required beyond those listed above (for building Indexed-Sequential files) in order to process an Indexed-Sequential file in its entirety. A sequentially processed file may be used as input (I in column 15 on the File specification) or update (U in column 15). If processed as an update file, records from the file may be updated at either detail or total time. The record available for updating is the record read on the previous input cycle.
From one to nine Indexed-Sequential files may be processed by the use of record key fields specified as chaining fields. A data field in an input record is designated as a chaining field by placing the chaining field identifier (C1, C2, C3, ... C9 in columns 61-62 of the Input specification). Each chaining field must also be included on an Extension specification which functions to link the chaining file to the chained file.
During the input cycle, the record key(s) contained in one or more chaining fields are used to retrieve the corresponding record(s) from the Indexed-Sequential file specified on the Extension specification. Chaining is the only circumstance in which more than one record identifying indicator may be on during a single cycle.
If an attempt to read a record from an Indexed-Sequential file randomly using a chaining field is not successful, the H0 indicator will be turned on. It is the responsibility of the program to turn off the H0 indicator if the program is not to be terminated abnormally at the end of the detail cycle.
A Record Address File, containing either individual record keys or a range of record keys, may be used to control which records are selected for processing from an Indexed-Sequential file.
Whenever a Record Address File is used, an Extension specification must be used to associate the Record Address File with the Indexed-Sequential file it controls. Only one Record Address File may be used in any single RPG I program.
If the Record Address File is used to specify range(s) of records to process, the Mode of Processing (column 28) for the Indexed-Sequential file must contain an L (limits). Each record in the Record Address File must contain one or more pairs of record keys. The first record key of the first (or only) pair of record keys must begin in position one of the record. The second record key of each (or the only) pair must immediately follow the first record key of the pair. The last (or only) pair of record keys in the Record Address File record must be followed by a series of blanks as long as an individual record key. This signals the RPG program to read the next record from the Record Address File. The two record keys provided in the Record Address File record represent the upper and lower limits of the Indexed-Sequential file area containing records to be processed.
If the Record Address File is used to specify individual records to process, the Mode of Processing (column 28) for the Indexed-Sequential file must contain an R (random). Each record in the Record Address File must contain one or more record keys. The first (or only) record key must begin in position one of the record. Each successive record key must immediately follow the previous record key. The last (or only) record key in the Record Address File record must be followed by a series of blanks as long as an individual record key. This signals the RPG program to read the next record from the Record Address File.
Records may be added to Indexed-Sequential files if the Indexed-Sequential file is being processed randomly. File Addition (column 66) on the File specification for the Indexed-Sequential file must contain an A. The Output specification used to add a record to the Indexed-Sequential file must contain ADD in columns 16-18. The program logic must ensure that an attempt is not made to add a record to the Indexed-Sequential file containing a key identical to a record already existing in the file. If an attempt is made to add a duplicate key, H0 will be turned on and the program will be abnormally terminated at the beginning of the next input cycle.
This page was last updated on August 21, 2003.