anandatheerthan

Remove Invalid Characters in Unicode

Sep 10th, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 1.29 KB | None | 0 0
  1.  data:  length type i,
  2.         off TYPE i,
  3.         HEXSTRING(4) TYPE C,
  4.         lv_value(40) type c.
  5.  
  6.   FIELD-SYMBOLS: <INCHAR>.
  7.  
  8.   lv_value = 'asdasdasdasd '. " input string
  9.  
  10.   length = STRLEN( lv_value ).
  11.  
  12.   REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>newline IN lv_value WITH ' '.
  13.  
  14.   REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>HORIZONTAL_TAB IN lv_value WITH ' '.
  15.  
  16.   REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>VERTICAL_TAB IN lv_value WITH ' '.
  17.  
  18.   REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>CR_LF IN lv_value WITH ' '.
  19.  
  20.   do length times.
  21.  
  22.     off = sy-index - 1.
  23.     ASSIGN lv_value+off(1) to <INCHAR>.
  24.     CALL FUNCTION 'YY_CHAR_HEX_CONV'
  25.       EXPORTING
  26.         INPUT     = <INCHAR>
  27.       IMPORTING
  28.         HEXSTRING = HEXSTRING.
  29.  
  30. * replace with a blank character if any of the following is met
  31.  
  32.     IF HEXSTRING = '0009'.                       " Horizontal tab
  33.       lv_value+off(1) = ' '.
  34.     elseif hexstring = '000A'.                   " Line feed, new line
  35.       lv_value+off(1) = ' '.
  36.     elseif hexstring = '0023'.
  37.       lv_value+off(1) = ' '.                     " device control 3
  38.     ENDIF.
  39.   enddo.
  40.   RESULT = lv_value.
  41.  
  42. " Code for YY_CHAR_HEX_CONV
  43. FIELD-SYMBOLS: <DUMMY>.  
  44. ASSIGN INPUT TO <DUMMY> TYPE 'X'.  
  45. hexstring = <dummy>.
Advertisement