Example 2: Dynamically join database files without DDS

This example shows how to read only those records with secondary file records when dynamically joining database files without DDS.

Assume that you want to join files FILEAB, FILECD, and FILEEF to select only those records with matching records in secondary files. Define a file JOINF and describe the format that should be used. Assume that the record formats for the files contain the following fields:

FILEAB FILECD FILEEF JOINF
Abitm Cditm Efitm Abitm
Abord Cddscp Efcolr Abord
Abdat Cdcolr Efqty Cddscp
      Cdcolr
      Efqty

In this case, all field names in the files that make up the join file begin with a 2-character prefix (identical for all fields in the file) and end with a suffix that is identical across all the files (for example, xxitm). This makes all field names unique and avoids having to qualify them.

The xxitm field allows the join from FILEAB to FILECD. The two fields xxitm and xxcolr allow the join from FILECD to FILEEF. A keyed sequence access path does not have to exist for these files. However, if a keyed sequence access path does exist, performance might improve significantly because the system will attempt to use the existing access path to arrange and select records, where it can. If access paths do not exist, the system automatically creates and maintains them as long as the file is open.
OVRDBF     FILE(JOINF) TOFILE(FILEAB) SHARE(*YES)
OPNQRYF    FILE(FILEAB FILECD FILEEF) +
              FORMAT(JOINF) +
              JFLD((ABITM CDITM)(CDITM EFITM) +
              (CDCOLR EFCOLR))
CALL       PGM(PGME) /* Created using file JOINF as input */
CLOF       OPNID(FILEAB)
DLTOVR     FILE(JOINF)
The join field pairs do not have to be specified in the preceding order. For example, the same result is achieved with a JFLD parameter value of:
JFLD((CDCOLR EFCOLR)(ABITM CDITM) (CDITM EFITM))

The attributes of each pair of join fields do not have to be identical. Normal padding of character fields and decimal alignment for numeric fields occurs automatically.

The JDFTVAL parameter is not specified so *NO is assumed and no default values are used to construct join records. If you specified JDFTVAL(*YES) and there is no record in file FILECD that has the same join field value as a record in file FILEAB, defaults are used for the Cddscp and Cdcolr fields to join to file FILEEF. Using these defaults, a matching record can be found in file FILEEF (depending on if the default value matches a record in the secondary file). If not, a default value appears for these files and for the Efqty field.