Page 1 of 1

Problem in if then else coding in transformer

Posted: Thu Jan 17, 2008 4:45 am
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

Posted: Thu Jan 17, 2008 5:19 am
by keshav0307
If name=a then 1
else
if name=b then 2
else
if name=c then 3
else
''

Re: Problem in if then else coding in transformer

Posted: Thu Jan 17, 2008 5:21 am
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!!

Posted: Thu Jan 17, 2008 5:33 am
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

Posted: Thu Jan 17, 2008 5:49 am
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))

Posted: Thu Jan 17, 2008 7:02 am
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

Posted: Thu Jan 17, 2008 7:04 am
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

Posted: Thu Jan 17, 2008 7:44 am
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.

Posted: Thu Jan 17, 2008 8:10 am
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? :?:

Posted: Thu Jan 17, 2008 8:41 am
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:

Posted: Thu Jan 17, 2008 4:21 pm
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".