View previous topic :: View next topic
|
Author |
Message |
Deepthy Jose P
New User
Joined: 07 Mar 2007 Posts: 40 Location: India
|
|
|
|
Hi All,
I have a match file requirement where my files can be in the below format
File 1
field1 field2
111 AAA
222 AAA
222 AAA
333 AAA
444 BBB
555 BBB
666 BBB
666 BBB
File 2
Field1 Field2
222 AAA
222 AAA
555 BBB
888 BBB
Many combinations of this files can exist
basically i should read all the records of file 1 with the same field1 and field2 combination and then process the file 2 records one by one which has the same combination
Processed until one of the file is read completely
Can any one help me with the algorithm for this requirement? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
At the top of this COBOL part of the forum is a "Sticky" with working code to do nearly what you want.
With only a little modification, you can do what you want using this (unless i misunderstand what you want to do). |
|
Back to top |
|
|
Deepthy Jose P
New User
Joined: 07 Mar 2007 Posts: 40 Location: India
|
|
|
|
Thanks Dick,
I read the sticky, but it seems to be a normal file compare, my requirement is a bit different as i have to read the same "key"(not a unique one but same field1 and field2 combinations) from file 1 and then from file2 find the same combination records one by one |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Suggest you more closely look at your requirement and the posted code. From what you have posted so far, the sample code should be able to get very close. . .
You need to explain why you believe the simple solution will not work for your case.
You (or someone) has arbitrarily made a "processing requirement" that may complicate the implementation. Why can the 2 "keys" not be concatenated and treated as one and then the files matched? |
|
Back to top |
|
|
Deepthy Jose P
New User
Joined: 07 Mar 2007 Posts: 40 Location: India
|
|
|
|
File 1 has another field which has some specific text values for which we have to analyse multiple fields values from file 2 (could be in any order) and then write the file 2 record as output if a match is found
Let me give an example
File 1
field1 field2 field 3
111 aaa text1
111 aaa text2
111 aaa text3
file 2
field1 field2 field 3 to field n
111 aaa records matching to text 3
111 aaa records matching to text 1
basically the files cannot be sorted to have it as a sequentiall search so we have to read all teh records from file 1 for 111 and aaa and set the flags for the text1 text 2 and text 3 and then read one by one record from file 2 and look for whether all the field values(field3 to field n) corresponds to any of the text 1 text2 or text 3 conditions |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Suggest you take a bit of time and post some "close to real" data and the output wanted from the sample data. Real-world data is easier for many to relate to than alphabet-soup and "textn" values. I also believe that your "file 2" looks like some kind of output rather than the second input.
When posting this new data, please use the "Code" tag to preserve alignment and improve readability. Use Preview to see your post as it will appear to the forum and Submit when the post appears as you want.
If i understand at all, there should be 3 files and there is no reason for anyone here to "figure it out". |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Deepthy Jose P,
1. you never reread files.
2. you always presort the files in the matching sequence.
3. learn to pose you questions with all the requriements.
stop trying to sandbag us with
'well there is another requirement which justifies my approach'
in a subsequent post.
4. if this is a school assignment to learn how to use COBOL Internal Tables,
say so,
because otherwise this is just a two file match merge,
no matter what 'big' words you misuse to describe you situation. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
As dbz says, pre-sort the files. If you need them back in the original order afterwards, add a sequence number. After your processing, sort on the sequence number and strip it off.
With duplicates on both files, I use what I call a "sideways" match. Look at what you have written, you already have it - as long as the files are sorted. |
|
Back to top |
|
|
|