Wayne_in_Texas
New User
Joined: 28 Dec 2024 Posts: 10 Location: USA
|
|
|
|
Note: Below might be a mixture of EXACT coding terms as I've been retired a number of years now and no current access to a mainframe. Also I'm drawing this mostly from memory so let me know if I've screwed something up, but I've used this process hundreds (if not more) of times and once to even match 6 files. Lastly, if this is all really common knowledge now and not really relevant, I apologize.
Matching 3 Files (or more) is really pretty easy. I had been doing it and flowcharting it for over 45 years. To successfully match 3 files, eliminating convoluted logic testing for "highs" or "lows", and eliminating problems with end of files, all you have to do is:
1)Each file must be sorted ascending on the common KEY (kind of obvious)
WORKING-STORAGE:
2)Establish a "WORK-KEY" for each file (example: WORK1-KEY, WORK2-KEY, WORK3-KEY)
3)Establish a "LOW-TAG" KEY (example: LOW-TAG)
4)Establish a simple "Counter" for process control (example: CASE defined as 9)
PROCEDURE DIVISION:
5)Create a file READ routine for EACH individual file:
Read File1 (File2, File3)
AT END MOVE HIGH-VALUES TO its WORK?-KEY
ELSE MOVE input file key to its WORK?-KEY
6)Establish a find-lowest-key routine (example: FIND-LOW) that simply does:
MOVE WORK1-KEY TO LOW-TAG
IF WORK2-KEY LESS THAN LOW-TAG, MOVE WORK2-KEY TO LOW-TAG
IF WORK3-KEY LESS THAN LOW-TAG, MOVE WORK3-KEY TO LOW-TAG
Exit
(This establishes the Lowest KEY from all 3 files and does not matter if any are equal...yet)
7)In the initialization routine:
(Perform a Read of each File to establish its WORK?-KEY to start out)
READ-FILE1
READ-FILE2
READ-FILE3
PERFORM FIND-LOW
(LOW-TAG now has the lowest key value across all 3 files and ready to start processing)
8)Main Logic Flow Loop (performed until LOW-TAG equals HIGH-VALUES):
(When LOW-TAG equals HIGH-VALUES all files have been processed. Perform End functions and Exit)
MOVE 0 TO CASE
IF WORK1-KEY EQUAL LOW-TAG, ADD 1 TO CASE
IF WORK2-KEY EQUAL LOW-TAG, ADD 2 TO CASE
IF WORK3-KEY EQUAL LOW-TAG, ADD 4 TO CASE
(Values will only exist as 1,2,3,4,5,6, or 7)
1=File 1 is Low
2=File 2 is Low
3=Files 1 and 2 are Low
4=File 3 is Low
5=Files 1 and 3 are Low
6=File 2 and 3 are Low
7=All files are Low
Simple processing can take place knowing what processing is needed for EACH value
Note that whatever processing takes place, each MUST perform Read(s) for the files WORKed
(example: If CASE equals 3, do processing for matching Files 1 and 2 AND before leaving that
processing Paragraph, calls to read File 1 and File 2 MUST be performed AND before cycling
around for a new sequence of tests, a call to FIND-LOW MUST be performed. This is because
READs were performed during processing)
(This is pretty simplistic presentation as sometimes additional logic testing/processing is
needed to handle files with multiple matching records like multiple payment/invoice records
for a customer account but that's easy to handle)
This "LOW-TAG" method eliminates the worry of which file(s) ended first or who is "high" or "low".
Matching more than 3 files, while bulky is still pretty easy. Example: a 4 file match would add
the value value of 8 making CASE test values to be 1,2,3,4,5,6,7,8,9,10,11,12,13,14,or 15.
You know what you need to do for each set so just have to build processing logic for each one.
It all WORKs easily when you don't have worry about the actual File KEY values because the
value in "CASE" tells you what processing is needed and on what files.
The only caveat is the actual files cannot contain an ending KEY value of HIGH-VALUES. If that did
exist, it could be easily worked around by skipping the AT END and test for HIGH-VALUES to move
to the save key. Although, in all my years I can't ever remember that coming up.
PS: This can also work on just 2 files as well...again eliminating the high/low/end issues.
[/code] |
|