ABAP – Getting last character of string

data: var1 type string,
      len type i,
var2 type i.   
var = 'abc1234f'.
len = strlen( var ).
var2 = len - 1.
write: 'The last character is', var1+var2(1). //Output: The last character is f.
In the last line var1+var2(1) ,
var1+var2 indicates the 8th character of the string that is "f" in the example. 
var1+var2(1) means beginning from the var2 position , number of character is 1. 
If you want last 3 character then replace 1 by the required number 3 that you want.

0 Comments

Leave A Reply