cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to multiply 2 Fields in incoming Message

vinotha_m
Participant
0 Kudos

Hi Everyone,

We have a scenario wherein there are 2 fields in the source structure , Quantity and Price.( Both of them are string type in Data type)

We have to multiply these and assign to target field of type string.

This causes an exception of No cast to float.

I am not aware of Java coding. Please provide me with UDF code required.

Thanks,

Vinotha M

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi ,

try this code

if (a.equals(""))

return "0";

else

return (Float.parseFloat(a))*(Float.parseFloat(b)) + "";

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

it's possible to use (most) of the standard functions with XI 3.0 SP >= 18 and PI 7.0 SP >= 9 by setting the parameter com.sap.aii.mappingtool.flib3.bigdecimalarithmetic to true as described here:

Regards

Patrick

Former Member
0 Kudos

Thanks Patrick for giving this information(solution), as I forgot to mention this in my reply.

Regards,

Sarvesh

Shabarish_Nair
Active Contributor
0 Kudos

Why go for a UDF when you can actually use the multiply standard function itself? Use that and avoid the UDF.

http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm

Former Member
0 Kudos

Hi,

I would like to add few of my lines here...

What Vijay has said is correct, use standard function to multiply two values but make sure you are getting the correct result. The reason whay I am saying so is, most of the time standard function (Arithmatic function) gives the wrong result (in XI 3.0).

Let's say you if you multiply string 12345678 * 100 = 1234567808 (wrong result)

So in this case go for an UDF as suggested by experts in above replies.

Regards,

Sarvesh

SudhirT
Active Contributor
0 Kudos

Vinotha,

Use simple UDF not advance and pass the input values as the source fields say a and b.

and try this code

double c;
c =Double.parseDouble(a)*Double.parseDouble(b);

return ""+c;

Thanks!

former_member859847
Active Contributor
0 Kudos

Hi,

Please use the following simple code for MUL.

take String a,String b,String c.

c =Double.parseDouble(a)*Double.parseDouble(b);

return c;

warm regards

mahesh.