Application Development and Automation 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: 
Read only

ABAP string functions

Former Member
0 Likes
2,269

What is the ABAP code to find the last three characters of a string?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,858

data : a type string,b type i,c type string,d type i.

a = 'abcdefghi'.

b = strlen( a ). "9

d = b - 3. "6

c = a + d(3). "ghi

write 😕 c.

10 REPLIES 10
Read only

Former Member
0 Likes
1,858

hi,

data : lv_string type string.

to get last 3 characters use the code

lv_string + 3.

Read only

Former Member
0 Likes
1,859

data : a type string,b type i,c type string,d type i.

a = 'abcdefghi'.

b = strlen( a ). "9

d = b - 3. "6

c = a + d(3). "ghi

write 😕 c.

Read only

Former Member
0 Likes
1,858

Hi,

var1 = STRLEN(var)

var2 = var1 - 3

var+var2(var1) would give you the lst three characters

Pankaj

Read only

ThomasZloch
Active Contributor
0 Likes
1,858
SHIFT lf_string RIGHT CIRCULAR BY 3 PLACES.
WRITE lf_string(3).
Read only

0 Likes
1,858

Thanks.. It worked

Read only

0 Likes
1,858

This message was moderated.

Read only

Former Member
0 Likes
1,858

Use FM 'STRING_REVERSE'. Reverse your string and select first 3 characters

Read only

0 Likes
1,858

but then the content is backwards, e.g. "ramuk hsekum"!

you'd have to put the result into STRING_REVERSE again to get the actual sequence.

Edited by: Aravinda A Hegde on Jul 27, 2009 3:02 PM

Read only

Former Member
0 Likes
1,858

data: c TYPE string VALUE 'this is string',

c1(3),

len TYPE i.

len = STRLEN( c ).

len = len - 3.

c1 = c+len(3).

WRITE / c1.

try this

Edited by: mayank jain on Jul 27, 2009 1:03 PM

Read only

0 Likes
1,858

Thanks, this was useful.