Saturday, May 10, 2008

SAP ABAP Function Module to Reverse a String

SAP ABAP Function Module to Reverse a String.

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.


If the input is as follows

'ABCDEFGH'

Then the output is

Reverse a String                         
                                         
Inputted String                          
ABCDEFGH                                 
                                         
Reverse of the above string is           
HGFEDCBA

                                
                                         


No comments:

Post a Comment