on ‎2008 Jul 28 12:22 PM
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
Request clarification before answering.
Hi,
Use length function for actual length if it is less than the length make your own logic.
Thanks,
RamuV
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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;
}
}
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' expectedThanks
Shirin
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...
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' expectedAny suggestion what might be worong
Thanks
Shirin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi shirin,
Check with the braces.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Use the combination of length, if and substring function in the graphical mapping
Thanks
SaNv...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
this is the property of substring function if the value is less then the defined value it will through an error.
if you are felxible with having value in only one part e.g. 10 char then go for UDF. just write an UDF and inside udf code you can take values based on incoming value length.
Regards,
Sarvesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shrin,
best way is to write UDF (Java) . get the length of the String and based upon the length u can write u r code to get the string first three or watever u requirment is demanding
rgds
srini
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 8 | |
| 7 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.