cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Mapping issue: Function 'Substring error'

Former Member
0 Likes
2,279

Hi All,

I have an incoming field of length upto 30 which needs to be split into 3 diff fields of length 10 each.

I used the function 'substring' in Mapping using the following range 0-10 and 10-20 and 20-30. It works fine if the string has all 30 characters.

If the string has only 10 characters, then the first field is poulated but for the remiaing 2 fields I get the error

Exception:[java.lang.StringIndexOutOfBoundsException: String index out of range: 10] in class com.sap.aii.mappingtool.flib3.TextFunctions method substring[185120, com.sap.aii.mappingtool.tf3.rt.Context@3d1048df]

I guess the issue is because string is only 20 caharcters long.

Is there any other way I can split the string without getting this error.

Many thanks

Shirin

View Entire Topic
Former Member
0 Likes

Hi,

Use length function for actual length if it is less than the length make your own logic.

Thanks,

RamuV

Former Member
0 Likes

Hi,

I do not know java. Can you help let me know a sample UDF to code this.

All I need is a UDF with 2 incoming parameters and 1 outbound.

Incoming:

1. for the data string.

2. Field no ( e.g 1 or 2 or 3)

Outbound:

1. Value of the substring

Logic would be like.

1. Read incoming string. If data found proceeed else error

2. Based on 2nd incoming filed determine whcih data string to be found. e.g if 2nd field = 2, then I need string 10 to 20. If 2nd field is 3, then i need data string 20 to 30 and so on.

Apprciate your help.

Many thanks

Shirin

GabrielSagaya
Active Contributor
0 Likes

function myudf(String a, String b, Container container)

{

int num=0;

int times=0;

int start=0;

try

{

num=Integer.parseInt(b);

times=num*10;

if (num>1)

start=(num-1)*10;

else

start=0;

if (a.length>times)

return a.subString(start,10);

else

return "No String found";

}catch(NumberFormatException nfe)

{

return "Exception occured"+e;

}

}

Former Member
0 Likes

Thanks Gabriel,

Am trying to use it but am getting the following errors

Source code has syntax error:  D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map7884ba305ca011ddcaaa001a4b52813a/source/com/sap/xi/tf/_MM_CONFIGURATION_.java:1168: 'class' or 'interface' expected public static void main(String[] args) throws Exception{/*!_$ClNRep_*/_MM_CONFIGURATION_ st = new /*!_$ClNRep_*/_MM_CONFIGURATION_(); st.testExecute(); } ^ D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map7884ba305ca011ddcaaa001a4b52813a/source/com/sap/xi/tf/_MM_CONFIGURATION_.java:1169: 'class' or 'interface' expected

Thanks

Shirin

Santhosh_Vellingiri
Active Contributor
0 Likes

Hi,

Try out this UDF..

public String test(String a,String b,Container container){
String err = "Error String";
 int val=Integer.parseInt(b);
if(val==1)
{
if(a.length()>10)
return a.substring(0,10);
else
return a.substring(0,a.length());
}
else if(val==2)
{
if(a.length()<10)
return err;
else if(a.length()>20)
return a.substring(10,20);
else
return a.substring(10,a.length());
}
return err;
}

Thanks

SaNv...

Former Member
0 Likes

Hi Santosh,

Thanks for the code.

I have copied/pasted ur code but upon activation I get the error:

Source code has syntax error:  D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map442ab5d05ca211dd81f7001a4b52813a/source/com/sap/xi/tf/_MM_CONFIGURATION_.java:1166: 'class' or 'interface' expected public static void main(String[] args) throws Exception{/*!_$ClNRep_*/_MM_CONFIGURATION_ st = new /*!_$ClNRep_*/_MM_CONFIGURATION_(); st.testExecute(); } ^ D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map442ab5d05ca211dd81f7001a4b52813a/source/com/sap/xi/tf/_MM_CONFIGURATION_.java:1167: 'class' or 'interface' expected } ^ D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map442ab5d05ca211dd81f7001a4b52813a/source/com/sap/xi/tf/_MM_CONFIGURATION_.java:1168: 'class' or 'interface' expected

Any suggestion what might be worong

Thanks

Shirin