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

String Reverse

Former Member
0 Likes
1,291

Hi everybody i wanted to know how to reverse a string and extract the last 3 charcters of the string into a separate variable.

I have to reverse the string using the function module.

Thanks

Prem

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,238

Let me be a bit more specific about the problem i want to know where is the reverse string stored i.e in which parameter and how to extract only the last 3 characters of the reversed string.

Thanks

9 REPLIES 9
Read only

JozsefSzikszai
Active Contributor
0 Likes
1,238

FM: STRING_REVERSE

Read only

Former Member
0 Likes
1,238

STRING_REVERSE

Read only

Former Member
0 Likes
1,239

Let me be a bit more specific about the problem i want to know where is the reverse string stored i.e in which parameter and how to extract only the last 3 characters of the reversed string.

Thanks

Read only

0 Likes
1,238

REPORT ZSRK_023 .

PARAMETERS : P_STRING(30).

DATA : RSTRING(30),

LEN TYPE I,

L TYPE I,

RESULT(3).

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

STRING = P_STRING

LANG = 'E'

IMPORTING

RSTRING = RSTRING

EXCEPTIONS

TOO_SMALL = 1

OTHERS = 2.

LEN = STRLEN( RSTRING ).

L = LEN - 3.

RESULT = RSTRING+L(3).

WRITE : / RESULT.

Read only

0 Likes
1,238

does it mean, that you only need the first three characters of the original string in reversed order? if yes, you can use:

CONCATENATE string+2(1) string+1(1) string(1) INTO string_new.

Read only

Former Member
0 Likes
1,238

Thanks sreekant for the help.

Read only

Former Member
0 Likes
1,238

Hi eric,

No i actually want the last 3 charcters of the original in reverse order. actually i apologize for the confusion.

Thanks for your help.

Read only

0 Likes
1,238

no problem, I have a simplier solution for that as well

DATA : gv_length TYPE i,
gv_text TYPE string,
gv_result(3) TYPE c.

gv_length = strlen( gv_text ).
DO 3 TIMES.
gv_length = gv_length - 1.
CONCATENATE gv_result gv_text+gv_length(1) INTO gv_result.
ENDDO.

Read only

Former Member
0 Likes
1,238

Thanks eric.