Reading Duplicate Records in Secondary Files (Example 3)

Sometimes a join to a secondary file produces more than one record from the secondary file. When this occurs, specifying the JDUPSEQ keyword in the join specification for that secondary file tells the system to base the order of the duplicate records on the specified field in the secondary file.

The DDS for the physical files and for the join logical file are as follows:

Figure 14. DDS Example Using the JDUPSEQ Keyword

JLF
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A          R JREC                      JFILE(PF1 PF2)
     A          J                           JOIN(PF1 PF2)
     A                                      JFLD(NAME1 NAME2)
     A                                      JDUPSEQ(TELEPHONE)
     A            NAME1
     A            ADDR
     A            TELEPHONE
     A
 
PF1
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A          R REC1
     A            NAME1         10
     A            ADDR          20
     A
 
PF2
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A          R REC2
     A            NAME2         10
     A            TELEPHONE      8
     A

The physical files have the following records:
Examples of Records

The join logical file returns the following records:
Examples of Records

The program reads all the records available for Anne, then Doug, then Mark. Anne has one address, but three telephone numbers. Therefore, there are three records returned for Anne.

The records for Anne sort in ascending sequence by telephone number because the JDUPSEQ keyword sorts in ascending sequence unless you specify *DESCEND as the keyword parameter. The following example shows the use of *DESCEND in DDS:



JLF
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A          R JREC                      JFILE(PF1 PF2)
     A          J                           JOIN(PF1 PF2)
     A                                      JFLD(NAME1 NAME2)
     A                                      JDUPSEQ(TELEPHONE *DESCEND)
     A            NAME1
     A            ADDR
     A            TELEPHONE
     A

When you specify JDUPSEQ with *DESCEND, the records are returned as follows:
Examples of Records
Note:The JDUPSEQ keyword applies only to the join specification in which it is specified. For an example showing the JDUPSEQ keyword in a join logical file with more than one join specification, see A Complex Join Logical File (Example 10).


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]