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

Comparing two files using cobol program


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
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
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

Superior Member


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

PostPosted: Mon Sep 07, 2009 1:09 pm
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
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

Superior Member


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

PostPosted: Mon Sep 07, 2009 8:22 pm
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
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
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

Moderator Emeritus


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

PostPosted: Tue Sep 08, 2009 7:46 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
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
Search our Forums:

Back to Top