Skip to Content
0

To split the input string based on condition in mapping SAP PI 7.5

Apr 30 at 11:07 AM

55

avatar image

Hi Experts,

My requirement is to split the input string if it is more than 35 characters, then populate the first 35 to one target field & rest of characters to second target field. Else if length is less than 35 characters then populate the input string to first target field.

Please suggest whether we require UDF or can be done using functions in graphical mapping.

Thanks,

Ramu.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Liz Jin
May 01 at 05:52 AM
1

Hi Ramu,

You can simply use the function of If and substring("", 0, 35) to fulfill your requirement. I just tested in my local PI system, the result is as expected. Please check the following screen of the mapping design:

If anything unclear, get back to me.

Best Regards,

Liz


mapping-35.png (19.4 kB)
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Liz,

Thank you for your snippet:)

But what if the input field is NULL value? How to handle NULL values in input field here?

Thanks,

Nithin.

0

Hi Nithin,

It depends on you. How do you want to treat this?

1. there must be error, if you input NULL by design.

2. but you also can do a check, if the input field is null, you set a constant value to it, and there will be no mapping error.

Best Regards,

Liz

0
Peter Karg May 02 at 08:14 AM
1

Hi Ramu,

I would do the same mapping as Liz for the first part. For a longer string you need a second substring also. On our PO 7.4 the substring function works only if your string has same or more characters needed for the substring function. To avoid problems I add always a constant with blanks and add later a trim function.

Regards

Peter

Share
10 |10000 characters needed characters left characters exceeded
dhivakar muthusamy May 02 at 01:15 PM
0

Hi Ramu,

Since you have to split the strings to two output fields if the length is greater than 35. you should go ahead with an UDF.

Because for the standard substring functions you need the length of the complete string.

eg: first target field will have 0..35 second target field should be passed with string starting from 36 till end. we don't know the complete length in this case.

Refer the attached Screenshots for the solution.

Mapwith Default function will avoid error in mapping as it will pass even the NULL value as empty field.targetfield1.jpgtargetfield2.jpgudf.jpg

Regards,

Dhivakar.


targetfield1.jpg (39.8 kB)
targetfield2.jpg (34.8 kB)
udf.jpg (62.4 kB)
Share
10 |10000 characters needed characters left characters exceeded