Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

cobol program to compare two seq. files

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
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    Post subject: cobol program to compare two seq. files
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    Post subject: Reply to: cobol program to compare two seq. files( five lakh
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    Post subject:
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    Post subject:
Reply with quote

Hi Ashwin

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

Senior Member


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

PostPosted: Tue Feb 12, 2008 7:01 pm    Post subject:
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

Site Director


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

PostPosted: Tue Feb 12, 2008 10:11 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts member list compare jzhardy TSO/ISPF 6 Fri May 12, 2017 3:18 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us