Two file sequential file processing (maximum 1 record per id on each file) Please use speaker notes for additional information!
ID1>ID2 Merge 2 files Prepare record from file 2 to write Write output record Read file2 record Prepare record from file 1 to write Write output record Read file1 record Reading two files and creating a single merged output file with all records from file 1 and file2. Two ways of drawing the flowchart are shown. ID1: ID2 Prepare record from file 2 to write Write output record Read file2 record Prepare record from file 1 to write Write output record Read file1 record ><=YN
Merge 2 files Read record from each file prior to the logic shown. ID1 (111) is not greater than ID2 (111). They are equal. The logic says to prepare record from file1 (111100) to write and write it. Then read another record from file1. File12.dat
ID1 (222) is greater than ID2 (111). The logic says to prepare record from file2 (111010) to write, write it Then read another record from file2. File12.dat Merge 2 files
ID1(222) is not greater than ID2 (222), in fact they are equal. The logic says to prepare record from file1 to write and write it. Then read another record from file1. File12.dat Merge 2 files
ID1(333) is greater than ID2 (222). The logic says to prepare record from file2 to write and write it. Then read another record from file2. File12.dat Merge 2 files
ID1(333) is greater than ID2 (300). The logic says to prepare record from file2 to write and write it. Then read another record from file2. File12.dat Merge 2 files
ID1 (333) is not greater than ID2 (333), in fact they are equal. The logic says to prepare record from file1 to write and write it. Then read another record from file1. File12.dat Merge 2 files
ID1 (444) is greater than ID2 (333). The logic says to prepare record from file2 to write and write it. Then read another record from file2. File12.dat Merge 2 files
ID1 (444) is not greater than ID2 (444), in fact they are equal. The logic says to prepare record from file1 to write and write it. Then read another record from file1. File12.dat Merge 2 files
ID1 (555) is greater than ID2 (444). The logic says to prepare record from file2 to write and write it. Then read another record from file2. File12.dat Merge 2 files
ID1 (555) is not greater than ID2 (666). The logic says to prepare record from file1 to write and write it. Then read another record from file1. File12.dat Merge 2 files
ID1 (666) is not greater than ID2 (666), in fact they are equal. The logic says to prepare record from file1 to write and write it. Then read another record from file1. File12.dat Merge 2 files
ID1 (888) is greater than ID2 (666). The logic says to prepare record from file2 to write and write it. Then read another record from file2. File12.dat Merge 2 files
ID1 (888) is greater than ID2 (777). The logic says to prepare record from file2 to write and write it. Then read another record from file2. End of file has been reached. File12.dat Merge 2 files I am going to set the id from file2 to 999 so it will compare high when there is still data on file1.
ID1 (888) is not greater than EOF where I set ID2 (999). The logic says to prepare record from file1 to write and write it. Then read another record from file1. End of file has been reached. File12.dat Merge 2 files I am going to set the id from file1 to 999 so it will compare high when there is still data on file2.
On file 1 or 2 or both ID1 > ID2 Prepare record from file 2 to write Write output record Read file2 record Prepare record from file 1 to write Write output record Read file1 record YN ID1 = ID2 Prepare record from file 1 & file 2 to write Write output record Read file1 record YN Read file2 record File 1 and file 2 have a maximum of 1 record per id. However the same id can appear on both files.
ID1 : ID2 Prepare record from file 2 to write Write output record Read file2 record Prepare record from file 1 to write Write output record Read file1 record >< Prepare record from file 1 & file 2 to write Write output record Read file1 record Read file2 record On file 1 or 2 or both - alternative =
On file 1 or 2 or both ID1 (111) is equal to ID2 (111). In this example, I will then add the amounts in amt from file1 (100) and amt from file2 (010) and write a new record containing id 111 and the total 110. I will then read a new record from both file 1 and file 2. File12ok.dat
On file 1 or 2 or both ID1 (222) is equal to ID2 (222). In this example, I will then add the amounts in amt from file1 (200) and amt from file2 (020) and write a new record containing id 222 and the total 220. I will then read a new record from both file 1 and file 2. File12ok.dat
On file 1 or 2 or both ID1 (333) is greater than ID2 (300). In this example, I will then move the id and the amt from the record on file2 and write a new record containing id 300 and the total 030. I will then read a new record from file 2. File12ok.dat
On file 1 or 2 or both ID1 (333) is equal to ID2 (333). In this example, I will then add the amounts in amt from file1 (300) and amt from file2 (000) and write a new record containing id 333 and the total 300. I will then read a new record from file1 and a new record from file 2. File12ok.dat
On file 1 or 2 or both ID1 (444) is equal to ID2 (444). In this example, I will then add the amounts in amt from file1 (400) and amt from file2 (040) and write a new record containing id 444 and the total 440. I will then read a new record from file1 and a new record from file 2. File12ok.dat
On file 1 or 2 or both ID1 (555) is less than ID2 (666). In this example, I will then move the id and the amt from the record on file1 and write a new record containing id 555 and the total 500. I will then read a new record from file1. File12ok.dat
On file 1 or 2 or both ID1 (666) is equal to ID2 (666). In this example, I will then add the amounts in amt from file1 (600) and amt from file2 (060) and write a new record containing id 666 and the total 660. I will then read a new record from file1 and a new record from file 2. File12ok.dat
On file 1 or 2 or both ID1 (888) is greater than ID2 (777). In this example, I will then move the id and the amt from the record on file2 and write a new record containing id 777 and the total 070. I will then read a new record from file1. There is no new record so EOF has been reached. File12ok.dat I am going to set the id from file2 to 999 so it will compare high when there is still data on file1.
On file 1 or 2 or both ID1 (888) is less than ID2 (999) which has been set that way because EOF was reached on file2.. In this example, I will then move the id and the amt from the record on file1 and write a new record containing id 888 and the total 800. I will then read a new record from file1. There is no new record so EOF has been reached. File12ok.dat I am going to set the id from file2 to 999 so it will compare high when there is still data on file1.
Required matching record ID1 > ID2 Set up missing record from file 1 error Write or display error Read file2 record Set up missing record from file2 error Write or display error Read file1 record YN ID1 = ID2 Prepare record from file 1 & file 2 to write Write output record Read file1 record YN Read file2 record
Must be on 1 and 2 ID1 (111) is equal to ID2 (111). In this example, I will then add the amounts in amt from file1 (100) and amt from file2 (010) and write a new record containing id 111 and the total 110. I will then read a new record from both file 1 and file 2. File12cb.dat
Must be on 1 and 2 ID1 (222) is equal to ID2 (222). In this example, I will then add the amounts in amt from file1 (200) and amt from file2 (020) and write a new record containing id 222 and the total 220. I will then read a new record from both file 1 and file 2. File12cb.dat
Must be on 1 and 2 ID1 (333) is greater than ID2 (300). In this example, I will then write the record from file 2 on the error report. I will then read a new record from file 2. File12cb.dat MISSING RECORD FROM FILE 1
Must be on 1 and 2 ID1 (333) is equal to ID2 (333). In this example, I will then add the amounts in amt from file1 (300) and amt from file2 (000) and write a new record containing id 333 and the total 300. I will then read a new record from file1 and a new record from file 2. File12cb.dat MISSING RECORD FROM FILE 1
Must be on 1 and 2 ID1 (444) is equal to ID2 (444). In this example, I will then add the amounts in amt from file1 (400) and amt from file2 (040) and write a new record containing id 444 and the total 440. I will then read a new record from file1 and a new record from file 2. File12cb.dat MISSING RECORD FROM FILE 1
Must be on 1 and 2 ID1 (555) is less than ID2 (666). In this example, I will then write the record from file 1 on the error report. I will then read a new record from file 1. File12cb.dat MISSING RECORD FROM FILE MISSING RECORD FROM FILE 2
Must be on 1 and 2 ID1 (666) is equal to ID2 (666). In this example, I will then add the amounts in amt from file1 (600) and amt from file2 (060) and write a new record containing id 666 and the total 660. I will then read a new record from file1 and a new record from file 2. File12cb.dat MISSING RECORD FROM FILE MISSING RECORD FROM FILE 2
Must be on 1 and 2 ID1 (888) is greater than ID2 (777). In this example, I will then write the record from file 2 on the error report. I will then read a new record from file 2. File12cb.dat MISSING RECORD FROM FILE MISSING RECORD FROM FILE MISSING RECORD FROM FILE 2 When I attempt to read from file 2, EOF is reached. I will then set the id to 999 for comparison.
Must be on 1 and 2 ID1 (888) is less than ID2 (999 for EOF). In this example, I will then write the record from file 1 on the error report. I will then read a new record from file 1. File12cb.dat MISSING RECORD FROM FILE MISSING RECORD FROM FILE MISSING RECORD FROM FILE MISSING RECORD FROM FILE 2 When I attempt to read from file 1, EOF is reached. Since both files have reached EOF, processing is over.