Sign in

docs RPG Reference

Processing Matching Records

Processing Matching Records

Processing Matching Records

Matching records for two or more files are processed in the following manner:

  • Whenever a record from the primary file matches a record from the secondary file, the primary file is processed first. Then the matching secondary file is processed. The record identifying indicator that identifies the record type just selected is on at the time the record is processed. This indicator is often used to control the type of processing that takes place.
  • Whenever records from ascending files do not match, the record having the lowest match field content is processed first. Whenever records from descending files do not match, the record having the highest match field content is processed first.
  • A record type that has no match field specification is processed immediately after the record it follows. The MR indicator is off. If this record type is first in the file, it is processed first even if it is not in the primary file.
  • The matching of records makes it possible to enter data from primary records into their matching secondary records because the primary record is processed before the matching secondary record. However, the transfer of data from secondary records to matching primary records can be done only when look-ahead fields are specified.

Figure 1 through Figure 2 show how records from three files are selected for processing.

Figure 1. Normal Record Selection from Three Disk Files

Normal Record Selection from Three Disk Files

The records from the three disk files above are selected in the order indicated by the dark numbers.

Table 1. Normal Record Selection from Three Disk Files

CycleFile ProcessedIndicators OnReason for Setting Indicator
1PRIMARY02No match field specified
2PRIMARY02No match field specified
3FIRSTSEC04No match field specified
4SECSEC05Second secondary low; no primary match
5PRIMARY01, MRPrimary matches first secondary
6PRIMARY01, MRPrimary matches first secondary
7FIRSTSEC03, MRFirst secondary matches primary
8FIRSTSEC03First secondary low; no primary match
9FIRSTSEC03First secondary low; no primary match
10SECSEC05Second secondary low; no primary match
11PRIMARY01Primary low; no secondary match
12PRIMARY01, MRPrimary matches second secondary
13PRIMARY02No match field specified
14SECSEC05, MRSecond secondary matches primary
15SECSEC05, MRSecond secondary matches primary
16SECSEC06No match field specified
17PRIMARY01, MRPrimary matches both secondary files
18FIRSTSEC03, MRFirst secondary matches primary
19FIRSTSEC04No match field specified
20SECSEC05, MRSecond secondary matches primary
21FIRSTSEC03First secondary low; no primary match
22PRIMARY01, MRPrimary matches both secondary files
23FIRSTSEC03, MRFirst secondary matches primary
24FIRSTSEC02, MRFirst secondary matches primary
25SECSEC05, MRSecond secondary matches primary
26SECSEC05, MRSecond secondary matches primary

Figure 2. Normal Record Selection from Three Disk Files, Part 1

This figure illustrates Normal Record Selection from Three Disk Files

Figure 3. Normal Record Selection from Three Disk Files, Part 2

This figure illustrates Normal Record Selection from Three Disk Files