cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for Separating the Fields

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (5)

Answers (5)

0 Kudos

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;

}

markangelo_dihiansan
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

former_member463616
Contributor
0 Kudos

Hi,

You have to use delimiter as "/".

Like,

String[] temp;

String delimiter = "/";

temp = input.split(delimiter);

Please see the below thread, it will useful to you.

Regards,

P.Rajesh

Former Member
0 Kudos

You need to split the fields. Check the thread below for some coding solutions:

Basically you will use a String[] values = string.split("/"); and then you will be able to access each value by using value[0], vlaue[1] and so forth.

Former Member
0 Kudos

Hi Lucas,

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.

Can you pls suggest.

Regards,

Pasi.

Edited by: pasi s on May 31, 2011 3:03 PM

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

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

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>>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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hi Pasi,

I would rather suggest AmitSri's solution. Quite straightforward and when you use constants there are no context issues as well.

Regards,

Ninu

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

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-.