View previous topic :: View next topic
|
Author |
Message |
Kothai Jayaraj
New User
Joined: 08 Aug 2012 Posts: 3 Location: INDIA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Kothai Jayaraj
New User
Joined: 08 Aug 2012 Posts: 3 Location: INDIA
|
|
|
|
Sorry I missed to include 101 23-11-12 CCCC combination in the output file by mistake |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Peter cobolskolan
Active User
Joined: 06 Feb 2012 Posts: 104 Location: Sweden
|
|
|
|
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 |
|
|
Kothai Jayaraj
New User
Joined: 08 Aug 2012 Posts: 3 Location: INDIA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
depending upon the validation required,
there is a lot that SORT can accomplish. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
@dick : He said he wanted the cartesian product |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
actually,
the TS used the redundant phraseology:
cartesian combination |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Quote: |
@dick : He said he wanted the cartesian product |
Oops - missed that
d |
|
Back to top |
|
|
|