Presentation is loading. Please wait.

Presentation is loading. Please wait.

Two file sequential file processing (maximum 1 record per id on each file) Please use speaker notes for additional information!

Similar presentations


Presentation on theme: "Two file sequential file processing (maximum 1 record per id on each file) Please use speaker notes for additional information!"— Presentation transcript:

1 Two file sequential file processing (maximum 1 record per id on each file) Please use speaker notes for additional information!

2 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

3 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 111100

4 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 111100 111010 Merge 2 files

5 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 111100 111010 222200 Merge 2 files

6 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 111100 111010 222200 222020 Merge 2 files

7 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 111100 111010 222200 222020 300030 Merge 2 files

8 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 111100 111010 222200 222020 300030 333300 Merge 2 files

9 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 111100 111010 222200 222020 300030 333300 333000 Merge 2 files

10 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 111100 111010 222200 222020 300030 333300 333000 444400 Merge 2 files

11 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 111100 111010 222200 222020 300030 333300 333000 444400 444040 Merge 2 files

12 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 111100 111010 222200 222020 300030 333300 333000 444400 444040 555500 Merge 2 files

13 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 111100 111010 222200 222020 300030 333300 333000 444400 444040 555500 666000 Merge 2 files

14 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 111100 111010 222200 222020 300030 333300 333000 444400 444040 555500 666000 666060 Merge 2 files

15 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 111100 111010 222200 222020 300030 333300 333000 444400 444040 555500 666000 666060 777070 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.

16 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 111100 111010 222200 222020 300030 333300 333000 444400 444040 555500 666000 666060 777070 888800 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.

17 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.

18 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 =

19 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 111110

20 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 111110 222220

21 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 111110 222220 300030

22 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 111110 222220 300030 333300

23 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 111110 222220 300030 333300 444440

24 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 111110 222220 300030 333300 444440 555500

25 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 111110 222220 300030 333300 444440 555500 666600

26 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 111110 222220 300030 333300 444440 555500 666600 777070 I am going to set the id from file2 to 999 so it will compare high when there is still data on file1.

27 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 111110 222220 300030 333300 444440 555500 666600 777070 888800 I am going to set the id from file2 to 999 so it will compare high when there is still data on file1.

28 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

29 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 111110

30 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 111110 222220

31 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 111110 222220 300 030 MISSING RECORD FROM FILE 1

32 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 111110 222220 333300 300 030 MISSING RECORD FROM FILE 1

33 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 111110 222220 333300 444440 300 030 MISSING RECORD FROM FILE 1

34 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 111110 222220 333300 444440 300 030 MISSING RECORD FROM FILE 1 555 500 MISSING RECORD FROM FILE 2

35 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 111110 222220 333300 444440 666600 300 030 MISSING RECORD FROM FILE 1 555 500 MISSING RECORD FROM FILE 2

36 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 111110 222220 333300 444440 666600 300 030 MISSING RECORD FROM FILE 1 555 500 MISSING RECORD FROM FILE 2 777 070 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.

37 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 111110 222220 333300 444440 666600 300 030 MISSING RECORD FROM FILE 1 555 500 MISSING RECORD FROM FILE 2 777 070 MISSING RECORD FROM FILE 1 888 800 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.


Download ppt "Two file sequential file processing (maximum 1 record per id on each file) Please use speaker notes for additional information!"

Similar presentations


Ads by Google