Alternate record key support for the ILE COBOL compiler.
Original Publication Date: 2002-Aug-12
Included in the Prior Art Database: 2003-Jun-21
The invention is implemented in the ILE COBOL Compiler for iSeries system. The purpose is to provide support for Alternate Record Keys as defined by ANSI 85 COBOL. Alternate Record keys are defined in a COBOL program using the "ALTERNATE RECORD KEY IS data-item" clause. More than one alternate key is allowed. Usually, records in an indexed file are accessed using the primary key to order the records. Defining alternate keys allow the COBOL program to access the index file using an alternate key to order the records instead of the primary key. Database files in iSeries have support only for primary keys. That is, the records in the files can be accessed using a keyed sequence base on the primary key. Indexed COBOL files are mapped to these system database files. The RECORD KEY clause is used to map the record key data item defined in the COBOL program to the primary key of the database file. If system database files have support for alternate keys, the implementation of alternate record keys would be simple. The COBOL program can simply map an alternate key data item defined in the program to the alternate keys of the database file. The compiler must be adapted since system database files do not support alternate keys. The problem is solved as follows. Although the system does not provide support for alternate keys in database files, there is an API (QQQQRY) that can perform queries against database files. The QQQQRY API has the ability to perform an order-by-field query against any field of a database file and return a file pointer that allows access of the file records in the order specified by the query. This file pointer is similar to the one use by the COBOL run-time to read records ordered by the primary key. As an example, if the database file has three fields (FLD1, FLD2, and FLD3) and field FLD1 is the key field, the QQQQRY API can be used to perform an order-by-field FLD2 query. The file pointer returned by the API can then be used to read records from the file and these records will be returned ordered by FLD2. For each alternate record key defined in the COBOL program, our run-time can use QQQQRY to perform an order-by-field query. The file pointer returned by the API is saved. When the COBOL program wants to access the file using an alternate record key, the appropriate file pointer is used to read from the file. To do the query, the offset and length of the alternate record key data-item defined in the COBOL program is used and map it to a field in the database file. The field that has the same offset and length is the one that is used to perform the query.