IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

cobol program to compare two seq. files


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Rohit.sun123
Warnings : 1

New User


Joined: 01 Jun 2007
Posts: 1
Location: bangalore

PostPosted: Tue Feb 12, 2008 12:38 pm
Reply with quote

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
View user's profile Send private message
srinivas_443

New User


Joined: 19 Dec 2007
Posts: 11
Location: chennai

PostPosted: Tue Feb 12, 2008 12:57 pm
Reply with quote

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
View user's profile Send private message
ashwinreddy

Active User


Joined: 16 Sep 2004
Posts: 106
Location: Hyderabad

PostPosted: Tue Feb 12, 2008 3:42 pm
Reply with quote

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
View user's profile Send private message
srinivas_443

New User


Joined: 19 Dec 2007
Posts: 11
Location: chennai

PostPosted: Tue Feb 12, 2008 4:38 pm
Reply with quote

Hi Ashwin

Good idea.Thanks
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue Feb 12, 2008 7:01 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Feb 12, 2008 10:11 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Using API Gateway from CICS program CICS 0
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top