Example 4: Using join fields whose attributes are different
This example shows how to handle join fields when their attributes (length, data type, and decimal positions) are different.
For example, as in Example 3: Reading duplicate records in the secondary file, the Name1 field is a character field 10 characters long in physical file PF1, and can be joined to the Name2 field, a character field 10 characters long in physical file PF2. The Name1 and Name2 fields have the same characteristics and, therefore, can easily be used as join fields.
You can also use character type fields that have different lengths as join fields without requiring any redefinition of the fields. For example, if the NAME1 field of PF1 is 10 characters long and the NAME2 field of PF2 is 15 characters long, those fields can be used as join fields without redefining one of the fields.
The following example shows the join fields that do not have the same attributes. Both physical files have fields for employee number. The Nbr field in physical file PF1 and the Nbr field in physical file PF2 both have a length of 3 specified in position 34, but in the PF1 file the field is zoned (S in position 35), and in the PF2 file the field is packed (P in position 35). To join the two files using these fields as join fields, redefine one or both fields to have the same attributes.
The following example illustrates the fields in the logical and physical files:
The join logical file (JLF) contains Employee number, Name, and Salary fields. Physical file 1 (PF1) contains Employee number (zoned) and Name. Physical file 2 (PF2) contains Employee number (packed) and Salary. The data description specifications (DDS) for these files are shown as follows:
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 S JREF(2) A NAME A SALARY APF1 |...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A R REC1 A NBR 3S 0 <-Zoned A NAME 20 A K NBR A
PF2 |...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A R REC2 A NBR 3P 0 <-Packed A SALARY 7 2 A K NBR A
In this example, the Nbr field in the logical file comes from PF2, because JREF(2) is specified. Instead of specifying the physical file name, you can specify a relative file number on the JREF keyword; in this example, the 2 indicates PF2.
Because the Nbr fields in the PF1 and PF2 files are used as the join fields, they must have the same attributes. In this example, they do not. Therefore, redefine one or both of them to have the same attributes. In this example, to resolve the difference in the attributes of the two employee number fields, the Nbr field in JLF (which is coming from the PF2 file) is redefined as zoned (S in position 35 of JLF).
Parent topic:
Setting up a join logical file