A join logical file is a logical file that combines (in one record format) fields from two or more physical files. In the record format, not all the fields need to exist in all the physical files.
The following example illustrates a join logical file that joins two
physical files. This example is used for the five cases discussed in
Example 1.

In this example, employee number is common to both physical files (PF1 and PF2), but name is found only in PF1, and salary is found only in PF2.
With a join logical file, the application program does one read operation (to the record format in the join logical file) and gets all the data needed from both physical files. Without the join specification, the logical file would contain two record formats, one based on PF1 and the other based on PF2, and the application program would have to do two read operations to get all the needed data from the two physical files. Thus, join provides more flexibility in designing your database.
However, a few restrictions are placed on join logical files:
The following shows the DDS for Example 1:
Figure 13. DDS Example for Joining Two Physical Files
JLF
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
A R JOINREC JFILE(PF1 PF2)
A J JOIN(PF1 PF2)
A JFLD(NBR NBR)
A NBR JREF(PF1)
A NAME
A SALARY
A K NBR
A
PF1
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
A R REC1
A NBR 10
A NAME 20
A K NBR
A
PF2
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
A R REC2
A NBR 10
A SALARY 7 2
A K NBR
A
The following describes the DDS for the join logical file in Example 1 (see the DDS Reference for more information on the specific keywords):
The record level specification identifies the record format name used in the join logical file.
The join specification describes the way a pair of physical files is joined. The second file of the pair is always a secondary file, and there must be one join specification for each secondary file.
Join fields, except character type fields, must have the same attributes (data type, length, and decimal positions). If the fields are character type fields, they do not need to have the same length. If you are joining physical file fields that do not have the same attributes, you can redefine them for use in a join logical file. See Using Join Fields Whose Attributes Are Different (Example 4) for a description and example.
The field level specification identifies the fields included in the join logical file.
The key field level specification is optional, and includes the key field names for the join logical file.
The select/omit field level specification is optional, and includes select/omit field names for the join logical file.
The following cases describe how the join logical file in Figure 13 presents records to an application program.
The PF1 file is specified first on the JFILE keyword, and is therefore the primary file. When the application program requests a record, the system does the following:
If you specify the JDFTVAL keyword:
| Note: | If the DFT keyword is specified in the secondary file, the value specified for the DFT keyword is used in the join. The result would be at least one join record for each primary record. |
If you do not specify the JDFTVAL keyword:
| Note: | When the JDFTVAL is not specified, the system returns a record only if a match is found in every secondary file for a record in the primary file. |
In the following examples, cases 1 through 4 describe sequential read operations, and case 5 describes reading by key.
Assume that a join logical file is specified as in Figure 13, and that four records are contained in both PF1 and PF2, as
follows:

The program does four read operations and gets the following records:

Assume that a join logical file is specified as in Figure 13, and that there are four records in PF1 and three records in
PF2, as follows:

With the join logical file shown in Example 1, the program reads the join
logical file and gets the following records:

If you do not specify the JDFTVAL keyword and no match is found for the join field in the secondary file, the record is not included in the join logical file.
Assume that a join logical file is specified as in Figure 13, except that the JDFTVAL keyword is specified, as shown in the following DDS:
JLF
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
A JDFTVAL
A R JOINREC JFILE(PF1 PF2)
A J JOIN(PF1 PF2)
A JFLD(NBR NBR)
A NBR JREF(PF1)
A NAME
A SALARY
A K NBR
A
The program reads the join logical file and gets the following
records:

With JDFTVAL specified, the system returns a record for 500, even though the record is missing in PF2. Without that record, some field values can be missing in the join record (in this case, the Salary field is missing). With JDFTVAL specified, missing character fields normally use blanks; missing numeric fields use zeros. However, if the DFT keyword is specified for the field in the physical file, the default value specified on the DFT keyword is used.
Assume that a join logical file is specified as in Figure 13, and that four records in PF1 and five records in PF2, as
follows:

The program gets five records:

For more information, see Reading Duplicate Records in Secondary Files (Example 3).
Assume that a join logical file is specified as in Figure 13, and that four records are contained in PF1 and five records
in PF2, as follows:

The program reads the join logical file and gets only four records, which
would be the same even if JDFTVAL was specified (because a record must always
be contained in the primary file to get a join record):

Assume that a join logical file is specified as in Figure 13. Note that the join logical file has key fields defined. This case shows which records would be returned for a random access read operation using the join logical file.
Assume that PF1 and PF2 have the following records:

The program can get the following records:
Given a value of 235 from the program for the Nbr field in the
logical file, the system supplies the following record:

Given a value of 500 from the program for the Nbr field in the
logical file and with the JDFTVAL keyword specified, the system supplies the
following record:

| Note: | If the JDFTVAL keyword was not specified in the join logical file, no record would be found for a value of 500 because no matching record is contained in the secondary file. |
Given a value of 984 from the program for the Nbr field in the logical file, the system supplies no record and a no record found exception occurs because record 984 is not in the primary file.
Given a value of 997 from the program for the Nbr field in the
logical file, the system returns one of the following records:

Which record is returned to the program cannot be predicted. To specify which record is returned, specify the JDUPSEQ keyword in the join logical file. See Reading Duplicate Records in Secondary Files (Example 3).
Notes: