Page 1 of 1

Need to Pass previous record data to next line

PostPosted: Wed Oct 01, 2014 4:31 pm
by Hariprasad K
Hi,

I want to take previous record key value and need to update it next record which does not have a key.

Input file as below:
1111 aaaa
2222 bbbb
        cccc
        dddd
3333 eeee
4444 fffff
        gggg


Output file should be like below:
1111 aaaa
2222 bbbb
2222 cccc
2222 dddd
3333 eeee
4444 fffff
4444 gggg


Thanks in advacne !

Code'd

Re: Need to Pass previous record data to next line

PostPosted: Wed Oct 01, 2014 5:17 pm
by BillyBoyo
If you use the Code tags and the Preview button, you can preserve spacing.

You need IFTHEN=(WHEN=GROUP....

I'm not sure if SyncSORT (or your SyncSORT) has KEYBEGIN. If not, use IFTHEN=(WHEN=INIIT to set a sequence number with RESTART, then in the WHEN=GROUP use BEGIN with a value of one for your sequence number. You PUSH the key to the existing position of the key PUSH=(1:1,4) and it will be copied to each record.

Re: Need to Pass previous record data to next line

PostPosted: Wed Oct 01, 2014 5:22 pm
by Hariprasad K
Hi Billy,

Thanks for your suggestion, it would be great if you can provide more details on this.

Re: Need to Pass previous record data to next line

PostPosted: Wed Oct 01, 2014 6:03 pm
by BillyBoyo
OK, but you have SyncSORT and I don't even know the particular version you have.

It's easier than I made out anyway. You just need WHEN=GROUP with a BEGIN for your key not being space, then the PUSH. Try it.

Re: Need to Pass previous record data to next line

PostPosted: Wed Oct 01, 2014 6:25 pm
by Hariprasad K
Thanks Billy, I tried and it's given correct results.. Thank you much for your guidelines.

Here is the sort card:
First step:
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,4,CH,NE,C' '),PUSH=(40:ID=1))

Second step:
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(40,1),
PUSH=(1:1,4))

Re: Need to Pass previous record data to next line

PostPosted: Wed Oct 01, 2014 7:19 pm
by BillyBoyo
Try this now in one step:

SORT FIELDS=COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,4,CH,NE,C' '),PUSH=(1:1,4))

Re: Need to Pass previous record data to next line

PostPosted: Wed Oct 01, 2014 8:36 pm
by Hariprasad K
Great, it worked as I expected, I used to read all your suggestions posted in this site. Really appreciate your efforts for reading and giving suggestions for all users.