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:
|
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.
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)
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.