Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Comparing two files using cobol program

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
mohan.andaluri

New User


Joined: 06 Mar 2009
Posts: 3
Location: Hyderabad

PostPosted: Mon Sep 07, 2009 12:48 pm    Post subject: Comparing two files using cobol program
Reply with quote

Hi!

i have been asked a question in my recent interview, please let me know the answer to this question.

i have a two files lets say FILEA, FILEB

FILEA FILEB

1 2
2 5
3 5
5 6
6 7
8 8
9 9
10 9
13 9
18 18
20 22

now my requirement is matched records should be write in FILE3 with out duplecates.

so answer should be

FILE3

2
5
6
8
9
18

this task i have do using only cobol program, without any JCL sorts.
So Please tell me the logic.

Regards,
Murali Mohan
Back to top
View user's profile Send private message

Anuj Dhawan

Senior Member


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

PostPosted: Mon Sep 07, 2009 1:09 pm    Post subject:
Reply with quote

Hi Mohan,

Hope you did well in the interview... icon_smile.gif

Here in these forums for interview questions, we usually encourage the topic starter to tell his answer first and then we take it from there to provide any suggestion/s (if required).

However, for the question you posted -- we've a sample sticky in the "Mainframe COBOL" part of the Forum. You can refer that, in case you were not satisfied with your answer there in the interview. After going thorugh the sticky, if you still find some queries, ask away.

Good Luck.
Back to top
View user's profile Send private message
mohan.andaluri

New User


Joined: 06 Mar 2009
Posts: 3
Location: Hyderabad

PostPosted: Mon Sep 07, 2009 7:34 pm    Post subject: Reply to: Comparing two files using cobol program
Reply with quote

Hi Anuj,

i have given this answer....

If FILEA > FILEB

Read FILEB

If FILEA < FILEB

Read FILEA

If FILEA = FILEB

Write FILEC

i guess this code wont eleminate duplicates. So Please let me know where should i change the code to eleminate duplicates.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


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

PostPosted: Mon Sep 07, 2009 8:22 pm    Post subject:
Reply with quote

If FileA has no duplicates and both the files are sorted (as your example shows), your answer is good enough.
Back to top
View user's profile Send private message
deepali33

New User


Joined: 21 Sep 2008
Posts: 4
Location: pune

PostPosted: Tue Sep 08, 2009 11:31 am    Post subject: Reply to: Comparing two files using cobol program
Reply with quote

Hi Anuj,

I think following are the steps to do it.

1. FILEA & FILEB should be sorted before it process.
2. perform loop for FILEA until EOF
read FILEA
perform loop for FILEB until EOF
read FILEB
compare FILEA = FILEB
if it matches then write it into FILEC, but before writing
it check that the value is not present in FILEC.
Back to top
View user's profile Send private message
mohan.andaluri

New User


Joined: 06 Mar 2009
Posts: 3
Location: Hyderabad

PostPosted: Tue Sep 08, 2009 12:07 pm    Post subject:
Reply with quote

Hi Anuj,

What will be the change if FILEA has duplicates.
in my interview she said your code gives duplicates, how can i eleminate the duplicates.
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 Sep 08, 2009 7:46 pm    Post subject:
Reply with quote

Hello,

Near the top of the COBOL part of the forum is a "Sticky" that is working 2-file match/merge code. It will handle (as is) duplicate keys in either file (but not both - many to many requires additional consideration). The code in the "sticky" is more comprehensive that a couple of simple compares - it will work all of the time and is not data dependent.

Suggest you review that code for a better understanding.

If you become comfortable with the method used in the sticky, you will have match/merge code that will work for longer than you will probably be coding (that particular bit of code is over 40 years old and has been implemented successfully thousands of times across hundreds of systems).
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 The same REXX program doesnt work for... jackzhang75 CLIST & REXX 5 Wed Dec 06, 2017 2:51 am
No new posts Compare VSAM files using DFSORT pshongal DFSORT/ICETOOL 5 Thu Nov 23, 2017 10:24 am
No new posts Comparing dates in different formats migusd SYNCSORT 4 Sat Nov 18, 2017 3:02 am
This topic is locked: you cannot edit posts or make replies. Cobol to fetch the content by using s... arunc55 COBOL Programming 4 Fri Nov 17, 2017 1:25 pm
No new posts Calling IKJEFT01 program from Rexx upendrasri CLIST & REXX 8 Wed Nov 15, 2017 4:27 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us