The following program shows a method to make Easytrieve's Synchronized File Processing work in a way beyond which it was designed. This program will process all matching records, even if there are duplicates on the most major file (in this example, FILEA).
This example ignores any records that do not exist on both files. Additional logic may be added to handle this situation, if necessary.
This code assumes FILEA is fixed and its record length is 150, FILEB is also fixed with a record length of 100. The array is built assuming that there will be no more than 10 duplicate key records that exist on FILEB.
FILEA
FLDA 1 10 A .* key field used in sync processing
.
.
FILEB
RECB 1 100 A .* define entire record
FLDB 10 10 A .* key field used in sync processing
.
.
ENTIRE-ARRAY W 1000 A VALUE ' ' .* length times occurs equals this length
WSB-ARRAY ENTIRE-ARRAY 100 A OCCURS 10
SAVE-KEY W 10 A .* save the key of FILEA
WS-RECB W 100 A .* unload array into this area
.
. you may need to define all fields of FILEB here
.
ARRAY-CNT W 2 B 0 VALUE 0
ARRAY-SUB W 2 B 0 VALUE 0
JOB INPUT (FILEA KEY(FLDA) FILEB KEY (FLDB))
IF MATCHED
IF FIRST-DUP FILEA
ARRAY-CNT = ARRAY-CNT + 1
IF ARRAY-CNT GT 10
DISPLAY 'ARRAY OVERLOAD - CHANGE OCCURS AMOUNT'
STOP EXECUTE
END-IF
WSB-ARRAY (ARRAY-CNT) = RECB
END-IF
.
. other program logic
.
SAVE-KEY = FLDA
END-IF
IF NOT MATCHED AND FILEA AND FLDA = SAVE-KEY
ARRAY-SUB = 1
DO WHILE ARRAY-SUB LE ARRAY-CNT
WS-RECB = WSB-ARRAY (ARRAY-SUB)
.
. other program logic
.
ARRAY-SUB = ARRAY-SUB + 1
END-DO
IF LAST-DUP FILEA
MOVE SPACES TO ENTIRE-ARRAY
ARRAY-CNT = 0
END-IF
END-IF
.
.
.
NOTE: This is just a skeleton program. Additional code should be inserted as required. This example ignores any unmatched records from either file, you could add code to handle this situation as well.
FILEA FILEB
A A
A A
B A
B
Normally, Synchronized File Processing would process the first FILEA key A against all of the FILEB key A records and the second key A record from FILEA would be presented as NOT MATCHED. The above code will read the first key A record from FILEA and the first Key A record from FILEB and present that as a MATCH, it will then read FILEB record 2 and present that as a match with the first record from FILEA. While this processing is going on, the FILEB records are being stored in the array. Once we read the fourth record in FILEB and encounter an unmatched key we then read ahead in FILEA, since the key of FILEA matches the SAVE-KEY we will process the second record from FILEA against the array of FILEB records. Record two from FILEA is the last duplicate which causes the array to be emptied. Processing continues to the next record in FILEA which now matches the current key of FILEB, another MATCH condition.