Problem in if then else coding in transformer
Moderators: chulett, rschirm, roy
Problem in if then else coding in transformer
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
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
-
- Premium Member
- Posts: 783
- Joined: Mon Jan 16, 2006 10:17 pm
- Location: Sydney, Australia
-
- Participant
- Posts: 33
- Joined: Mon Nov 12, 2007 1:02 am
- Location: Bangalore
Re: Problem in if then else coding in transformer
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)??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
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
Bangalore
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
If there will never be any value apart from "a", "b" or "c" then there is an easier solution.
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
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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
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
-
- Participant
- Posts: 334
- Joined: Fri Dec 01, 2006 5:17 am
- Location: Texas
You can use stage variable...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
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?
-
- Participant
- Posts: 334
- Joined: Fri Dec 01, 2006 5:17 am
- Location: Texas
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....
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....
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.