Page 1 of 1

Splicing and keeping duplicates

PostPosted: Fri May 02, 2008 9:30 pm
by profondo
In the example below, I would like to pick up the 3-byte field from record A and try to apply it to other records with a matching key but I would like to keep the base record A unchanged and keep all the updated records. I thought splice with KEEPBASE would help do the trick but I'm having difficulty applying the update to the duplicate matching records (like the C record and duplicate B records shown in the example below) and keeping those records in the output.

Input:
A KEY1 111
B KEY1 000
C KEY1 000
A KEY2 123
B KEY2 000
B KEY2 000
B KEY2 000
D KEY2 000
D KEY2 000
A KEY3 101
B KEY3 000
C KEY3 000


Output I need:
A KEY1 111
B KEY1 111
C KEY1 111
A KEY2 123
B KEY2 123
B KEY2 123
B KEY2 123
D KEY2 123
D KEY2 123
A KEY3 101
B KEY3 101
C KEY3 101

Can splice help do something like this?

Re: Splicing and keeping duplicates

PostPosted: Fri May 02, 2008 11:10 pm
by Frank Yaeger
You can use a SPLICE operator like this to do what you asked for:

SPLICE FROM(IN) TO(OUT) ON(9,4,CH) KEEPBASE -
  WITHALL WITH(1,1) WITH(9,4)

Re: Splicing and keeping duplicates

PostPosted: Mon May 05, 2008 11:29 am
by profondo
Thanks, Frank - that worked well.

Another problem - say I want to perform the same task but this time I'm dealing with a 100 byte variable length file where, using the same example above, records A, B, C, D are each of different lengths - "A" = 100 bytes, B = 80, C=90, D=40...
I tried it using VLENMAX and noticed what I expected - the resulting spliced records were given the length of the base record because it had the largest length of all records. The data in bytes 80-100 of "A" were carried over to "B"'s record. So I'm thinking SPLICE may not be the way to go here if i'm looking to keep the overlay records their original size, correct?

Re: Splicing and keeping duplicates

PostPosted: Mon May 05, 2008 8:32 pm
by Frank Yaeger
If you want to keep the length of the OVERLAY records, why did you choose VLENMAX rather than VLENOVLY? Doesn't it seem obvious that VLENOVLY would give you the length of the overlay records?

Re: Splicing and keeping duplicates

PostPosted: Fri May 09, 2008 10:02 pm
by profondo
Yikes - I must have read through the DFSORT guide a bit too quick. Maybe because each overlaid record is of different length, I didn't think VLENOVLY would maintain the original size of each but I was mistaken.

The key was actually in 2 different places in that variable length file so I added another ON and WITH for that, and along with the WITH for the rest of the record, everything's now looking dandy.

Many thanks!