on 02-24-2011 12:47 PM
Hello everybody,
is there an opportunity to use the substring method of message mapping with dynamic parameters and without using a UDF?
Because my requirement is that in an input string there is a semicolon, but not always on the same position. I need now the substring from the beginning to the position of the semicolon. Do you have any ideas how to realize this requirement?
Thanks a lot.
Best Regards
Martin
Hi Martin,
First get the index of ';' in the string using indexOf text function in graphical mapping.
for indexOf function pass String for first parameter and a constant ";" as second parameter.
Then write a UDF with just a return statement
Pass the String as var1 and the out put of indexOf[;] as var2
public String subStr(String var1, int var2, Container container) throws StreamTransformationException
{
return var1.substring(0,var2);
}
you will get the substring from the begining of the string up to semicolon as the output.
hope this satisfies you requirement.
Regards,
Aravind
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works nicely, but its surprising to me that a graphical substring function with dynamic inputs does not exist from SAP!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
you can not do that dynamically. you need an udf. the solution proposed solves your issue. try using something like this in combination with find first or first occurence of:
public String Mid(String input, String start, String noChars, Container container){
int no = Integer.parseInt(noChars);// this will throw an exception if the noChars is not an integer
int pStart = Integer.parseInt(start);
if (pStart > input.length())
return ""; // the starting position is after the end of the string so we can safely return ""
no += pStart; // now variable no, does not contain only the number of characters but the index where the substring should stop.
if (pStart + no > input.length())
no = input.length();
return input.substring(pStart,no);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Martin,
If position of semicolon in substring is determined at runtime, I guess you need to use UDF.
if(!value.equals("")){
value = value.substring(0,value.indexOf(";"));
}
return value;
-Rahul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.