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
 

 

two Files compare - having duplicates in both files

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Kothai Jayaraj

New User


Joined: 08 Aug 2012
Posts: 4
Location: INDIA

PostPosted: Wed Aug 08, 2012 9:51 am    Post subject: two Files compare - having duplicates in both files
Reply with quote

Hi,

The below is my requirement,

File1:
Key Date comment
---- ---------- ----------
101 20-10-12 AAAA
101 21-10-12 BBBB
101 23-11-12 CCCC
102 12-11-12 DDDD
102 12-12-12 AAAV
103 11-11-12 BBBB

File 2:

Key1 Item number DATA
----- --------------- -------
100 1 Data
100 2 Data
100 3 Data
101 1 Data
101 2 Data
101 4 Data
102 1 Data
102 4 Data
103 1 Data
103 9 data

My expected output file should have all the combination of matching records

101 20-10-12 AAAA 1 DATA
101 20-10-12 AAAA 2 DATA
101 20-10-12 AAAA 4 DATA
101 21-10-12 BBBB 1 DATA
101 21-10-12 BBBB 2 DATA
101 21-10-12 BBBB 4 DATA
102 12-11-12 DDDD 1 DATA
102 12-11-12 DDDD 4 DATA
102 12-12-12 AAAV 1 DATA
102 12-12-12 AAAV 4 DATA
103 11-11-12 BBBB 1 Data
103 11-11-12 BBBB 9 Data

Input file1:
Having Duplicates with different dates and comments

Input file2
Having Dupicated with different item no and data

Output file should be written whenever there is a matching key found between two files for all the combination that has in inputfile 1 and inputfile 2

My idea is to read the input file1 repeatedly comparing the key with itself till the key changes and store it in the array, then read the second file and compare the key of second file with first file ke, if key matches then loop the array to write records for each array occurance and then read the second file till the key changes to repeat the same. I am not sure if this program logic will work. Please Help me with your ideas
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 08, 2012 10:26 am    Post subject:
Reply with quote

before we discuss logic,
explain why
101 23-11-12 CCCC
is not included in the output?

now, logic:
this is a very typical Sort problem. that would be the better solution.

if you insist that it must be cobol,
then post this homework in the student forum
Back to top
View user's profile Send private message
Kothai Jayaraj

New User


Joined: 08 Aug 2012
Posts: 4
Location: INDIA

PostPosted: Wed Aug 08, 2012 10:43 am    Post subject:
Reply with quote

Sorry I missed to include 101 23-11-12 CCCC combination in the output file by mistake
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 08, 2012 10:57 am    Post subject:
Reply with quote

the solution to your problem if you have DFSORT is
Match, FB, keys in different places, duplicates
which is one of the topics in the SORTRCK.PDF which is on page 27.

obviously you need to modify so that it looks for the keys in the same place on both files.
Back to top
View user's profile Send private message
Peter cobolskolan

Active User


Joined: 06 Feb 2012
Posts: 104
Location: Sweden

PostPosted: Wed Aug 08, 2012 11:01 am    Post subject: Reply to: two Files compare - having duplicates in both file
Reply with quote

Quote:
I am not sure if this program logic will work.

The only way to be sure is to test it!
Why haven't you done that before posting your idea here?
Back to top
View user's profile Send private message
Kothai Jayaraj

New User


Joined: 08 Aug 2012
Posts: 4
Location: INDIA

PostPosted: Wed Aug 08, 2012 11:25 am    Post subject:
Reply with quote

Thanks Dick for your suggestion, I will try in Sort. There were some validations for each field thats i why i have chosen the Cobol coding, I think after getting the cartesian combination through Sort and will do validations writing simple program.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 08, 2012 11:54 am    Post subject:
Reply with quote

depending upon the validation required,
there is a lot that SORT can accomplish.
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: Wed Aug 08, 2012 6:47 pm    Post subject:
Reply with quote

Hello,

I believe you have already downloaded the 2-file match/merge sample code form the "Sticky". If you need a COBOL solution, modify that code to handle the situations of your requirement.

It will be far easier to modify code that is already proven (or should be far easier) than starting from scratch.

Recommend you look into sort as suggested, but if it must be code, you already have a start. Indeed, more than a start - it is nearly done. . .
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: Wed Aug 08, 2012 6:50 pm    Post subject:
Reply with quote

Follow on:

Handling duplicates in both files will take a bit more thought regardless of whether you use the sort or code. You need to determine which fileA records should match with which fileB records.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Wed Aug 08, 2012 8:56 pm    Post subject:
Reply with quote

I would reverse it and store rec2 in the array:
Code:
Read file1,
read file2
perform until both key = high-value
    eval true
    when key1 > key2 : read file2 at eof move high-value to key2
    when key1 = key2 :
        store rec2 in array (n=n+1)
        write output rec1/rec2
        read file2 at eof move high-value to key2
    when key1 < key2 : 
       read rec1 at eof move high-value to key1
       eval true
       when n=0 continue
       when key1 = array : write output rec1/array(1..n) for all in array
       when key1 <> array : empty array (set n = 0)
       end-eval
   end-eval
end-perform
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: Wed Aug 08, 2012 9:08 pm    Post subject:
Reply with quote

Hello,

Yup, that could work, depending on which of the 8 duplicates from fileB and the 6 duplicates from fileA should match. . . (these are made up "stats" but the concern is real and often mis-handled).

Same issue with the sort or the sample match/merge code from the sticky. How to deal with unbalanced sets of duplicates. . .

Some kind of rule must be established rather than "just let'er rip" and use what comes out icon_wink.gif
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Wed Aug 08, 2012 9:19 pm    Post subject:
Reply with quote

@dick : He said he wanted the cartesian product
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 08, 2012 9:30 pm    Post subject:
Reply with quote

actually,
the TS used the redundant phraseology:
cartesian combination
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: Wed Aug 08, 2012 11:30 pm    Post subject: Reply to: two Files compare - having duplicates in both file
Reply with quote

Quote:
@dick : He said he wanted the cartesian product
Oops - missed that icon_redface.gif

d
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
No new posts Updating the counters after eliminati... PANDU1 DFSORT/ICETOOL 12 Mon Nov 21, 2016 9:47 am
No new posts Match or compare two files in VB Format anatol DFSORT/ICETOOL 14 Thu Nov 03, 2016 7:41 pm
This topic is locked: you cannot edit posts or make replies. How to use 2 input files in control c... Gunapala CN DFSORT/ICETOOL 23 Thu Oct 13, 2016 3:42 pm
No new posts Adding records from two files into on... shiitiizz SYNCSORT 4 Mon Sep 19, 2016 8:41 pm


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