cancel
Showing results for 
Search instead for 
Did you mean: 

subtring

Former Member
0 Kudos

Dear SAP PI Guru,

I am using a substring function to get the 3st last char of the string but the mapping fails. I can only have the first 3st if the input how can I handle this? do we have to write a UDF for this?please help

Thank in advance.

ombessa

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ombessa,

Here is the UDF which matches your requirement. I think its not possible to get last three charcters using standard text functions available in graphical mapping.


public static String lastThreeChars(String s)
	{
		try
		{
			s=s.substring(s.length()-3);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return s;
	}

For input "Hello" you get output "llo".

Regards

Anupam

Former Member
0 Kudos

Hi Anupam,

thanks you so much for the Input the udf work fine.

Kind regards.

Ombessa

Answers (1)

Answers (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

you can handle both in standard function or udf. But doing udf is simple in this case.

Create a UDF function with name like lastThreeCharacter and variable type String input

return input.substring(input.length()-3, input.length());

The above function return last three characters of the input value.

Use source field --> lastThreeCharacter --> Target field

Hope that helps. Very simple.