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
 

 

comparing logic of two files in cobol

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

New User


Joined: 14 Nov 2006
Posts: 4
Location: bangalore

PostPosted: Mon Dec 11, 2006 9:14 am    Post subject: comparing logic of two files in cobol
Reply with quote

How to validate two files in cobol, such that the resultant file will contain only matching data from two files.

file 1, file 2 and resultant file is 3.

If file 1 contains 1,2,4,6,8 and file 2 contains 1,6,3,2,7.
Back to top
View user's profile Send private message

priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Mon Dec 11, 2006 12:16 pm    Post subject: Re: comparing logic of two files in cobol
Reply with quote

Hi Rohit,

I can see contents of the files are not in sorted order... so how about sorting first then having a Binary search...
Back to top
View user's profile Send private message
rohitsoni26
Currently Banned

New User


Joined: 14 Nov 2006
Posts: 4
Location: bangalore

PostPosted: Tue Dec 12, 2006 9:31 am    Post subject: plz reply
Reply with quote

ya first i have to make in sorted order .assume that it is in sorted order then after that what i have to write full logi ,program
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Tue Dec 12, 2006 9:47 am    Post subject:
Reply with quote

HI There,

You can use following logic.
READ FILEA
READ FILEB
PERFORM UNTIL END-OF-FILEA OR END-OF-FILEB
IF KEY OF FILEA= KEY OF FILEB
Populate RECORDC with RECORDA
WRITE FILEC
READ FILEA
READ FILEB
ELSE
IF KEY of FILEA < KEY of FILEB
READ FILEA
ELSE
READ FILEB
END-IF
END-IF
END-PERFORM.

Hope it will helpful
Back to top
View user's profile Send private message
Rajen

New User


Joined: 05 May 2005
Posts: 61

PostPosted: Tue Dec 12, 2006 9:49 am    Post subject: Re: comparing logic of two files in cobol
Reply with quote

Hi Rohit,
Sorry i am replying bit and i dont know if your purpose is been solved or not but below is the solution. As you have posted the question in Cobol Forum i am giving you logic for Cobol Program.

You have file 1, file 2 as Input file and resultant file is 3.

File 1 contains 1,2,4,6,8 and
File 2 contains 1,6,3,2,7.

Assuming both the files are sorted (if you want to compare on key then sort both the files on that particular Key).

You read both the files first (Reading first record) then
You can use EVALUATE. So it would be like

Code:
EVALUATE TRUE
    WHEN Record-1 (Key-1) = Record-2 (Key-2)
        Move Record-1 to Record-3 (this is output file record)
       Write record into output fille.
        Read File-1
        Read File-2
    WHEN Record-1 (Key-1) > Record-2 (Key-2)
        Read File-2
    WHEN Record-1 (Key-1) < Record-2 (Key-2)
        Read File-1



Here the resultant file will only have matching records from both the files but primary requirement is both the files should be pre-sorted(if required they should be sorted on particular KEY).

Do let me know if it worked or not.


Thanks,
Rajen.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Tue Dec 12, 2006 10:09 am    Post subject: Re: comparing logic of two files in cobol
Reply with quote

Look here, it is already discussed...
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 XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm
No new posts getting three output files out of JOI... migusd SYNCSORT 7 Mon Jun 05, 2017 11:30 pm
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am


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