Reading a join logical file
These cases show how the join logical file in example 1 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 things:
If you specify the JDFTVAL keyword:
- Uses the value of the first join field in the primary file (the Nbr field in PF1).
- Finds the first record in the secondary file with a matching join field (the Nbr field in PF2 matches the Nbr field in PF1).
- For each match, joins the fields from the physical files into one record and provides this record to your program. Depending on how many records are in the physical files, one of the following conditions might occur:
- For all records in the primary file, only one matching record is found in the secondary file. The resulting join logical file contains a single record for each record in the primary file. See Case 1: Matching records in primary and secondary files.
- For some records in the primary file, no matching record is found in the secondary file.
If you do not specify the JDFTVAL keyword:
- For those records in the primary file that have a matching record in the secondary file, the system joins to the secondary, or multiple secondaries. The result is one or more records for each record in the primary file.
- For those records in the primary file that do not have a matching record in the secondary file, the system adds the default value fields for the secondary file and continues the join operation. You can use the DFT keyword in the physical file to define which defaults are used. See Case 2A: A record missing in the secondary file (JDFTVAL keyword not specified) and Case 2B: A record missing in the secondary file (JDFTVAL keyword specified).
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 a record exists in the secondary file, but the primary file has no matching value, no record is returned to your program. A second join logical file can be used that reverses the order of primary and secondary files to determine if secondary file records exist with no matching primary file records.
- If a matching record in a secondary file exists, the system joins to the secondary, or multiple secondaries. The result is one or more records for each record in the primary file.
- If a matching record in a secondary file does not exist, the system does not return a record.
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.
Parent topic:
Example 1: Basic concepts of joining two physical files