Skip to Content
author's profile photo Former Member
Former Member

Mappping error in UDF

Hi

I have to remove leading zeroes from an alphanumeric string. I used the code in this link

http://wiki.sdn.sap.com/wiki/display/Java/RemoveLeadingandTrailingZerosfroma+String

if (str == null){

return null;}

char[] chars = str.toCharArray();

int index = 0;

for (; index < str.length();index++)

{

if (chars[index] != '0'){

break;}

}

return (index == 0) ? str :str.substring(index);

}

I am using XI 7.1 and I am getting errors when I trried to run it in Message Mapping

Java:90: 'class' or 'interface' expected public void init(GlobalContainer container) throws StreamTransformationException{ ^

java:130: 'class' or 'interface' expected public static void main(String[] args) throws Exception(); st.testExecute(); }

java:131: 'class' or 'interface' expected }

Java:132: 'class' or 'interface' expected ^ 4 errors

Any idea why I am getting this error ?

Regards

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Nov 09, 2011 at 08:25 AM

    use below code snippet

    s is input argument to UDF.

    String s1=s.replaceFirst("^0+(?!$)", "") ;
    return s1;

    Regards,

    Raj

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 09, 2011 at 08:11 AM

    Hi Ajith,

    first you need to pass your string as a input, in your case argument missing.

    try using format number standard fuction.

    Regards,

    Raj

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 09, 2011 at 08:17 AM

    Hello,

    Java:90: 'class' or 'interface' expected public void init(GlobalContainer container) throws StreamTransformationException{ ^

    java:130: 'class' or 'interface' expected public static void main(String[] args) throws Exception(); st.testExecute(); }

    java:131: 'class' or 'interface' expected }

    Java:132: 'class' or 'interface' expected ^ 4 errors

    Any idea why I am getting this error ?

    You should comment out the main method. Re-test and get back to us.

    Regards,

    Mark

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 09, 2011 at 09:57 AM

    Hi Ajit,

    There is no standard mapping function to check the alphanumeric. You need to write a small UDF to do this function.

    here is small code: this UDF takes one input(inString) value for which we check whether it is numeric or alphanueric

       
    		   catch(Exception e)   
    		   {  
    			  result = false;
    		      return result.toString();   
    		   } 
                            

    Above UDF gives true is inString is Numeric or false if it's not numeric (it means, inString is Alphanumeric).

    Also, check the below thread:

    Link: [http://forums.sdn.sap.com/thread.jspa?threadID=2058429&messageID=10728460#10728460]

    Thanks,

    RK

    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.