Page 1 of 1

File Operation (Asked in IBM)

PostPosted: Wed Sep 29, 2010 8:12 pm
by rakaitn
There are two huge files, let's say FILEA and FILEB.

Objective is:

1) Read FILEA first and if the same record is found in FILEB, write it into FILE01 and if not found write it into FILE02. This process has to continue till the end-of-file of FILEA.

2) Once FILEA completely read, then write a line full of ' ***** ' in FILE01 as well as FILE02

3) Then start reading FILEB and find the record in FILEA. If found write into FILE01, not found write into FILE02. Continue till end-of-file of FILEB.

Interviewer asked me to write a cobol code (just structure) to achieve the above - I have written the lengthy approach first -
Sort FILEA, FILEB
Read FILEA, Find in FILEB
Write to FILE01/FILE02.

He agreed that it will give appropriate result but would be very inefficient taking long time as records may be millions.

Kindly suggest how to achieve the above efficiently. (using JCL and COBOL only).

Re: File Operation (Asked in IBM)

PostPosted: Thu Sep 30, 2010 12:59 am
by dick scherrer
Hello,

At/near the top of the COBOL part of the forum is a "Sticky" of working code that will do a 2-file match/merge (which is what you want if i understand the question).

Once both files are sorted, this code will do what you want in one pass of the files comparing them as it goes.

Re: File Operation (Asked in IBM)

PostPosted: Thu Sep 30, 2010 10:17 am
by rakaitn
Hi,

Extremely sorry, I didn't get what you were trying to state.

Could you please elaborate a bit.

Re: File Operation (Asked in IBM)

PostPosted: Thu Sep 30, 2010 10:46 pm
by NicC
Dick is trying to state that there is sample, working, code in the COBOL part of the forum. It is about the first or second topic in that section. It is called a 'sticky' because it sticks in that place because new topics are placed after all stickies. Take a look and you will see.

Re: File Operation (Asked in IBM)

PostPosted: Fri Oct 01, 2010 1:41 am
by dick scherrer
Hello,

Click on "Board index" near the top left of the screen.

Then click on IBM Cobol.

Then click on the 2-file match/merge "sticky".