cancel
Showing results for 
Search instead for 
Did you mean: 

User defined function to check the NULL and 0.00 value in a Amount field

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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;
}

Former Member
0 Kudos

while saving this it is giving java.lang exception.

and in your approach where is the validation for null values.please help.

thanks in advance.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Amit,

i worked according to your approach.

the mapping is throwing exception in case of 0.00 and null values.

But it is also throwing exception in case of other values say i passed Rs1000 to amount then also exception in coming.

Thanks in advance.

Former Member
0 Kudos

Hi amit,

It is done with your approach.Thanks a lot

Former Member
0 Kudos

Hi Amit,

A new issue has arised in this UDF.

I have to check the amount field for every value <=0

But i am paasing value of amount as String and i can not chnge it to Integer.

I have tried typecasting for that.

But its not working for me.

Can you please help me regarding this.

Thanks in advance.

Former Member
0 Kudos

u want to throw an exception when the amount is <= 0.00 ( i guess u will also get decimal values)

chk this:



double d = Double.parseDouble(var1); 
 if(var1.equals("a") || d<=0.00  )
{
throw new RuntimeException("Invalid Input");
}
else
{
return var1;
}

anupam_ghosh2
Active Contributor
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

can you plese explain in more detail.

which value function to use and how to do it.