# UDF to multiply 2 Fields in incoming Message

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

10|10000 characters needed characters exceeded

### Related questions

Former Member
Posted on Dec 23, 2008 at 07:24 AM

hi ,

try this code

if (a.equals(""))

return "0";

else

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

10|10000 characters needed characters exceeded
• Posted on Dec 23, 2008 at 07:44 AM

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

10|10000 characters needed characters exceeded
• Former Member

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

• Former Member
Posted on Dec 23, 2008 at 08:56 AM

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:

New Arithmetic and Statistical Functions in Message Mappings in SP18

Regards

Patrick

10|10000 characters needed characters exceeded
• Former Member

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

Regards,

Sarvesh

• Former Member
Posted on Dec 23, 2008 at 07:16 AM

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.

10|10000 characters needed characters exceeded
• Posted on Dec 23, 2008 at 07:33 AM

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!