You can easily reverse the string using the following function module.
STRING_REVERSE
Please refer the program shown below for details.REPORT ZEX_STRINGREV .
Parameters: p_string(200).
Data: r_string(100).
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = p_string
LANG = 'E'
IMPORTING
RSTRING = r_string
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Inputted String.
Write:/ 'Inputted String', p_string.
SKIP.
*The reverse of the above mentioned string is as follows.
Write:/ r_string.
Parameters: p_string(200).
Data: r_string(100).
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = p_string
LANG = 'E'
IMPORTING
RSTRING = r_string
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Inputted String.
Write:/ 'Inputted String', p_string.
SKIP.
*The reverse of the above mentioned string is as follows.
Write:/ r_string.
'ABCDEFGH'
Then the output is
Reverse a String
Inputted String
ABCDEFGH
Reverse of the above string is
HGFEDCBA
Inputted String
ABCDEFGH
Reverse of the above string is
HGFEDCBA