View previous topic :: View next topic
|
Author |
Message |
John F Dutcher
New User
Joined: 02 Apr 2008 Posts: 11 Location: Harrisburg, PA
|
|
|
|
I had been believing that the sort below, used to match two files and write out just matches would never have more records on the output file than exist n file F1, that is, if all F1 records found a match in F2 they would all appear in the output. Not so, as the output has many more records than the input F1. Yes, there are dups in F1 and I believe F2.... but I presumed that only the matches to F1 found in F2 would write out. CAN THIS be adjusted......so that only as many records as came in on F1 are written out ??
Code: |
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(1,9,CH,A)
JOINKEYS FILE=F2,FIELDS=(1,9,CH,A)
REFORMAT FIELDS=(F1:1,243,F2:10,3)
SORT FIELDS=COPY
/* |
code' d |
|
Back to top |
|
|
Abid Hasan
New User
Joined: 25 Mar 2013 Posts: 88 Location: India
|
|
|
|
Hello,
Now this is where things get tad bit tricky.
JOINKEYS works by building cartesian joins; and there is an example which explains the situation you're facing in the DFSORT manual.
Look at: Example 2 - Paired F1/F2 records with duplicates (cartesian) - in the DFSORT Application Programming Guide (SC26-7523-06); Chapter 4, Using a JOINKEYS Application for Joining Two Files.
That definitely should clear the air. |
|
Back to top |
|
|
John F Dutcher
New User
Joined: 02 Apr 2008 Posts: 11 Location: Harrisburg, PA
|
|
|
|
The same manual seems to show with its Example # 3 the scenario I desire, one which keeps only the F1 records which successfully 'paired' on the key fields with a record in F2. However it sems to be coded exactly as my own example (minus the 'parsing' exercise)....and it's clear mine does not work as expected..... or as suggested in Example # 3 ? |
|
Back to top |
|
|
John F Dutcher
New User
Joined: 02 Apr 2008 Posts: 11 Location: Harrisburg, PA
|
|
|
|
OK...... on this issue,,,,,, I find if I eliminate the dups on File F2 I get the results I expected. I will simply be guided by this experience in the future and not think that the SORT will limit output file records to what is on input file unless the 'matching' file is first purged of any dups on the key fields involved. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3049 Location: NYC,USA
|
|
|
|
Quote: |
CAN THIS be adjusted |
You can use SUM FIELDS=NONE and the keys in your SORT FIELDS otherwise Abid has explained how that works. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Every each record on F1 that matches a record on F2 will cause a joined record to be created, and vice versa.
If you actually have the need to SORT the F1 and F2 you can remove duplicates with SUM FIELDS=NONE. If you don't need to SORT the data, you can always use WHEN=GROUP or SEQNUM to identify the "first" of a group of records. Various ways with INCDLUE/OMIT COND in the main task, or with OUTFIL INCLUDE=/OMIT=. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3049 Location: NYC,USA
|
|
|
|
This is precisely what Bill said. |
|
Back to top |
|
|
|