cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for splitting a string

Former Member
0 Kudos

Hi,

I am relatively new to SAP PI. I have a requirement to write a UDF in the mapping program which i find it difficult to do using the mapping functions itself.

I will get an input in a field as "SampleItem-RequestB"

This string has to be splitted into two different fields based on the string "-"

The first field should hold the letters before the "-" and the next 35 characters after "-" should be put in the second field.

So, the output should be

first field ==> SampleItem

second field ==> RequestID (Upto 35 characters only)

Could you please help me in writing an UDF for this requirement since i am not good at writing Java scripts.

Thanks,

Aslam

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

At most, this needs two UDF (depending on the PI version).

SampleItem mapping


input -> UDF -> SampleItem

UDF type is single values (simple)

Arguments: input


return input.substring(0,input.indexOf("-"));

RequestID mapping


input -> UDF -> RequestID

UDF type is single values (simple)

Arguments: input


String temp = input.substring(input.indexOf("-")+1);
if(temp.length()>35)
	return temp.substring(0,35);
else
	return temp;

Hope this helps,

Mark

Former Member
0 Kudos

Thanks a ton for the quick response.

It ran successfully without any errors.

Thanks,

Aslam

Answers (0)