Controlling how records are retrieved in a logical file with multiple formats

 

Key field definitions are required in a logical file with more than one record format.

Each record format can have its own key field definition. The record format key fields can be defined to merge the records from different formats. Each record format does not have to contain every key field in the key.

Consider the following records.

Table 1. Header record format
Record Order Cust Ordate
1 41882 41394 050688
2 32133 28674 060288

Table 2. Detail record format
Record Order Line Item Qtyord Extens
A 32133 01 46412 25 125000
B 32133 03 12481 4 001000
C 41882 02 46412 10 050000
D 32133 02 14201 110 454500
E 41882 01 08265 40 008000
In data description specifications (DDS), the header record format is defined before the detail record format. If the access path uses the Order field as the first key field for both record formats and the Line field as the second key field for only the second record format, both in ascending sequence, the order of the records in the access path is:

Records with duplicate key values are arranged first in the sequence in which the physical files are specified. Then, if duplicates still exist within a record format, the duplicate records are arranged in the order specified by the FIFO, LIFO, or FCFO keyword. For example, if the logical file specified the DDS keyword FIFO, then duplicate records within the format would be presented in first-in-first-out sequence.

For logical files with more than one record format, you can use the *NONE DDS function for key fields to separate records of one record format from records of other record formats in the same access path. Generally, records from all record formats are merged based on key values. However, if *NONE is specified in DDS for a key field, only the records with key fields that appear in all record formats before the *NONE are merged. When such records are retrieved by key from more than one record format, only key fields that appear in all record formats before the *NONE are used. To increase the number of key fields that are used, limit the number of record formats considered.

The logical file in the following example contains three record formats, each associated with a different physical file:

Record format Physical file Key fields
EMPMSTR EMPMSTR Empnbr (employee number) 1
EMPHIST EMPHIST Empnbr, Empdat (employed date) 2
EMPEDUC EMPEDUC Empnbr, Clsnbr (class number) 3

All record formats have one key field in common, the Empnbr field.

The DDS for this example is:

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
      A       A          K EMPNBR  1
      A       A          K EMPNBR  2
      A          K EMPDAT       A       A          K EMPNBR  3
      A          K *NONE       A          K CLSNBR       A

*NONE is assumed for the second and third key fields for EMPMSTR and the third key field for EMPHIST because no key fields follow these key field positions.

The following table shows the arrangement of the records.

Empnbr Empdat Clsnbr Record format name
426     EMPMSTR
426 6/15/74   EMPHIST
426   412 EMPEDUC
426   520 EMPEDUC
427     EMPMSTR
427 9/30/75   EMPHIST
427   412 EMPEDUC
*NONE serves as a separator for the record formats EMPHIST and EMPEDUC. All the records for EMPHIST with the same Empnbr field are grouped together and sorted by the Empdat field. All the records for EMPEDUC with the same Empnbr field are grouped together and sorted by the Clsnbr field.

Because additional key field values are placed in the key sequence access path to guarantee the above sequencing, duplicate key values are not predictable.

 

Parent topic:

Creating a logical file with more than one record format

 

Related concepts


DDS concepts