Join a physical file to itself (example 8)

You can join a physical file to itself to read records that are formed by combining two or more records from the physical file itself.

The following chart shows how you can join a physical file to itself:


Examples of records

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)
     A
 
PF1
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A          R RCD1
     A            NBR            3
     A            NAME          10          DFT('none')
     A            MGRNBR         3
     A
Notes:
  1. 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.
  2. 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.

Table 2. Join logical file (JLF)
Employee number Name Manager's name
235 Anne Doug
440 Doug Sue
500 Mark Doug
729 Sue none
Notes:
  1. A record is returned for the manager name of Sue because the JDFTVAL keyword was specified.
  2. The value none is returned because the DFT keyword was used on the Name field in the PF1 physical file.