View previous topic :: View next topic
|
Author |
Message |
santhosh5983
New User
Joined: 11 Mar 2015 Posts: 10 Location: India
|
|
|
|
Hi,
I have a requirement to concatenate 2 files based on account number field. The position of the account number field in each of the input file is different. Please find the file 1 and file 2 format and the output that am expecting. Please let me know how can this be achieved thru sort ?
Input File 1 - Variable block say of length 50. Account number position is 15 of size 5.
Code: |
----+----1----+----2----+----3----+----4----+-
***************************** Top of Data ****
ABCDEFGH 11223 BANGALORE
XXXXXXXX 11345 CHENNAI
TTTTTTTT 11700 MYSORE
YYYYYYYYYY 12000 USA
ZZZZZZZZZ 13000 CANADA
**************************** Bottom of Data **
|
Input File 2 - Variable block say of length 30. Account number position is 1 of size 5.
Code: |
----+----1----+----2----+-
***************************** Top of Data ***
11223 CHINA
11345 BANGLADESH
11700 AUSTRALIA
12000 JAPAN
13000 WENTZVILLE
**************************** Bottom of Data *
|
Expected Output:
Code: |
ABCDEFGH 11223 BANGALORE
11223 CHINA
XXXXXXXX 11345 CHENNAI
11345 BANGLADESH
TTTTTTTT 11700 MYSORE
11700 AUSTRALIA
YYYYYYYYYY 12000 USA
12000 JAPAN
ZZZZZZZZZ 13000 CANADA
13000 WENTZVILLE
|
|
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Will there always be one record for each account on each file. Are the files in account number sequence? |
|
Back to top |
|
|
santhosh5983
New User
Joined: 11 Mar 2015 Posts: 10 Location: India
|
|
|
|
Yes the files will be sorted on account number. And yes both the files will have one record for every account number.
As part of error handling, it will be great if we can push the records that does not have the corresponding matching record to a different/separate file. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
I see the file is already sorted by account number so all you need to do is add sequence number to each file and then sort based on that. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
I got disconnected so couldn't edit my post.
So to continue, may be use a join key on account number or the sequence number as told above and reformat them together and then resize based on record length, Not sure if that works but try. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
JOINKEYS on the account number.
Variable-length REFORMAT record, although one of the records (better the short one) need to be padded to fixed-length in the REFORMAT. Also specify the match-marker. JOIN UNMATCHED,F1,F2. There OUTFILs, one for matched, one for unmatched F1, one for unmatched F2.
On your match, BUILD, using the slash operator (/) to create two records from one OUTFIL input. Use VLTRIM to make the records variable again, being careful of what values may be in the final field on each record (you don't want to lose necessary trailing blanks). |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Bill, Can we use resize(ICETOOL) as below as a alternative to '/'? any downsides?
e.g.Vb is not considered for this example.
Code: |
//TOOLIN DD *
COPY JKFROM TO(OUT1) USING(CTL2)
RESIZE FROM(OUT1) TO(OUT2) TOLEN(50)
//CTL2CNTL DD *
JOINKEYS F1=IN1,FIELDS=(16,5,A)
JOINKEYS F2=IN2,FIELDS=(1,5,A)
JOIN UNPAIRED
OPTION COPY
REFORMAT FIELDS=(F1:1,50,F2:1,30)
/* |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
RESIZE is for fixed-length records only.
With the COPY already being a JOINKEYS, the RESIZE would add a second pass of the data.
You could make a fixed-length REFORMAT record, and then RESIZE, but you still have the extra pass.
ICETOOL's COPY and SORT can use JKFROM. RESIZE cannot. Can't avoid the two passes. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Thanks Bill. |
|
Back to top |
|
|
|