ABAP-去除特殊符号函数
方法1
1 *ABAP中有关于换行符,TAB KEY等 收藏 2 3 *换行符,TAB KEY等的表示 4 *在数据文件输出的时候,有时候需要使各个字段间用TAB KEY进行分割。 5 *那么,TAB KEY在ABAP中是如何表示的,就是写入一个TAB KEY吗? 6 *事实上,在类对象CL_ABAP_CHAR_UTILITIES中已经事先定义好了如换行符,TAB KEY等。 7 *CR_LF 换行符 8 *HORIZONTAL_TAB 水平方向的TAB KEY 9 *VERTICAL_TAB 竖直方向的TAB KEY 10 *FORM_FEED 改页 11 *例: CONCATENATE COL1 COL2 CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO … 12 13 *换行符,TAB KEY等在DB中保存 14 *换行符,TAB KEY等在SAP的DB中被存为“#“。 15 *虽然被保存为#,但在报表中仍能正常显示。 16 17 *换行符,TAB KEY等的置换处理 18 *换行符,TAB KEY等的置换不能简单的用REPLACE命令进行处理。 19 *正确的处理如下: 20 CALL FUNCTION 'NLS_GET_FRONTEND_CP' 21 EXPORTING 22 LANGU = SY-LANGU 23 * fetype = 'MS' 24 IMPORTING 25 FRONTEND_CODEPAGE = CPCODEPAGE 26 EXCEPTIONS 27 ILLEGAL_SYST_CODEPAGE = 1 28 NO_FRONTEND_CP_FOUND = 2 29 INTERNAL_OR_DB_ERROR = 3 30 OTHERS = 4. 31 32 CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS' 33 EXPORTING 34 INTEXT = INTEXT"入参 35 INTER_CP = CPCODEPAGE 36 REPLACEMENT = 32 37 IMPORTING 38 OUTTEXT = OUTTEXT"出参 39 EXCEPTIONS 40 INVALID_CODEPAGE = 1 41 CODEPAGE_MISMATCH = 2 42 INTERNAL_ERROR = 3 43 CANNOT_CONVERT = 4 44 FIELDS_NOT_TYPE_C = 5 45 OTHERS = 6.
方法2
1 DATA: lv_char(10) TYPE c." 2 lv_char = cl_abap_char_utilities=>horizontal_tab. "09 TAB符 3 REPLACE ALL OCCURRENCES OF lv_char IN p_sting WITH ''. 4 5 lv_char = cl_abap_char_utilities=>cr_lf. "0D0A 回车换行 6 REPLACE ALL OCCURRENCES OF lv_char IN p_sting WITH ''. 7 lv_char = cl_abap_char_utilities=>vertical_tab. "0B 垂直制表符 8 REPLACE ALL OCCURRENCES OF lv_char IN p_sting WITH ''. 9 10 lv_char = cl_abap_char_utilities=>newline. "0A 换行 11 REPLACE ALL OCCURRENCES OF lv_char IN p_sting WITH ''. 12 lv_char = cl_abap_char_utilities=>form_feed. "0C 换页 13 REPLACE ALL OCCURRENCES OF lv_char IN p_sting WITH ''. 14 15 lv_char = cl_abap_char_utilities=>backspace. "08 退格符 16 REPLACE ALL OCCURRENCES OF lv_char IN p_sting WITH ''. 17 lv_char = cl_abap_char_utilities=>byte_order_mark_little. "(UTF-16LE)的文件头 18 REPLACE ALL OCCURRENCES OF lv_char IN p_sting WITH ''. 19 20 lv_char = cl_abap_char_utilities=>byte_order_mark_utf8. "(UTF-8)的文件头 21 REPLACE ALL OCCURRENCES OF lv_char IN p_sting WITH ''.