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
4,641

I tried to reverse the string using 'string_reverse' fm.But it won't work.Pls give me n eg to use this

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,463

data : v_string1(20) type C.

data : v_string2(20) type C.

initialization.

v_string1 = 'RAMA'.

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

string = v_string1

lang = sy-langu

IMPORTING

rstring = v_string2

EXCEPTIONS

too_small = 1

OTHERS = 2.

write 😕 v_string1,v_string2.

6 REPLIES 6
Read only

Former Member
0 Likes
1,463
Hi Khanna,

 try this

REPORT ychatest2.

DATA : v_str(100) VALUE 'SDN',
       v_rev(100).


CALL FUNCTION 'STRING_REVERSE'
  EXPORTING
    string    = v_str
    lang      = sy-langu
  IMPORTING
    rstring   = v_rev
  EXCEPTIONS
    too_small = 1
    OTHERS    = 2.

WRITE : v_rev.
Read only

0 Likes
1,463

i tried but it gives short dump error.

Read only

0 Likes
1,463

Hi Khanna,

What does the dump say??

Declare the string of type CHAR, it will work

Read only

Former Member
0 Likes
1,463

HI

<b>STRING_REVERSE</b> Returns a string in reverse order

<b>Functionality</b>

The function module returns the character string entered in reverse sequence. Leading blanks are taken into account, trailing blanks are not.

All exceptions are generated with RAISE and must be handled in the calling program.

<b>Examples</b>

' abc ' becomes 'cba ' . (If the actual parameter assigned to the formal parameter RSTRING is longer than 4 characters as shown in this example, the remaining places are padded with blanks.)

Sample call:

DATA: REVERSESTRING(10).

CALL FUNCTION 'STRING_REVERSE'

EXPORTING STRING = ' abcdef '

IMPORTING RSTRING = REVERSESTRING

EXCEPTIONS TOO_SMALL = 1.

IF SY-SUBRC = 0.

  • The reverse string is in RSTRING

ELSE.

  • RSTRING zu kurz

ENDIF.

<b>Reward if usefull</b>

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,463

hi Khanna,

by import parameter LANG you have to give the language to the system. This should be system wise, so you have to take care about conversions.

ec

Read only

Former Member
0 Likes
1,464

data : v_string1(20) type C.

data : v_string2(20) type C.

initialization.

v_string1 = 'RAMA'.

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

string = v_string1

lang = sy-langu

IMPORTING

rstring = v_string2

EXCEPTIONS

too_small = 1

OTHERS = 2.

write 😕 v_string1,v_string2.