cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting last 4 digits using graphical mapping.

Former Member
0 Kudos

Hi,

I have a requirement where I need to extract last 4 digit of an account number and pass the value to target field.

I dont want to use UDF. Is this possible without UDF?

We can extract the first 4 digit of the number using substring function in message mapping.

Pointers on this will be much appreciated.

Thanks

Ray..

Accepted Solutions (1)

Accepted Solutions (1)

Shabarish_Nair
Active Contributor
0 Kudos

if the input string always has a fixed length , then you can use the standard substring function

Former Member
0 Kudos

The input length is dynamic.

I think the input length can be made to fix by adding leading zeros.

Once I get the fixed length, how can I achieve to get last 4 characters of the string?

Shabarish_Nair
Active Contributor
0 Kudos

look into - http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/frameset.htm

substring

Returns a substring O for a string I. Use the dialog for the function properties to specify the position of the substring.

Example: substring(u201CHellou201D, 0,1) = u201CHu201D, means that the substring from Startindex 0 to Endindex 1 (not including position 1) is shown.

As above provide your start and end index for the input string.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Why dont use a simple UDF to achieve this. Just single line of code only...

Doing UDF is elegant way and even if your length input varies in business, you dont need to change the coding too.

Type: Argument Name: var1 Java Type: String

public String lastFourCharacters(String var1, Container container) throws StreamTransformationException{

     return var1.substring(var1.length-4, var1.length);

}

Connect source field --> lastFourCharacters --> target Field

This will work for any dynamic input string from the source.

Former Member
0 Kudos

So this will not work with dynamic string length to extract the last 4 digit?

UDF is the only option?

Shabarish_Nair
Active Contributor
0 Kudos

the substring standard function will only work on constant length. for dynamic, it is best to code a UDF since you will have better flexibility and error handling in place.

Former Member
0 Kudos

Thanks for the pointers.

I am going with udf for this mapping since I have dynamic string input.

Thanks

Ray...

Answers (0)