Best way to add a column conditionally to a sequential file

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
bondlee
Participant
Posts: 7
Joined: Tue Jan 11, 2011 11:15 pm

Best way to add a column conditionally to a sequential file

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Post by SURA »

I like this approach Ray.
Thanks
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Interesting. You could also conditionally write out the header record as well if desired.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
bondlee
Participant
Posts: 7
Joined: Tue Jan 11, 2011 11:15 pm

Post 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>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Yes, that's my suggested approach (once I'd understood your # to belong to "Row" and not to "=").
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ray.wurlod wrote:(once I'd understood your # to belong to "Row" and not to "=").
'Not' being the operative word here. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply