Example 8: Joining a physical file to itself
This example shows how to use a join logical file to combine records from one physical file.
The following chart shows how you can join a physical file to itself.
The join logical file (JLF) contains Employee number, Name, and Manager's name. The physical file (PF1) contains Employee number, Name, and Manager's employee number. The following example shows the data description specifications (DDS) for these files:
JLF |...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A JDFTVAL A R JOINREC JFILE(PF1 PF1) A J JOIN(1 2) A JFLD(MGRNBR NBR) A NBR JREF(1) A NAME JREF(1) A MGRNAME RENAME(NAME) A JREF(2) ANotes:PF1 |...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A R RCD1 A NBR 3 A NAME 10 DFT('none') A MGRNBR 3 A
- Relative file numbers must be specified on the JOIN keyword because the same file name is specified twice on the JFILE keyword. Relative file number 1 refers to the first physical file specified on the JFILE keyword, 2 refers to the second, and so forth.
- With the same physical files specified on the JFILE keyword, the JREF keyword is required for each field specified at the field level.
Assume that the following records are contained in PF1.
Table 1. Physical file 1 (PF1) Employee number Name Manager's employee number 235 Anne 440 440 Doug 729 500 Mark 440 729 Sue 888 The program reads the following logical file records.
Notes:
Table 2. Join logical file (JLF) Employee number Name Manager's name 235 Anne Doug 440 Doug Sue 500 Mark Doug 729 Sue none
- A record is returned for the manager name of Sue because the JDFTVAL keyword was specified.
- The value none is returned because the DFT keyword was used on the Name field in the PF1 physical file.
Parent topic:
Setting up a join logical file