on 09-21-2011 7:52 AM
Hi Experts,
I have one scenario in which i have amount field in Data type.
I have to create one UDF which will do the following thing.
1. If the amount field is Null it should throw an exception in mapping.
2.If the amount field is 0.00 it should throw an exception in mapping.
3. For all other cases it should pass the amount value to the target.
Can anyone provide me the code For this UDF.
Thanks in advance.
chk this:
Execution type: single value
mapping:
Source -Mapwithdefault(a)-UDF----Target
if(var1.equals("a") || var1.equals("0.00"))
{
throw new RuntimeException("Invalid Input");
}
else
{
return var1;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
mapwithdefault will take care of ur null values(in a sense if source filed does not exist then mapwith default will op the value "a") ....and in the udf depending upon the existence of "a" (u can change it to any value) it will throw the exception
>>while saving this it is giving java.lang exception
i have tested this code and its working fine
Hi,
You can add this logic to the UDF. Here var1 is the input string.
java.math.BigDecimal b=new java.math.BigDecimal(var1);
if(b.compareTo(new java.math.BigDecimal("0.00"))<=0)
{
//write your logic for values less equal to zero
}
One small request, if you think your question has been answered, properly and correctly, could you please kindly if possible close down this thread. It helps people who look for solutions to similar problem.
regards
Anupam
can anyone help me regarding the approach told by Raj or any other approach.
I am not sure how to use Fixvalues function.
what should i give in default value,Key1,Key2 fields in Fixvalues function and what should be the behavior.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fixvalues function is under standard function - Conversions
FixValues
Executes a value mapping using a fixed value table that you complete using the function properties. The table is saved together with the most current message mapping and can only be used once.
Here maintain default as true, Key1 as 0.00, value for key1 false, Key2 as <empty>, value for key2 false.
Rest you can map as I mentioned above.
Hope this helps you.
Regards
Raj
Gaurav
You can achieve it even without UDF.
Use fixValue function with keeping output as false for null (don't pass any input) and 0.00. And true in default value. Now take this output as an input to first parameter of ifWithOutElse and pass the actual value in second parameter of ifWithOutElse.
Regards
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.