on 12-12-2007 1:54 PM
Hi,
I'm starting with UDF functions.
How can i split source string at '-' and take first part into target.
ex : 123-456 -> 123
Easy points for those who know...
Thanks in advance,
Laurent.
Laurent,
Create a <i><b>Value</b></i> user defined function and name it as <b><i>replace</i></b>. Take one argument as <i><b>a</b></i>.
Import: java.*;
Add this code:
int i = a.indexOf("-");
a = a.substring(0,i);
return(a);
Then map like this:
source --> replace(udf) --> Target
This will always take the value before -.
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for all supports
Satish,
thanks it worked immediately.
Nikhil,
I tried your code but there was still error message with array missing.
java:2079: array required, but java.lang.String found String temp = a[0].toString();
Regards,
Laurent
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi laurent,
<b>use advanced udf</b>
int i = 0;
String temp = a[0].toString();
i = temp.indexOf('-');
result.addValue(temp.substring(0,i));
thanks and regards
nikhil bos
<i>**reward if helpful
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 substring function provided in the text function.
input field->substring-->output value
Thanks
Rinku
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Laurent,
Use an Advanced User Defined Function. Adavnced user Defined Functions can return Multiple values.
UDF1:
1.Takes renmark as input.
2.Does the split on the basis of ;
3. Splits each split of step 2 on the basis of /
4. Add the output of step 3 to the resultlist with a context change.
UDF2:
1.Takes renmark as input.
2.Does the split on the basis of ;
3. Splits each split of step 2 on the basis of /
4. Add the output of step 3 to the resultlist with a context change.
For Advanced UDF's,
http://help.sap.com/saphelp_nw04/helpdata/en/f8/2857cbc374da48993c8eb7d3c8c87a/content.htm.
You can try this piece of code in your mapping...
You need 3 UDFs each for <detail>, <field1>,<field2>
UDF1: For <detail>
String arr[] = a[0].split(";");
for (int i=0;i<arr.length;i++)
result.addValue(arr);
UDF2: For ><field1>
String str = a[0];
String str1 = null;
String sarr1[] = str.split(";");
for (int i=0; i<sarr1.length;i++)
{
str1 = sarr1;
String sarr2[] = str1.split("/");
for (int j=0; j><sarr2.length;j++){
result.addValue(sarr2[j]);
j++;
}
result.addContextChange();
}
UDF2: For ><field2>
String str = a[0];
String str1 = null;
String sarr1[] = str.split(";");
for (int i=0; i<sarr1.length;i++)
{
str1 = sarr1;
String sarr2[] = str1.split("/");
for (int j=0; j><sarr2.length;j++){
j++;
result.addValue(sarr2[j]);
}
result.addContextChange();
}
..All these functions requires one input <remark>
Hope this helps you ..
*Reward with points if helpful*
Regards,
Shibani
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 charAt() function and just do nothing after getting the character "-".ie avoid next characters or break..
regards
Aashish Sinha
PS : reward points if helpful
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You need to define the input Array also.. then copy paste my program.
<b>The error says :
array required, but java.lang.String found String[] vals = a[0].split("-");</b>
Remove these lines and put an array for input and then use the program exactly as mine.
Regards
Aashish Sinha
PS : reward points if helpful
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.