Download presentation
Presentation is loading. Please wait.
Published byИнна Яблочкова Modified over 5 years ago
1
2 file sequential matching with multiple records allowed on file 2
Please use speaker notes for additional information! More information on processing 2 files sequentially. In this example, file 1 has 1 record per id and file 2 has multiple records per id some of which will have multiple records per id.
2
File 1 (1 record/id) File 2 (multiple/id)
ID1 > ID2 N Y ID1 = ID2 Error with info from rec2 including missing record from file 1 message N Y Move id to output Add amt2 to total accum Print error Add amt to total accum and move to output Read file2 record Read file2 record Write output record Prior to processing this logic, the first record is read from each file. Processing is continued until EOF is reached on both files. The logic being shown in this example is: there must be a record on file 1 there can be multiple records on file 2 Read file1 record 0 to total accum
3
File 1 (1 record/id) File 2 (multiple/id) ID1 = ID2 Y
Add amt2 to total accum TOT-ACCUM 001 Read file2 record ID1 (111) is equal to ID2 (111). In this example, I will add amt from file2 (001) to the total accumulator which is now 001. I will then read a new record from file 2. The first record from file1 and file 2 both have id of The amt from the record on file2 is added to the total accumulator (TOT-ACCUM). Then a new record is read from file 2. File121M.dat
4
File 1 (1 record/id) File 2 (multiple/id)
ID1 = ID2 Y Add amt2 to total accum TOT-ACCUM 001 011 Read file2 record ID1 (111) is equal to ID2 (111). In this example, I will add amt from file2 (010) to the total accumulator which is now 011. I will then read a new record from file 2. The second record with the id of 111 in the file2 has its amount added to the accumulator and then another record is read from file2. File121M.dat
5
File 1 (1 record/id) File 2 (multiple/id) ID1 = ID2 N
Move id to output TOT-ACCUM 001 011 111 Add amt to total accum and move to output Write output record Read file1 record ID1 (111) is less to ID2 (222) which means that we have switched to a new id in file 2. The logic sets up the record and adds the amt from file 1 to the accumulator prior to writing. I will then read a new record from file 1 and set the accumulator to 0. 0 to total accum The record is written when all records with id of 111 from both files have been processed and the total from these records has been accumulated. The total includes the 01 and the 10 from file 2 and the 100 from file1. The total of = 111. Note that after the record is written and a new record is read from file 1, the accumulator is set to 0. File121M.dat 111111 TOT-ACCUM
6
File 1 (1 record/id) File 2 (multiple/id)
ID1 = ID2 Y Add amt2 to total accum TOT-ACCUM 22 Read file2 record ID1 (222) is equal to ID2 (222) so I am now going to process the record from file2 by adding it to the accumulator. I will then read a new record from file 2. The ids on the two files match, so I process by adding the amt to the total accumulator and then I read a record from file 2. Remember the accumulator was set to zero after the record was written. File121M.dat 111111
7
File 1 (1 record/id) File 2 (multiple/id)
ID1 = ID2 Y Add amt2 to total accum TOT-ACCUM 22 244 Read file2 record ID1 (222) is equal to ID2 (222) so I am now going to process the record from file2 by adding it to the accumulator. I will then read a new record from file 2. I add 222 to the 22 that is already in the accumulator to get 244. I then read another record from file 2. The record I read has an id of 300 so the next comparison will be between 222 on file 1 and 300 on file 2. File121M.dat 111111
8
File 1 (1 record/id) File 2 (multiple/id) ID1 = ID2 N
Move id to output TOT-ACCUM 22 244 444 Add amt to total accum and move to output Write output record Read file1 record ID1 (222) is less than ID2 (300) which means that we have switched to a new id in file 2. The logic sets up the record and adds the amt from file 1 to the accumulator prior to writing. I will then read a new record from file 1 and set the accumulator to 0. File121M.dat 111111 222444 0 to total accum Since ID1 (222) is less that ID2 (300) I know that all of the records with id of 222 have been processed from file 2. Therefore, it is time to add the amount from file 1 to the accumulator giving me a total of 444 and then write the record to the output file. I then read another record from file 1 and set the accumulator to 0. The next comparison will be between ID1 (333) and ID2 (300). TOT-ACCUM
9
File 1 (1 record/id) File 2 (multiple/id) ID1 > ID2 Y
Error with info from rec2 including missing record from file 1 message TOT-ACCUM Print error Read file2 record ID1 (333) is greater than ID2 (300) which means that we have an error because there must be a record on file 1. The unmatched record on file 2 is handled as an error and written to the printer. I will then read a new record from file 2. Error Report In this processing, we said that there had to be a record on file 1. Since there is no ID1 (300) then the ID2 (300) on file 2 is invalid and is handled as an error. At that point another record will be read from file 2. File121M.dat 111111 222444
10
File 1 (1 record/id) File 2 (multiple/id) ID1 = ID2 N
Move id to output Add amt to total accum and move to output TOT-ACCUM 300 Write output record Read file1 record ID1 (333) is less than ID2 (444) which that there are no matching records to on file 2. First I will add to the accumulator and then I will then write the record with id 333 on the disk since this is legitimate. I will then read a new record from file 1 and zero out the accumulator. Error Report 0 to total accum This is an example of a record from file 1 with no matching records on file 2. This could be an example of a master file (file 1) with no activity (file 2). File121M.dat 111111 222444 333300 TOT-ACCUM
11
File 1 (1 record/id) File 2 (multiple/id)
ID1 = ID2 Y Add amt2 to total accum TOT-ACCUM 004 Read file2 record ID1 (444) is equal to ID2 (444) which that there is a match and we will process the record from file 2 by adding the amount to the accumulator. I will then read a new record from file 2. File121M.dat 111111 222444 333300 Error Report When file 1 and file 2 match it can be seen as having activity in file 2 that applies to the single record in file 1. I need to process all of the matching activity records in file 2 so I will continue reading file 2 until there is a change in id.
12
File 1 (1 record/id) File 2 (multiple/id)
ID1 = ID2 Y Add amt2 to total accum TOT-ACCUM 004 044 Read file2 record ID1 (444) is equal to ID2 (444) which that there is a match and we will process the record from file 2 by adding the amount to the accumulator. I will then read a new record from file 2. File121M.dat 111111 222444 333300 Error Report This is the second record from file 2 that matches to the id of 444 in file 1. The amount is added to the accumulator and the next record is read. The next comparison will also be between matching records with id 444.
13
File 1 (1 record/id) File 2 (multiple/id)
ID1 = ID2 Y Add amt2 to total accum TOT-ACCUM 004 044 488 Read file2 record ID1 (444) is equal to ID2 (444) which that there is a match and we will process the record from file 2 by adding the amount to the accumulator. I will then read a new record from file 2. File121M.dat 111111 222444 333300 Error Report Again I have a match so I am processing the third record with id of The next record read from file 2 will be 555 so the next comparison is between 444 on file 1 and 555 on file 2. This will signal that we have finished all of the activity from file 2 for 444 so the record on file 1 will be dealt with and then the record will be written to the disk.
14
File 1 (1 record/id) File 2 (multiple/id) ID1 = ID2 N
Move id to output Add amt to total accum and move to output TOT-ACCUM 004 044 488 888 Write output record Read file1 record ID1 (444) is less than ID2 (555) which means it is time to finish process 444 by handling the record from file 1. The amount is added to the accumulator and the record is written. I will then read a new record from file 1 and then zero out the accumulator.. Error Report 0 to total accum The record for 444 is now written and the next processing will be for 555 in both files. File121M.dat 111111 222444 333300 444888 TOT-ACCUM
15
File 1 (1 record/id) File 2 (multiple/id)
ID1 = ID2 Y Add amt2 to total accum TOT-ACCUM 006 Read file2 record ID1 (555) is equal to ID2 (555) which means that we add the 006 which is the amount on record 555 to the accumulator. I will then read a new record from file 2. Error Report This is another equal to and as the flowchart segment says we need to add the contents of amt to the accumulator making it 006 and then read another record from file2 since the record on file2 was the one that got processed. File121M.dat 111111 222444 333300 444888
16
File 1 (1 record/id) File 2 (multiple/id) ID1 = ID2 N
Move id to output Add amt to total accum and move to output TOT-ACCUM 006 506 Write output record Read file1 record ID1 (555) is less than to ID2 (666) so I add the amount from file 1 to the accumulator and then write the output record. I will then read a new record from file 1 and 0 out the accumulator. Error Report 0 to total accum I now have the id on file 1 less than the id on file 2 so I know that I have processed all of the records on file 2 with that id. That means that it is time to complete the processing of that id by adding the amount from file 1 to the accumulator and writing the record on the output file. Then I read a new record from file 1 to give myself the base to compare against and 0 out the accumulator. Note that because there is only 1 record per id from file 1 and that I cannot have a record from file 2 that does not match the record in file 1, the id in file 1 because the base which I compare against. File121M.dat 111111 222444 333300 444888 555506 TOT-ACCUM
17
File 1 (1 record/id) File 2 (multiple/id)
ID1 = ID2 Y Add amt2 to total accum TOT-ACCUM 006 Read file2 record ID1 (666) is equal to ID2 (666) add the amt on file 2 to the accumulator, I will then read a new record from file 2. Error Report Again, I have equal records on the two files so I am simply adding to the accumulator and reading another record from the file that can have multiple records per id. File121M.dat 111111 222444 333300 444888 555506
18
File 1 (1 record/id) File 2 (multiple/id)
ID1 = ID2 Y Add amt2 to total accum TOT-ACCUM 006 066 Read file2 record ID1 (666) is equal to ID2 (666) add the amt on file 2 to the accumulator, I will then read a new record from file 2. Error Report This is processing where there is a match between the two files. Therefore we are simply accumulating the data from file 2 and then since file 2 has been processed, reading another record from file 2. In sequential processing, you always read from the file where you have just processed a record. File121M.dat 111111 222444 333300 444888 555506
19
File 1 (1 record/id) File 2 (multiple/id) ID1 = ID2 N
Move id to output Add amt to total accum and move to output TOT-ACCUM 006 066 666 Write output record Read file1 record ID1 (666) is less than to ID2 (777) so I add the amount from file 1 to the accumulator and then write the output record. I will then read a new record from file 1 and 0 out the accumulator. Error Report error msg 0 to total accum Since 666 was less than 777, I know that I have processed all of the records from file 2 with an id of That means it is time to add the amount on the 666 record from file 1 to the accumulator and write the record. Now I have processed the record on file 1 so it is time to read a new record from file 1. I am starting a new group so it is also time to zero out the accumulator. File121M.dat 111111 222444 333300 444888 555506 666666 TOT-ACCUM
20
File 1 (1 record/id) File 2 (multiple/id) ID1 > ID2 Y
Error with info from rec2 including missing record from file 1 message TOT-ACCUM Print error Read file2 record ID1 (888) is greater than ID2 (777) which means that we have an error because there must be a record on file 1. The unmatched record on file 2 is handled as an error and written to the printer. I will then read a new record from file 2. Since there are no more records on file 2 end of file processing will be handled. I am going to make the id high so the comparison with file 1 will make file 1 low. Error Report error msg error msg You can handle eof by moving 999 or high values to the id so file 1 will always compare low or you can code special processing to handle the situation where you reach eof on file 1 first and special processing to handle the situation where you reach eof on file 2 first etc. File121M.dat 111111 222444 333300 444888 555506 666666
21
File 1 (1 record/id) File 2 (multiple/id) ID1 = ID2 N
Move id to output Add amt to total accum and move to output Write output record TOT-ACCUM 800 Read file1 record 999 for EOF Error Report error msg error msg ID1 (888) is less than ID2 (999) which I moved to the file 2 id because EOF was reached. I now want to process record First I will add to the accumulator and then I will then write the record with id 888 on the disk since this is legitimate. I will then attempt to read a new record from file 1 and zero out the accumulator. 0 to total accum EOF has now been reached on both files and since the loop was performed until eof on both files was reached, processing will stop. File121M.dat 111111 222444 333300 444888 555506 666666 888800 TOT-ACCUM
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.