IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

two Files compare - having duplicates in both files


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Kothai Jayaraj

New User


Joined: 08 Aug 2012
Posts: 3
Location: INDIA

PostPosted: Wed Aug 08, 2012 9:51 am
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
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: 3
Location: INDIA

PostPosted: Wed Aug 08, 2012 10:43 am
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
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
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: 3
Location: INDIA

PostPosted: Wed Aug 08, 2012 11:25 am
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
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

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Aug 08, 2012 6:47 pm
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

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Aug 08, 2012 6:50 pm
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: 1281
Location: Belgium

PostPosted: Wed Aug 08, 2012 8:56 pm
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

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Aug 08, 2012 9:08 pm
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: 1281
Location: Belgium

PostPosted: Wed Aug 08, 2012 9:19 pm
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
Reply with quote

actually,
the TS used the redundant phraseology:
cartesian combination
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Aug 08, 2012 11:30 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 2
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
Search our Forums:

Back to Top