Skip to Content
avatar image
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 comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    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 comment
    10|10000 characters needed characters exceeded

  • 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 comment
    10|10000 characters needed characters exceeded

  • 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 comment
    10|10000 characters needed characters exceeded

    • remove last curly bracket from the code

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

  • avatar image
    Former Member
    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 comment
    10|10000 characters needed characters exceeded