Example 4: Specifying the key field
Example: Specifying the key field for physical and logical files
Example 4: Specifying the key field
The example shows how several record formats function as a set. In this example, assume that an employee has repeated a class. To sequence two records with the same values for EMPNBR and CLSDTE, a third key field, DATE, is specified in record format CLSHST.
However, DATE cannot be specified in the next available key position (position 3) because JOBDTE and ACTDTE appear in that position for other formats. If DATE is specified in this position, the attributes of DATE are compared with the attributes of CLSHST and JOBHST, and the key definitions are rejected.
To obtain the sequencing necessary, specify *NONE before DATE, displacing DATE to key position 4.
The DATE field can be shown in position 4 as in Figure 1.
Figure 1. Specifying the key field
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00010A R EMPMST PFILE(EMPMSTP)
00020A K EMPNBR
00030A*
00040A R CLSREG PFILE(CLSREGP)
00050A K EMPNBR
00060A K CLSDTE
00070A*
00080A R CLSHST PFILE(CLSHSTP)
00090A K EMPNBR
00100A K CLSDTE
00110A K *NONE 1
00120A K DATE 1
00130A*
00140A R JOBHST PFILE(JOBHSTP)
00150A K EMPNBR
00160A K *NONE
00170A K JOBDTE
00180A*
00190A R ACTHST PFILE(ACTHSTP)
00200A K EMPNBR
00210A K *NONE
00220A K ACTDTE
A
| Record format | Key positions | |||
|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |
| EMPMST | EMPNBR | *NONE | *NONE | *NONE |
| CLSREG | EMPNBR | CLSDTE | *NONE | *NONE |
| CLSHST | EMPNBR | CLSDTE | *NONE | DATE |
| JOBHST | EMPNBR | *NONE | JOBDTE | *NONE |
| ACTHST | EMPNBR | *NONE | ACTDTE | *NONE |
Specifying DATE in key position 4 enables records from physical file CLSHSTP with identical values for EMPNBR and CLSDTE to be merged and sequenced according to the value for DATE.
Note: Because values are actually placed in the keys to ensure the sequencing in the previous examples, duplicate key values are not always predictable when *NONE is needed for logical files with more than one record format.