Wednesday, December 30, 2009

Replace/Remove Specified Characters From String



*** Here we check GV_STRING has any chars other than
*** legal_chars value. If anyone has we replace the value.

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.

1 comment:

  1. Good 1. Thanx.At some places REPLACE ALL OCCURRENCES does not work

    ReplyDelete