Page 1 of 1

Best way to add a column conditionally to a sequential file

Posted: Thu Jun 20, 2013 9:26 pm
by bondlee
Hi All,

I have a specific requirement of adding a column conditionally to a target sequential file. I am looking for the best way of doing it.

To put it in detail, the source can have two columns Col1, Col2. Col1 always goes to target file (which is a sequential file) but Col2 should be added to target only if it satisfies a condition. Assuming that there is only one record in source, what will be the best way to achieve this?

I think we can't use RCP as it is blocked by the conditional addition of the column on contrary to unconditional addition.

I have a workaround using sequences but I am interested to see if there is any better way. Appreciate your interest in this.

Posted: Thu Jun 20, 2013 9:56 pm
by ray.wurlod
For this to work you must set "First line is column headings" to False.

Always send one column. It may be derived as InLink.Col1 or it may be derived as InLink.Col1 : "," : InLink.Col2 in a Transformer stage.

Wrap these two possiblilties in an If..Then..Else construct to manage your condition, and amend the delimiter character appropriately.

Posted: Thu Jun 20, 2013 10:20 pm
by SURA
I like this approach Ray.

Posted: Thu Jun 20, 2013 10:24 pm
by chulett
Interesting. You could also conditionally write out the header record as well if desired.

Posted: Thu Jun 20, 2013 11:06 pm
by ray.wurlod
Yes, either in a before-job subroutine or when processing row #1.

In the former case the Sequential File stage would need to be set to Append to the file.

Posted: Sun Jul 07, 2013 8:49 am
by bondlee
Thanks all for the replies. Sorry for late reply.

@Ray, It's a nice approach. I was also thinking of column export and import stages for similar approach. I was wondering, however, how can we generate record of column names in the latter case (while processing row#1). I guess for this we might need to use either a row generator stage or a funnel stage after transformer.

I hope you are suggesting to use a record delimiter for row#1 like below:
If Row#=1 Then <Col_Names> <Rec_Delim> <Col_Values>

Posted: Sun Jul 07, 2013 5:23 pm
by ray.wurlod
Yes, that's my suggested approach (once I'd understood your # to belong to "Row" and not to "=").

Posted: Sun Jul 07, 2013 8:30 pm
by chulett
ray.wurlod wrote:(once I'd understood your # to belong to "Row" and not to "=").
'Not' being the operative word here. :wink: