View previous topic :: View next topic
|
Author |
Message |
mohan.andaluri
New User
Joined: 06 Mar 2009 Posts: 3 Location: Hyderabad
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi Mohan,
Hope you did well in the interview...
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 |
|
|
mohan.andaluri
New User
Joined: 06 Mar 2009 Posts: 3 Location: Hyderabad
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
If FileA has no duplicates and both the files are sorted (as your example shows), your answer is good enough. |
|
Back to top |
|
|
deepali33
New User
Joined: 21 Sep 2008 Posts: 4 Location: pune
|
|
|
|
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 |
|
|
mohan.andaluri
New User
Joined: 06 Mar 2009 Posts: 3 Location: Hyderabad
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|