on 09-25-2008 1:13 AM
Hi folks
I need help in a context udf : pass arrays
Source field:
Array of values
Sun is bright,Moon shines
Ball is blue,table is brown
If we see there is a comma in source field and we pass an array of source values to a udf
In target i have 2 fields.
I want to extract the values from source before comma and map to the first target field
and the text after comma in the second target field.
Is it achievable in XI and I am not good in writing java udfs.
Help will be appreciated.
Thnx
Hi,
By using IndexOf , Length and Substring function from text you can solve this problem without using UDF.
1) Using IndexOf to check the index of (, or ;).
2) For 1st Target field use Substring, start with 0 and no. of char are (index of (, or - 1).
3) Then check total length of Input value by using Length function.
4) For 2nd target field use Substring start with (index of (, or + 1) and no. of char. are (total length - index of (, or )
Regards,
Rohit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have prepared word document with UDF code and Mapping screens,If you provide your email ID i can send it through.
Thanks,
Jag
************
Please read the Forum's Rules of Engagement,
i.e.,
[/thread/117188 [original link is broken];
and refrain from using email correspondence as the main objective of the Forums is to share knowledge.
SDN PI/XI Forum Moderator
Hi,
as you have two targets you will have two UDFs ( a is the parameter).
For the first string:
>int index = (a.indexOf(";") > a.indexOf(",")? a.indexOf(";") : a.indexOf(","));
>if (index > 0) {
>return a.substring(0, index);
>}
>return a;
For the second string:
>int index = (a.indexOf(";") > a.indexOf(",")? a.indexOf(";") : a.indexOf(","));
>if (index > 0) {
>return a.substring(index + 1, a.length());
>}
>return a;
You could also do it with one UDF if you pass another parameter b that you fill with a constant ( "1" in case of first target and "2" in case of second target).
The UDF looks then like this:
>int index = (a.indexOf(";") > a.indexOf(",")? a.indexOf(";") : a.indexOf(","));
>if (index > 0 && b.equals("1")) {
>return a.substring(0, index);
>}
>if (index > 0 && b.equals("2")) {
>return a.substring(index + 1, a.length());
>}
>return a;
Regards
Patrick
Edited by: Patrick Koehnen on Sep 25, 2008 10:45 AM
Hi,
This is very simple
1. goto initialization section
under golbal variable make a declaration for string array
String arr[];
2. you have to write 2 udf's
src---->splitsrc1--->tgt1
src---->splitsrc2--->tgt2
Use cache parameter as context for both UDF
3. udf-1
public void splitsrc1(String[] a,ResultList result,Container container)
{
//write your code here
arr = a[0].split(",");
result.addValue(arr[0]);
}
4. udf-2
public void splitsrc2(String[] a,ResultList result,Container container)
{
//write your code here
result.addValue(arr[1]);
}
Edited by: malini balasubramaniam on Sep 25, 2008 9:07 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this UDF:
here pass value FIRST or SECOND to 2nd parameter of the UDF (FIRST if u want value before comma and SECOND if want value after comma )
getValues(String str[], String position, Container ....){
int i= str.indexOf(",");
if(position.equals("FIRST")){
result.addValue(str.substring(0,i));
}else if(position.equals("SECOND")){
result.addValue(str.substring(i+1, str.length()) );
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Whats your XI version?
Its possbile with UDF code.
Thanks,
Jag
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
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.