Three file processing

Speaker Notes:

Slide 1:

This presentation deals with two types of 3 file processing situations.

Slide 2:

This program is matching records from three files. Notice that there is only 1 record per id on each file and that the data is not being combined, rather it is being merged together into one file.

The flowchart is continued on the next page.

Slide 3:

This continues the previous flowchart and deals with the case where ID1 < ID2.

Slide 4:

The initial read of each file is done prior to reaching the processing. All of the ids match so all records are written to the output. If I wanted to combine information from the files and produce one output record, the processing could be done instead of simply writing the record.

Slide 5:

Again there are three records with the same id so all are written to the file.

Slide 6:

This time ID1 is greater than ID2 and ID2 = ID3 so both the record from file 2 and the record from file3 are written to the output file.

Slide 7:

Again I have three matching records so all are written to the output file.

Slide 8:

This time records from file1 and file 2 are written and then records from file1 and file 2 are read.

Slide 9:

File 1 is less than file 2 and file 1 is greater file3 so file 3 is the smallest and the one that got written.

Slide 10:

File 1 is less than file 2 and file 3 so it gets written.

Slide 11:

The three matching records are written and a record is read from each file.

Slide 12:

File2sng has reached EOF so the logic can put 999 in the id for comparison purposes or do special EOF processing.

Slide 13:

Since file2sng has reached EOF, I have set up the logic that has 999 in its ID so it is the largest. File 1 is less that file 2 and equal to file 3 so file 1 and file 2 are written. When I read from these two files I hit EOF and at EOF on all three files processing terminates.

Slide 14:

Because there are multiple in each file, I am determining which file has the record with the smallest id and I am putting that in the hold area.

Slide 15:

This starts looking at the logic where there are three records and each can have multiple records per id. There is also no requirement that an id appear on any particular file.

Slide 16:

This deals with more of the logic with the three files. The situation where ID1 was greater than ID2 was handled on the previous slide. The situation where ID1 = ID2 is handled on this slide. The situation where ID1 < ID2 is handled on the next slide. Notice that I do not need to ask that question because if ID1 is not greater than ID2 and not equal to ID2 it has to be less than ID2.

Slide 17:

This part of the flowchart is entered when ID1 is less than ID2. Again, it is because we know that ID1 is not greater than or equal to ID2.

Slide 18:

Note that I am showing the numbers in total amount based on what record the amount added came from.

In this example, the three records have the same id so the three amounts are added to tot amount and then three records are read - one from each file.

Slide 19:

Three more amounts are added to total amount and the next record is read from each of the files.

Slide 20:

The ID1(111) is less than the ID2(222) and the ID3(112) so the amount from the record on file1mul is added to the total amount and a new record is read from file1mul.

Slide 21:

All of the records with id of 111 have been processed, the 111 is taken from the holdid and the amount is taken from the accumulator and the record is written on the file. The 112 from the id of file3mul is moved to the holdid and the amount of 12 is moved to the accumulator. Finally, since we have processed the record on file3mul, a new record is read from this file.

Slide 22:

There was only one record for 112. It is now being written and then the new id is moved to holdid and the total amount is zeroed out. We then added the amount from the three records to the accumulator and read another record from each file.

Slide 23:

The ID2 (222) is less than the ID1 (333) and ID2 (333) and ID2 = holdid so the record is processed and a new record is read from file 2.

Slide 24:

ID2 (300) is less than the ids on the other files and it is not equal to the hold id so the record with the id of 222 is written out and the new record from file2mul is processed.

Slide 25:

Record 300 is written and processing starts on records with id 333.

Slide 26:

There are still records with 333 so they are processed and then where there was a 333 that was processed, a record is read from that file.

Processing would continue using this style. I suggest you do some of it and see if you are processing correctly.