Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Quick formula to get the last 3 characters of the string

Former Member

Hi,

I need ABAP code on how to get the last three characters of a string.

For example, the string is 2008000

I need to get the last 3, which in this case happens to be 000.

thank you

1 ACCEPTED SOLUTION

Former Member

len = strlen ( variable ) - 3.

last_three = variable+len(3).

6 REPLIES 6

Former Member
0 Kudos

hi AG,

do this way ..


data : v_string type string,
       v_newstring type string,
       v_temp(10), 
       v_target type string. 

v_string = '280000'.

CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = v_string 
LANG = 'E'
IMPORTING
RSTRING = v_newstring
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.

v_temp = v_newstring.
v_target = v_temp+0(3). 

Regards,

Santosh

Message was edited by:

Santosh Kumar Patha

Former Member

len = strlen ( variable ) - 3.

last_three = variable+len(3).

0 Kudos

There is no need to abbreviate. This was done in the 1970's to save disk and memory space.

Former Member
0 Kudos

hi,

DATA: LV_LEN TYPE I.

DATA : LV_LAST3(3) TYPE C.

DATA : LV_STRING(10) TYPE C.

LV_STRING = '576483738'.

LV_LEN = STRLEN( LV_STRING ).

LV_LEN = LV_LEN - 3.

LV_LAST3 = LV_STRING+LV_LEN(3).

WRITE LV_LAST3.

tHANKS

mAHESH

JurgenLootens
Participant
0 Kudos

Or clearer:

offset = strlen ( variable ) - 3.

last_three = variable+offset(3).

rakeshdevani
Explorer
0 Kudos
data: lv_Input type string value '28930002'.
data(lv_len) = strlen( lv_input ).
data(lv_index) = lv_len - 3 .


assign lv_input to field-symbol(<fs_temp_data>).
data(lv_last_three) = <fs_temp_data>+lv_index(3).
write / lv_last_three.