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
 

 

Creating 3 files

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

Active User


Joined: 21 Mar 2007
Posts: 203
Location: India

PostPosted: Tue Sep 16, 2008 3:40 pm    Post subject: Creating 3 files
Reply with quote

Hi,

We have two files say A and B. They contains some records in them. Let us assume the details in the two files as
FILE A:
1
2
3
4
5

FILE B:
1
3
5
7
9


Now we are required to created 3 files X,Y and Z.

The File X should contain all the datas that are common to File A & B, while File Y should contain all the data that are present in A but not in B and File Z should contain all the data that are present in B but not in A i.e. the desired output for the three files are as under:

FILE X
1
3
5

FILE Y
2
4

FILE Z
7
9

How can we achieve the same using a COBOL program?

I thought of the logic to read the file A and then compare it with File B. If the records are found, then write the same to File X and if not found, write the same in File Y.

But how can we get File Z?

Its a bad idea to read file B and compare it with File A and then write the same into File Z.
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10256
Location: italy

PostPosted: Tue Sep 16, 2008 3:43 pm    Post subject: Reply to: Creating 3 files
Reply with quote

please do not double post
Your other post with the same subject will be deleted
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10256
Location: italy

PostPosted: Tue Sep 16, 2008 3:47 pm    Post subject: Reply to: Creating 3 files
Reply with quote

just a hint....
the input files should be sorted on the field used for matching

if key1 = key2 ..... write file x read file1 and file2

if key1 < key2 ..... write file y read file1

if key1 > key2 ..... write file z read file2
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Sep 16, 2008 3:50 pm    Post subject:
Reply with quote

Store the records in an array while writing file X. Compare file B with this array. If the records are not found, then write to file Z.
Back to top
View user's profile Send private message
swapnadeep.ganguly

Active User


Joined: 21 Mar 2007
Posts: 203
Location: India

PostPosted: Tue Sep 16, 2008 4:01 pm    Post subject:
Reply with quote

Thanks Enrico and Bharath for your prompt reply....
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Sep 16, 2008 4:03 pm    Post subject:
Reply with quote

Does that mean you are satisfied with the answer? Or do you have something else on your mind?
Back to top
View user's profile Send private message
swapnadeep.ganguly

Active User


Joined: 21 Mar 2007
Posts: 203
Location: India

PostPosted: Tue Sep 16, 2008 4:06 pm    Post subject:
Reply with quote

No, I am satisfied with your answer.
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Tue Sep 16, 2008 4:06 pm    Post subject:
Reply with quote

Hi,

You can do in this way

First SORT FILE A and FILE B in ASCENDING ORDER (I Assume that there will unique field-about which you should sort).

Then

1. Read Record from FILE A.
2. Read Record from FILE B.
3. Put it in loop FILE A Read until End of file
4. Compare fields like

Code:
     >  If FIELD A = FIELD B
              write FILE A and FILE B records into FILE X
              read FILE A
              read FILE B   
         ELSE
             IF FIELD A > FIELD B
                  write FILE A records into FILE Y
                  read FILE A
             ELSE
                  write FILE B records into FILE Z
                  read FILE B
             END-IF
         END-IF   


5. Once End of File is reached, Close it.

Hope you clear
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Sep 16, 2008 4:24 pm    Post subject: Re: Creating 3 files
Reply with quote

swapnadeep.ganguly wrote:
How can we achieve the same using a COBOL program?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Tue Sep 16, 2008 4:57 pm    Post subject:
Reply with quote

I suppose that you could always ask the interviewer why COBOL should be used when either main sort product could easily accomplish this task.
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 16, 2008 9:45 pm    Post subject:
Reply with quote

Hello,

revel - the logic posted is incomplete and will fail.

Quote:
I suppose that you could always ask the interviewer why COBOL should be used when either main sort product could easily accomplish this task.
In more than 99% of the cases where 2 files are matched, there is more to the code than simply "matching the files". There is nearly always other business logic (internal array processing, vsam access, database access, etc) which makes cobol a better choice than using the sort. I've seen implementations that someone who did not know how to code a simple 2-file match used 4 or more steps (and several full passes of the data) to accomplish what one fairly simple cobol program could do. The only reason i was asked to look at these processes was that they took "too long" to run. If you only have a few thousand records, i guess multiple steps/passes is ok, but much of what my clients work with are hundreds of millions of records. The testing (little bits of data) goes quite well and when full-volume testing is attempted it grinds to a halt.

Quote:
Store the records in an array while writing file X. Compare file B with this array. If the records are not found, then write to file Z.
This should not be done. A programmer should learn to write proper code.

swapnadeep.ganguly - at/near the top of the cobol part of the forum is a "Sticky" that contain working code for a 2-file match/merge. if you download and review that code, you should have a more complete understanding of the process. any questions, please post back here.
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Wed Sep 17, 2008 11:19 am    Post subject:
Reply with quote

Hi Dick,

Quote:
revel - the logic posted is incomplete and will fail.


have to tested above logic, i don't think so, it will fail.....

Just i coded main logic part rest he as to think....

Ya.. it will fail in below code only when

Code:
3. Put it in loop FILE A Read until End of file


Ie he need to handle for EOF condition for both files else it will fo in loop.

Quote:
First SORT FILE A and FILE B in ASCENDING ORDER (I Assume that there will unique field-about which you should sort).


The above logoc is work only when Files were having records of unique type and were sorted about that fields in case If the Fisrt File is having duplicate records the logic will change

Any suggestion are welcomed[/quote]
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 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
No new posts Dynamic split of files under groups sril.krishy DFSORT/ICETOOL 4 Mon Apr 17, 2017 1:09 pm
No new posts Compare two files and subtract values ameetmund DFSORT/ICETOOL 7 Fri Mar 31, 2017 3:35 pm
No new posts Append data from two files into a sin... Praveen04 DFSORT/ICETOOL 5 Thu Mar 16, 2017 7:29 pm


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