View previous topic :: View next topic
|
Author |
Message |
Rohit.sun123 Warnings : 1 New User
Joined: 01 Jun 2007 Posts: 1 Location: bangalore
|
|
|
|
There are 2 sequential files with records. Now we have to check for the matching records in both the files and put matched reords in a output file and unmatched records in a second output file. |
|
Back to top |
|
|
srinivas_443
New User
Joined: 19 Dec 2007 Posts: 11 Location: chennai
|
|
|
|
Using cobol program we can do.
First open 2 file
Read file1(first rec)
Move record to WS-area1
Read file 2(first rec)
Move record to WS-area2
If WS-area1=WS-area2
Write to match-rec-file
Else
Write to diff-rec-file
This is my thought
Correct me if I am wrong
Regards,
Srinivas Jala |
|
Back to top |
|
|
ashwinreddy
Active User
Joined: 16 Sep 2004 Posts: 106 Location: Hyderabad
|
|
|
|
Hi Srinivas,
The above solution holds good for after sorting both the files with equal number of records in both the files.
Let me give you an example
file 1 file 2
1 3
2 1
3 4
If the files are in above format, then you may miss some records (almost all).
Slight modification in Srinivas logic
First open 2 file
Read file1(first rec)
Move record to WS-area1
Read file 2(first rec)
Move record to WS-area2
If WS-area1=WS-area2
Write to match-rec-file
Else
Perform the 2nd file read until match found with the first file
If match found
Write to match-rec-file
Else
Write to diff-rec-file
End-if
End-if
I can see some redundant code in above logic, but i think tat will be corrected by prasad
Please correct me if i am wrong.
Cheers
Ashwin |
|
Back to top |
|
|
srinivas_443
New User
Joined: 19 Dec 2007 Posts: 11 Location: chennai
|
|
|
|
Hi Ashwin
Good idea.Thanks |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi,
Well, for such a file matching Logic, don't You think.. both the files should be in sorted order (ofcourse on the same key). BTW, this topic has been discussed many times, please search.
There is a sticky in Mainframe COBOL Forum by Dick for a file matching program. Use that to give You a start & change the code as per Your needs..here is the link. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
This is my thought
Correct me if I am wrong |
Yes, the posted code will not work.
Quote: |
The above solution holds good for after sorting both the files with equal number of records in both the files. |
Even if the files are sorted and have the same number of records, the compare will not work correctly.
Quote: |
There is a sticky in Mainframe COBOL Forum by Dick for a file matching program |
As suggested by Anuj, i'd recommend reviewing the code at the "sticky" and post any questions about it here. We can clarify any doubts. |
|
Back to top |
|
|
|