cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping - Identify a number in a sting

Former Member
0 Kudos

Hello Guys,

There is a requirement to perform a conversion based on its length.

If the length of the incoming field is less than or equal to 20 characters pass the string directly to the target field.

If the length is more than 20 then find the number of excess characters and remove that many number of characters from the string before the first occuranace of number in the string to make the total length as 20 chars.

As an example, lets say if I have a string with a length of 22 like this " I have 4 books at home"

In the string 2 chars have to be removed before the number 4, so that it has to look like "i hav4 books at home" which of length 20 char.

Some more examples :

"I have 14 keys and 1 pen" should be converted to "I h14 keys and 1 pen" (4 excess chars "ave " has been removed)

Have used this UDF and many combinations but that didn't work :

____________________________________________________________________________________________

public String test2(String STREET1,Container container){ //STREET1 is the incoming field

int input = STREET1.length();

int Length = 30;

int a,b,c;

int Loc = -1;

String str = "";

String str1, str2 = "";

if(input<=30)

{

str = STREET1;

}

//else

// {

for (int i = 0; i < STREET1.length(); i++)

{

if (Character.isDigit(STREET1.charAt(i)))

{

Loc = i;

}

}

// No digit found, so truncate to 30 length streetStr

if (Loc == -1)

{

str = STREET1;

}

// Digit found

else

{

a = input - Length;

b = Loc - a;

c = input - Loc;

str1 = STREET1.substring(0,b-2);

str2 = STREET1.substring(Loc,c);

str = str1" "str2;

}

return str;

-_________________________________________________________________________________________________-

Please correct the code or provide a workaround.... Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

this should be your code. I make a test with "I have 14 keys and 1 pen" and my result is "I h14 keys and 1 pen".

Regards, Björn

int input = text.length();

int Length = 20;

int a,b,c;

int Loc = -1;

String str = "";

String str1, str2 = "";

if(input<=Length)

{

str = text;

return str;

}

for (int i = 0; i < text.length(); i++)

{

if (Character.isDigit(text.charAt(i)))

{

Loc = i;

break;

}

}

// No digit found, so truncate to 30 length streetStr

if (Loc == -1)

{

str = text.substring(0,Length);

}else

{

a = input - Length;

b = Loc - a;

c = Length - Loc;

str1 = text.substring(0,b);

str2 = text.substring(Loc,input);

str = str1""str2;

}

return str;

Answers (2)

Answers (2)

Former Member
0 Kudos

Swetha,

I have not used such a declaration anywhere in the UDF, but still the error is referring the st.testexecute method and the public String argss[]. No idea about this strange behaviour.

Thanks,

Former Member
0 Kudos

Hi Vuppala,

The function is working correct only. I think you are not sending any input parameter. It should like this.Create a value udf and name it is IdentifyString with one input parameter text. Then add this code:

Imports: java.;*

public String IdentifyString(String text,Container container)

//write your code here

Add the whole code given by him.

Then it should get the required output. The only thing you wrong is I think you are not passing any input parameter.

Regards,

---Satish

Former Member
0 Kudos

Hi Bjorn,

There is not much change in the code. Even after implementing the new code,

I am getting the same errors as earliier. 3 errors are displayed which has the same description.

Error Desc :

C:/usr/sap/IDV/DVEBMGS01/j2ee/cluster/server1/./temp/classpath_resolver/Map0d3b3110875011deaa330018fe866e58/source/com/sap/xi/tf/_SAP_DESADV_DELVRY05_TO_VDA_CustomerDelivery_.java:1080: unreachable statement public static void main(String[] args) throws Exception{/!_$ClNRep_/_SAP_DESADV_DELVRY05_TO_VDA_CustomerDelivery_ st = new /!_$ClNRep_/_SAP_DESADV_DELVRY05_TO_VDA_CustomerDelivery_(); st.testExecute(); }

Please suggest, Thanks

shweta_walaskar2
Contributor
0 Kudos

Hi Raghavenrdra,

Error says:

unreachable statement public static void main(String[] args) throws Exception

where do you have this statement ?

Regards,

Shweta

Former Member
0 Kudos

Hi

I use the code above and it's work...only put a parameter call "text" is a simple function.