cancel
Showing results for 
Search instead for 
Did you mean: 

PI Mapping to split source into multiple Target fields based on "+" seperator

former_member1330829
Participant
0 Kudos

Hi experts,

I would like to know how to split a source string in XI mapping, based on "+" seperator.

eg: source : ABC|DEF|GHI

target1: ABC

target2:DEF

target3:GHI

How can this be achieved using UDF in mapping?

Regards

Accepted Solutions (1)

Accepted Solutions (1)

former_member191435
Contributor
0 Kudos

Hi Tanzoom,

Please use below udf

String[] arg = a[0].split("+");

for(int j=0; j<arg.length; j++)

{

result.addValue(arg[j]);

}

after this udf  u can use INDEX function

for Index1 u can use target 1

for index2 u can use target2

Let mw know if u face any issue...

Thanks,

Sreenivas

former_member1330829
Participant
0 Kudos

Hi Sreenivas,

There is a small correction in the UDF. it should be

String[] arg = a[0].split("//+");

this udf results in an array with all the splitted values.

However, i am trying to get it as 2 different output strings which can be mapped to the target directly.

i.e ABC|DEF should result in

output 1: ABC

output 2: DEF (not in array)

Please let me now if this can be achieved.

Thanks

former_member191435
Contributor
0 Kudos

Hi  Tanzoom,

Please find below screen shots for your query...

Please let me if u face any issues..........

former_member1330829
Participant
0 Kudos

Thanks Sreenivas. will test and let u know

former_member1330829
Participant
0 Kudos

hi Sreenivas,

I wanted to modify this UDF to include an empty value, ie

If Source: ABC|DEF|GHI

Target1 : ABC

Target2: DEF

Target3: GHI

else if Source = ABC|DEF - the udf should  not fail in this case and instead the target should get blank

Target1: ABC

Target2: DEF

Target3:  (Blank)

any pointers for this?

former_member191435
Contributor
0 Kudos

Hi Tanzoom...

Do the corresponding mapping based on your requirement....

Please let me know still face any issue....

Thanks,

Sreenivas

former_member1330829
Participant
0 Kudos

Works perfect, Thanks:)

former_member1330829
Participant
0 Kudos

Hi Sreenivas,

I need to modify this UDF to serve the below purpose,

eg: source : ABC|

target1: ABC

target2:blank

target3:blank

The UDF throws a string out of bound exception for the third field in this case.

Any pointers?

Answers (3)

Answers (3)

former_member1330829
Participant
0 Kudos

Hi All,

I am trying to have someting without the use of string tokeniser. Some java function with split?

Harish
Active Contributor
0 Kudos

Hi Tanzoom,

you can refer the UDF provided by Sreenivas is earlier reply.

regards,

Harish

Former Member
0 Kudos

public String SplitString(String var1, int var2, String separator Container container) throws StreamTransformationException{

String str = var1;

String[] value;

/* given string will be splitted by the argument delimeter provided. */

value = str.split(separator);

/* print splitted substrings - var2 (01,2,3 etc...) is the index you can define as parameter and call in each target field*/

return value[var2];

baskar_gopalakrishnan2
Active Contributor
0 Kudos

http://wiki.scn.sap.com/wiki/display/Snippets/taking+strings+apart+using+StringTokenizer

To do udf, it is very simple . Pass the input value  and use java class stringtokenizer  to extract string from  "+"  token from the string.

You can follow the above wiki as code snippet to do this.. In your case use '+' instead of ''," given in the example.

iaki_vila
Active Contributor
0 Kudos

Hi Tanzoom,

Check this thread , you have some options to do it

Regards.