|
View previous topic :: View next topic
|
| Author |
Message |
scdinesh
New User
Joined: 06 Sep 2006 Posts: 45 Location: United States
|
|
|
|
Guys, Appreciate your help me on following requirement:
I've 2 input files(not in sorted order) , compare both files with matching key as(1st 4 digits) and create 4 output files: Output File1 with matching records only from input file1 and output File 2 with matching records only from input file2(Although key matches , I need to validate the remaining records latter from the files separately)
Output file 3 with unmatched records from input file1 and Output file 4 with unmatched records from input file2.
Sample Records
Input File1:
2222Keith
1111David
4444Sam
3333Rohit
Input File2:
3778Ruban
3333Rizwan
4444Andrew
5555Travis
Comparison upon key: S.No(1st 4 digit)
Output File1:(match from input File1)
4444Sam
3333Rohit
Output File2:(match from input File2)
3333Rizwan
4444Andrew
Output File3:(un match from input File3)
2222Keith
1111David
Output File4:(unmatch from input File4)
3778Ruban
5555Travis
Thanks for your help |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2290 Location: USA
|
|
|
|
RTFM:
| Code: |
JOINKEYS FILE=F1,...
JOINKEYS FILE=F2,...
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=...,FILL=...
SORT FIELDS=...
OUTFIL FNAMES=OFILE1,INCLUDE=...,BUILD=...
OUTFIL FNAMES=OFILE2,INCLUDE=...,BUILD=...
OUTFIL FNAMES=OFILE3,INCLUDE=...,BUILD=...
OUTFIL FNAMES=OFILE4,INCLUDE=...,BUILD=...
|
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
No need for FILL=, use the match-marker (?, a question-mark, in the REFORMAT record, B=both, 1=file1 only, 2=file2 only).
The SORT would be FIELDS=COPY. |
|
| Back to top |
|
 |
scdinesh
New User
Joined: 06 Sep 2006 Posts: 45 Location: United States
|
|
|
|
Thanks sergeyken for quick response...
Assume my record length is set to 80 , with first 4 digits as key
may I know what is the value I can add in 'Include =' . I don't have any specific condition to filter out the records.
Also please help me on REFORMAT FIELDS=...,FILL=... |
|
| Back to top |
|
 |
scdinesh
New User
Joined: 06 Sep 2006 Posts: 45 Location: United States
|
|
|
|
Hi Bill,
Thanks for the reply!!!
Please advise how can I specify.
JOINKEYS FILES=F1,FIELDS=(1,4,A)
JOINKEYS FILES=F2,FIELDS=(1,4,A)
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(F1:1,80,?)
OPTION COPY
OUTFIL FNAMES=OFILE1,INCLUDE=(81,1,CH,EQ,C'B'),
BUILD=(1,80)
OUTFIL FNAMES=OFILE2,INCLUDE=(81,1,CH,EQ,C'1'),
BUILD=(1,80)
OUTFIL FNAMES=OFILE3,INCLUDE=(81,1,CH,EQ,C'2'),
BUILD=(1,80)
Note:
B=both -> In my case I need to write matching/unmatching records into separate files |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
scdinesh,
Since you need to write the entire record area from both the inputs, your REFORMAT should include both F1 and F2 fields. Something like,
| Code: |
| REFORMAT FIELDS=(F1:1,80,F2:1,80,?) |
Your OFILE1 (matched records from input1) and OFILE2 (matched records from input2) should both INCLUDE 'B' records, but write only F1 and F2 records respectively into each of those outputs.
Similarly for OFILE3 (unmatched from input1) and OFILE4 (unmatched from input2) write relevant fields to output in the BUILD. |
|
| Back to top |
|
 |
scdinesh
New User
Joined: 06 Sep 2006 Posts: 45 Location: United States
|
|
|
|
Thanks Arun for the help!!!
"Your OFILE1 (matched records from input1) and OFILE2 (matched records from input2) should both INCLUDE 'B' records, but write only F1 and F2 records respectively into each of those outputs"
In my case I want to write only F1 records into OFILE1 upon condition , how does it know it should write only F1 records? (as we have mentioned both F1 and F2 in 'Reformat fields'). Please help |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| Quote: |
In my case I want to write only F1 records into OFILE1 upon condition , how does it know it should write only F1 records?
|
The BUILD parameter in each OUTFIL group lets you choose specific fields from the REFORMAT-ted combined record (161 bytes in your case).
It is just a matter of writing first 80 bytes of the reformatted record into your first OUTFIL and the next 80 bytes of the reformatted record into your second OUTFIL. |
|
| Back to top |
|
 |
scdinesh
New User
Joined: 06 Sep 2006 Posts: 45 Location: United States
|
|
|
|
| Thanks Sergeyken,Bill and Arun |
|
| Back to top |
|
 |
scdinesh
New User
Joined: 06 Sep 2006 Posts: 45 Location: United States
|
|
|
|
Hi,
Please see if there is anything wrong in the below sort upon my above requirement? am seeing empty records in all 4 output files.
JOINKEYS F1=CONCUR,FIELDS=(1,4,A)
JOINKEYS F2=LOOKUP,FIELDS=(1,4,A)
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(F1:1,80,F2:1,80,?)
SORT FIELDS=COPY
OUTFIL FILES=01,INCLUDE=(81,1,CH,EQ,C'B'),BUILD=(1,80)
OUTFIL FILES=02,INCLUDE=(81,1,CH,EQ,C'B'),BUILD=(1,80)
OUTFIL FILES=03,INCLUDE=(81,1,CH,EQ,C'1'),BUILD=(1,80)
OUTFIL FILES=04,INCLUDE=(81,1,CH,EQ,C'2'),BUILD=(1,80
Thanks |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Your match marker position is 161 and NOT 81.
Plus you need to fix your BUILDs as suggested earlier. |
|
| Back to top |
|
 |
John Del
New User

Joined: 27 Apr 2012 Posts: 42 Location: NY
|
|
|
|
scdinesh -
I would suggest that you first just write the reformatted output to one dataset, so that you can see how the join operation is outputting the joined data in relation to the match marker value(s). That might help you to understand how to write your INCLUDE conditions and BUILD parameters for the OUTFIL files.
/* |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|