on 05-31-2011 1:10 PM
Hi,
I am getting the 4 fields of data in single field from souce system, i need to send to target side with 4 Diffrent Fields. I want to separate the data based on (/).
I think for this I need 4 UDF's, Pls let me know the UDF's for this requirement. I am new to UDF's.
Example :
Source Field:
EmpNo / EmpName / EmpAddress / EmpPhone
Target fields:
EmpNo
EmpName
EmpAddress
EmpPhnoe
Mapping
EmpNo / EmpName / EmpAddress / EmpPhone -
> EmpNo
EmpNo / EmpName / EmpAddress / EmpPhone -
> EmpName
EmpNo / EmpName / EmpAddress / EmpPhone -
> EmpAddress
EmpNo / EmpName / EmpAddress / EmpPhone -
> EmpPhone
Regards,
Pasi.
Hi Pasi,
the UDF that you can use is:
public String splitStringBySeparator(String field1, int cont, String separator, Container container) throws StreamTransformationException{
String ret="";
int indexRupture=0;
for (int i=1;i<=cont;i++){
if (field1.indexOf(separator,indexRupture) >= 0)
ret=field1.substring( indexRupture,field1.indexOf(separator,indexRupture));
else
ret = field1.substring( indexRupture, field1.length());
indexRupture = field1.indexOf(separator,indexRupture) + 1;
}
return ret;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I think for this I need 4 UDF's, Pls let me know the UDF's for this requirement. I am new to UDF's.
Not sure about PI 7.0 and below, but for PI 7.1 you can create a context type UDF with four result sets
Argument: input
Result: empNo
Result: empName
Result: empAddress
Result: empPhone
UDF code is:
String temp[] = input[0].split("/");
empNo.addValue(temp[0]);
empName.addValue(temp[1]);
empAddress.addValue(temp[2]);
empPhone.addValue(temp[3]);
Mapping is like this:
Source -> UDF -> EmpNo
|---> EmpName
|---> EmpAddress
|---> empPhone
Hope this helps,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
create one UDF:
Input will be : a & b
String[] var = a[0].split("/");
int pos = Integer.parseInt(b[0]);
result.addValue(var[pos] );
mapping will be :
input -
-
UDF---EmpNo
constant(0)
input -
-
UDF----EmpName
constant(1)
input -
-
UDF----EmpAddress
constant(2)
input -
-
UDF----EmpAddress
constant(3)
Thanks
Amit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try this
String[] arg = a[0].split("/");
for(int j=0; j<arg.length; j++)
{
result.addValue(arg[j]);
}
after UDF put the index standard function, and set the proper index for each field. remember. if you are ussing PI 7.1 you can put many fields in same source field
i mean.
<field1>----UDF---index(0)-----<field1>
---->Index(1)---<field2>
---index(2)-----<field3>
---->Index(3)---<field4>
let me know if you face any error or doubt
Thanks
Rodrigo
Edited by: Rodrigo Alejandro Pertierra on May 31, 2011 10:23 AM
>>I already tried with that, but its not working, in mapping(Source) same field i have to use 4 times, but in target side 4 diffrent fields. In my Previous post i given my sample mapping.
If your PI version is 7.1 and above, you can achieve in single UDF. As previous replies mentioned, create a UDF with java split method and store the values in string array. Use the same UDF for mapping by passing array index 0,1,2,3 for the 4 respective target fields. Basically you use resultlist value for the target fields.
Hi Rodrigo,
thank you for your suggestion,
I am using PI 7.0.
Please let me know what i need to mention in Index Function.I tried with giving the value in Initial Value (10) same value is coming in Output (10)
I am able to see the
Initial Value
Increment
Count Indices In
Please suggest.
Regards,
Pasi.
Hi
I am using PI 7.0.
Please let me know what i need to mention in Index Function.I tried with giving the value in Initial Value (10) same value is coming in Output (10) I am able to see the Initial Value
in the index function you need to set the index value you want to get.
define this
<field1>----UDF---index(0)-----EmpNo
---->Index(1)---EmpName
---index(2)-----EmpAddress
---->Index(3)---EmpPhone
so i my example when you set value "0" the index funtion you will get the EmpNo value
if you set the value "1" you will get the EmpName a so on.
let me know.
i dont remember if you able to define this kind of mapping in PI 7.0. i you cannot. soyou should call the UDF for each target field.
Let me know.
Rodrigo P-.
User | Count |
---|---|
84 | |
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.