Problem in if then else coding in transformer

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
shaonli
Participant
Posts: 80
Joined: Tue Nov 28, 2006 6:52 am

Problem in if then else coding in transformer

Post by shaonli »

Hi,
In my source there are 3 condition for three values.If name=a then 1,name=b then 2,name=c then 3.
For any other value will not be considered.

Now in tranformer when I am using if then esle the problem is that in the last loop of else I am not able to give any other value as no default value is not mentioned.
If name=a then 1
else
if name=b then 2
else
if name=c then 3
esle
????

if I use the other one like

If name=a then 1
else
if name=b then 2
else
c

in this case the other input apart from a,b,c will pass.
I am not able to give end loop condition.
If I restrict the record in constraint then I can do but how to do that in if then else loop

Please suggest.

Thanks
Shaonli
keshav0307
Premium Member
Premium Member
Posts: 783
Joined: Mon Jan 16, 2006 10:17 pm
Location: Sydney, Australia

Post by keshav0307 »

If name=a then 1
else
if name=b then 2
else
if name=c then 3
else
''
vrishabhsagar
Participant
Posts: 33
Joined: Mon Nov 12, 2007 1:02 am
Location: Bangalore

Re: Problem in if then else coding in transformer

Post by vrishabhsagar »

shaonli wrote:Hi,
In my source there are 3 condition for three values.If name=a then 1,name=b then 2,name=c then 3.
For any other value will not be considered.

Now in tranformer when I am using if then esle the problem is that in the last loop of else I am not able to give any other value as no default value is not mentioned.
If name=a then 1
else
if name=b then 2
else
if name=c then 3
esle
????

if I use the other one like

If name=a then 1
else
if name=b then 2
else
c

in this case the other input apart from a,b,c will pass.
I am not able to give end loop condition.
If I restrict the record in constraint then I can do but how to do that in if then else loop

Please suggest.

Thanks
Shaonli
As far as I know, (I m a total NooB :) ), it's expecting the else condition, because it NEEDS to know, what to do with the rows that do not match any of the conditions met. So I guess, you should have a buisness rule to specify what to do with such rows... (rejects)??

For this maybe you can give the rows (which do not match any if conditions) some dummy values like "#" or something and collect all such rows in next stage or apply a transformer/filter constraint on such rows, so that they are not propogated.

Again, I am a completely new to DS Px, please let me know how did you solve it, if you get a better idea!!
Rishabh Sagar V
Bangalore
rjhcc
Premium Member
Premium Member
Posts: 34
Joined: Thu Jan 27, 2005 4:20 pm

Post by rjhcc »

You can assign the origianl value by using the attribute name in the final else. In other words, it's either a,b, or c, or leave it alone.

If name=a then 1
else
if name=b then 2
else
if name=c then 3
esle
name
rjhcc
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Don't neglect to get the data types correct. From your example I assume that name (the input column) is a string and the output column is an integer of some kind. Therefore the comparisons will need quoted constants, and the default value must be an integer.

Code: Select all

If InLink.Name = "a" Then 1 Else If InLink.Name = "b" Then 2 Else If InLink.Name = "c" Then 3 Else -99
If there will never be any value apart from "a", "b" or "c" then there is an easier solution.

Code: Select all

StringToInteger(Convert("abc","123",InLink.Name))
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
shaonli
Participant
Posts: 80
Joined: Tue Nov 28, 2006 6:52 am

Post by shaonli »

I have just given a example the data type are same for i/p and o/p.

I can't pass the i/p(apart from those values) for default.

The case is that apart from those three condition I don't want to pass
record.I just want to end the last Else without giving any value.
Please suggest.

Thanks
Shaonli
shaonli
Participant
Posts: 80
Joined: Tue Nov 28, 2006 6:52 am

Post by shaonli »

I have just given a example.But in real case the data type are same for i/p and o/p.

I can't pass the i/p(apart from those values) for default.

The case is that apart from those three condition I don't want to pass
record.I just want to end the last Else without giving any value.
Please suggest.

Thanks
Shaonli
rjhcc
Premium Member
Premium Member
Posts: 34
Joined: Thu Jan 27, 2005 4:20 pm

Post by rjhcc »

If you want to pass no value, consider passing a null or space ifyou still want the record, but with no value. Otherwise, you may as well reject the record.
rjhcc
AmeyJoshi14
Participant
Posts: 334
Joined: Fri Dec 01, 2006 5:17 am
Location: Texas

Post by AmeyJoshi14 »

shaonli wrote:The case is that apart from those three condition I don't want to pass
record.I just want to end the last Else without giving any value.
Please suggest.

Thanks
Shaonli
You can use stage variable... :!:
The value of stage variable goes like this:
if name=a
then 1
else
if name=b then 2
else name -------->svr1

Now in derivation(output Link) :
if svr1=name
then
3
else
svr1 -------->Output column

Is that what you want? :?:
AmeyJoshi14
Participant
Posts: 334
Joined: Fri Dec 01, 2006 5:17 am
Location: Texas

Post by AmeyJoshi14 »

The above post will not reject the records...if name <> c it will still assign the value 3(if the two conditions are not matched)...means supppose the values for name are a,b,c,d then for last column it will give value as 3..so your output will be 1,2,3,3.
As per my understanding the last value sholud be rejected...right?? :?

For that modify stage variable svr1, your stage variable derivation logic will be like this:
if name=a
then 1
else
if name=b
then 2
else
if name=c
then 3
else
name ------>svr1

and in the constraint put the condition as : svr1<>namethe output will have only stage variable value:
svr1 -------->Output column

Then your output will be 1,2,3.

This will give you the desired result.... :wink:
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can't pass the row "without any value". Your choices are to pass null (either in-band or out-of-band) or constrain the output so that rows are only passed if the input value of name is "a", "b" or "c".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply