cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion

former_member223432
Participant
0 Kudos

Hi experts,

Can someone please help me in converting the Alphanumeric to a number? i just have to delete the alphabets in the string and retain the numbers,

kindly help me.

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

A simple find/replace using Regex would handle your requirement


Source -> removeContext -> UDF -> Target

UDF code is as follows:

Arguments: input

Execution Type: Context Type


for(int a=0;a<input.length;a++){
   result.addValue(input[a].replaceAll("(\\D)",""));
}

Hope this helps,

Mark

former_member223432
Participant
0 Kudos

Hi Mark,

When i run this UDF,i am gettin an error..can you please help me with this..

Function getNumeric, Line 1:

cannot find symbol

symbol : variable length

location: class java.lang.String

for(int a=0;a<input.length;a++){

^

Function getNumeric, Line 2:

array required, but java.lang.String found

result.addValue(input[a].replaceAll("(
D)",""));

^

Function getNumeric, Line 2:

cannot find symbol

symbol : variable result

location: class com.sap.xi.tf._MM_Test

result.addValue(input[a].replaceAll("(
D)",""));

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You should use Context type UDF instead of Simple one. Change the execution type and this should work.

Hope this helps,

Mark

former_member223432
Participant
0 Kudos

Hi mark,

Thanks for your quick reply.

when i change execution type to "All values of context" i am getting another Resultlist also..but in code we are not passing the values to resultList right..

I have provide the following details.

Execution type: All values of context

category: user defined

Argument: Input--string

Result result ResultList

for(int a=0;a<input.length;a++)

{

result.addValue(input[a].replaceAll("(
D)",""));

}

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

when i change execution type to "All values of context" i am getting another Resultlist also..but in code we are not passing the values to resultList right..

The ResultList is normal. The return type is void, so you have to use the ResultList via result.

Argument: Input--string

Result result ResultList

Java is case-sensitive, so if you will use Input, better change the code to


for(int a=0;a<Input.length;a++)
{
result.addValue(Input[a].replaceAll("(D)",""));
}

Hope this helps,

Mark

former_member223432
Participant
0 Kudos

problem solved..thanks mark..

Answers (0)