cancel
Showing results for 
Search instead for 
Did you mean: 

Mappping error in UDF

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

rajasekhar_reddy14
Active Contributor
0 Kudos

use below code snippet

s is input argument to UDF.

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

Regards,

Raj

Answers (3)

Answers (3)

Former Member
0 Kudos

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

markangelo_dihiansan
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Mark

The first line in my code is, public String calculate(String str, Container container) throws StreamTransformationException{ and that I can't edit.

The remaining lines are the ones that refer to the code in the wiki.

I don't see any main method in the call

Regards

Former Member
0 Kudos

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

rajasekhar_reddy14
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Raja

I am getting strings, so I can't use format number

I chose Execution Type as Single values, Argument Name as str and entered the code.

I wonder whether I have to import anything else

Regards

Former Member
0 Kudos

Hi Ajith,

For this single line code is enough.

create simple UDF and take 2 input values, first one is the original string and second one is the leading removal/delete value, then use the below code in that UDF.

return(inputStr.replaceFirst("^"value"+","")); //here inputStr is the actual string and value is the removal/delete parameter

Regards,

Venkata Ramesh

Former Member
0 Kudos

            Boolean result = false;
            try 
            { 
                    Long.parseLong(inString); 
                    result = true;
                    return result.toString(); 
             } 
            catch(Exception e) 
            { 
                    result = false;
                    return result.toString(); 
             } 
Former Member
0 Kudos

Thanks Raja

I used your code and it's working.

Thanks AmitSri, Rajendra

Thanks to everyone who contributed