Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 1 Tue Sep 26, 2017 3:07 am
No new posts Comparing 2 Files using Current time arunsoods SYNCSORT 9 Fri Sep 22, 2017 6:00 pm
No new posts Split 1 file into 10 output Files - S... Prasanth Kumar SYNCSORT 5 Sat Sep 16, 2017 12:02 am
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts Join records from 2 files with No Dup... Poha Eater DFSORT/ICETOOL 21 Sun Aug 27, 2017 10:35 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us