Saturday, November 22, 2014

Removing specified characters from string

* Remove all occurrences of single and double quotes
  REPLACE ALL OCCURRENCES OF SUBSTRING '''' IN lv_all_params WITH ''.
  REPLACE ALL OCCURRENCES OF SUBSTRING '"' IN lv_all_params WITH ''.

Replace/Remove Specified Characters From String

DATA legal_chars TYPE string
      VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.,-*_!?'.
DATA lv_char_value(255)" give max length

lv_char_value gv_string.
CHECK NOT lv_char_value CO legal_chars ).

lv_length strlengv_string ).

DO lv_length TIMES.
  lv_i sy-index 1.
  IF NOT lv_char_value+lv_i(1CO legal_chars.
    "We get the illegal char , do what you want
    lv_char_value+lv_i(1' '.
  ENDIF.
ENDDO.

CLEAR gv_string.
gv_string lv_char_value.