Supporting Multi-file Tables

Multi-file table support allows the records of more than one COBOL data file to be combined into a single table.

If your COBOL application has data from several different business units, stored in different COBOL data files on the same machine, you can connect them to the same table definition.

Each table connection has a different table name that must be used in the SQL statement to indicate which data file is to be accessed. Sometimes, however, it is desirable to query the data in all business units. While it is possible to use separate table connections and to combine the resulting rows in the ODBC application, Relativity uses multi-file table support to perform this process automatically and at a record level, making use of the file keys.

The combining of records can occur in one of two ways. Either the records from each individual file are processed into rows separately, with each file being processed completely before proceeding to the next file, or the records from the individual files are read using the same key on each file and merged into one sorted record stream as if they were from a single file.

To control which method to use, and, in the ODBC application, to be able to distinguish the business unit from which the row originated, a special file definition item called a "file label" is added to the file's FD using the Designer. A given FD may have only one file label item. A file label item can have a column defined on it, and this column will be part of the indexes defined on the table. Assuming that columns are completely defined on all the file key parts, at least two indexes will be created for each file key: one with the file label column as the most significant part of the index, and one with the file label column as the least significant part of the index. If a query uses the index that has the file label column as the most significant column, then rows from each file will be grouped together. If a query uses the index that has the file label column as the least significant column, then the rows from each file will be returned merged together.

Note: To understand the difference between grouping records and merging records based on an index, consider two decks of playing cards, with each deck having different backs so that it is possible to tell which deck a card came from. If one deck of cards is placed on top of the other, the cards are grouped together by deck. But, if the cards are shuffled together, then they are merged. If the cards were then sorted into suits by their value without looking at which deck each card came from, then the cards are merged based on an index (their suit and value).

In Relativity, consider a table based on two files. Using the index that returns rows grouped together, the ODBC application would first see all the rows from the first file, and then the rows from the second. Using the index that merges the two files together, the ODBC application would see rows coming back from the two files mixed together.

When a COBOL data file is added to a multi-file table, it is assigned a value for its file label. This is the value that is returned in the file label column. Note that while it is usually desirable to assign the same file label value to all the files from the different business units, Relativity does not require or enforce this.