View previous topic :: View next topic
|
Author |
Message |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Hi,
I want to match two files and copy content from file-2 only if the content from file-1 found twice in the same record in file-2.
File-1: RECFM=FB, LRECL=80
Code: |
MAHIMA
RASIMA
ARULAN
RAJAHA
|
File-2: RECFM=FB, LRECL=80
Code: |
MAHIMA 2009 10-10-08 MAHIMA
RUBENS 2009 01-10-08 RUBENS
SASTRY 2009 12-01-08 SASTRY
ARULAN 2008 24-12-08 ARULAN
CHANDI 2009 09-06-07 CHANDI
|
Expected output: RECFM=FB, LRECL=80
Code: |
MAHIMA 2009 10-10-08 MAHIMA
ARULAN 2008 24-12-08 ARULAN
|
Thanks. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Ramsri,
Its not quite clear, What do you mean by "content from file-1 found twice". Does it mean same values for field-1 and field-4 in file-2? What is the key for file comparison in file-2 ----> field-1 or field-4?. Your input shows same values for these fields? What if any of these has a different value.
Post all possible combinations of input and the expected output along with a proper definition of the rules. |
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Arun,
All your assumptions are correct. The match must be done on field-1 and field-4. Both are key fields and will have same values.
fiel-1:
Code: |
MAHIMA
RASIMA
ARULAN
RUBENS
RAJAHA
|
file-2:
Code: |
MAHIMA 2009 10-10-08 MAHIMA
RUBENS 2009 01-10-08 RUBANS
SASTRY 2009 12-01-08 SASTRY
ARULAN 2008 24-12-08 ARULAN
CHANDI 2009 09-06-07 CHADNI
|
Output:
Code: |
MAHIMA 2009 10-10-08 MAHIMA
ARULAN 2008 24-12-08 ARULAN
|
Thanks. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Quote: |
Both are key fields and will have same values |
If that is the case, would nt it be a direct SYNCSORT JOIN application matching the first 6 characters in both the files? Try this and post back if you come across any issues. Good luck. |
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Arun, JOIN holds good if I had to compare only the first 6 bytes as you said. But, what happens in this case where the field-1 & field-4 have different values?
Code: |
RUBENS 2009 01-10-08 RUBANS
CHANDI 2009 09-06-07 CHADNI
|
Thanks. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Ramsri,
I m sorry. I dint notice the differences in your recent sample.
I dont have access to mainframe now. But I can show you a possible way which you can give a try. Post back if you come across any issues. Goodluck
Code: |
JOINKEYS FILE=F1,FIELDS=(1,6,A)
JOINKEYS FILE=F2,FIELDS=(1,6,A),
INCLUDE=(1,6,CH,EQ,22,6,CH)
REFORMAT FIELDS=(F2:1,27)
SORT FIELDS=COPY |
|
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Arun, wonderful.....you can never go wrong. It has worked as expected.
Thank you very much. |
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Arun, Can we have even multiple comparisons?
Code: |
JOINKEYS FILE=F2,FIELDS=(1,6,A),
INCLUDE=(1,6,CH,EQ,22,6,CH,EQ,72,6,CH)
|
Thanks. |
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Ok..I got it how to get it worked for multiple occurences !
Code: |
JOINKEYS FILE=F2,FIELDS=(1,6,A),
INCLUDE=(1,6,CH,EQ,22,6,CH,AND,1,6,CH,EQ,72,6,CH)
|
Correct me if I am wrong.
Thanks. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
You're welcome. |
|
Back to top |
|
|
|