Skip to Content

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    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)) + "";

    Add a comment
    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

    Add a comment
    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

  • author's profile photo Former Member
    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    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.

    Add a comment
    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!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.