換行符,TAB KEY等在SAP的DB中被存為“#“。
雖然被保存為#泉蝌,但在報(bào)表中仍能正常顯示。
DATA:gt_rfc_db_opt TYPE TABLE OF rfc_db_opt WITH HEADER LINE
,gt_rfc_db_fld TYPE TABLE OF rfc_db_fld WITH HEADER LINE
,gt_rfc_data TYPE TABLE OF tab512 WITH HEADER LINE,
gv_rfcdest TYPE rfcdest.
DATA:p_ftable TYPE dd02l-tabname VALUE 'ADRC'.
DATA: p_char TYPE sonv-flag VALUE '-'.
DATA: tcodepage TYPE cpcodepage.
DATA(iv_uscomp) = '9003255631'.
gt_rfc_db_opt-text = |ADDRNUMBER = '{ iv_uscomp }'|.
APPEND gt_rfc_db_opt.
gt_rfc_db_fld-fieldname = 'STREET'.
APPEND gt_rfc_db_fld.
gt_rfc_db_fld-fieldname = 'ADDRNUMBER'.
APPEND gt_rfc_db_fld.
gt_rfc_db_fld-fieldname = 'ADDR_GROUP'.
APPEND gt_rfc_db_fld.
gv_rfcdest = 'R2C_060'.
CALL FUNCTION 'RFC_READ_TABLE'
DESTINATION gv_rfcdest
EXPORTING
query_table = p_ftable
delimiter = p_char
* NO_DATA = ' '
* ROWSKIPS = 0
* ROWCOUNT = 0
TABLES
options = gt_rfc_db_opt
fields = gt_rfc_db_fld
data = gt_rfc_data.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
READ TABLE gt_rfc_data INDEX 1.
DATA(lv_xml) = gt_rfc_data-wa.
*
*DATA: str TYPE string.
*
*DATA ls_char TYPE c.
*ls_char = cl_abap_char_utilities=>cr_lf.
*
*str = 'hello' && LS_CHAR && 'hahahahha'.
*
*WRITE: str.
*
*REPLACE ls_char IN str WITH ''.
*REPLACE '#' IN lv_xml WITH ''.
*
*SKIP 1.
*
*WRITE str.
CALL FUNCTION 'NLS_GET_FRONTEND_CP'
EXPORTING
langu = '1' "sy-langu
fetype = 'MS'
IMPORTING
frontend_codepage = tcodepage
EXCEPTIONS
illegal_syst_codepage = 1
no_frontend_cp_found = 2
internal_or_db_error = 3
OTHERS = 4.
CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
EXPORTING
intext = lv_xml
inter_cp = tcodepage
replacement = 32 " 等于space, ASC
IMPORTING
outtext = lv_xml
EXCEPTIONS
invalid_codepage = 1
codepage_mismatch = 2
internal_error = 3
cannot_convert = 4
fields_not_type_c = 5
OTHERS = 6.
WRITE lv_xml.
上面這種方式是以非法字符來(lái)捕捉的
DATA(lv_wildcard1) = '*' && '"' && '*'.
DATA(lv_wildcard2) = '*' && separator && '*'.
DATA lv_rc(1) VALUE '0'.
DATA lv_line_break TYPE sy-subrc.
IF field_value CP lv_wildcard1.
REPLACE ALL OCCURRENCES OF '"' IN field_value WITH '""' IN CHARACTER MODE.
lv_rc = 1.
ENDIF.
FIND REGEX '[\r\n]' IN field_value. "Line Break
lv_line_break = sy-subrc.
IF field_value CP lv_wildcard2 OR lv_line_break = 0 OR field_value CP cl_abap_char_utilities=>cr_lf OR field_value CP '*\n*'.
field_value = '"' && field_value && '"'.
lv_rc = 0.
ENDIF.
IF lv_rc <> 0.
field_value = '"' && field_value && '"'.
ENDIF.
如果是導(dǎo)文件衫仑,就用正則表達(dá)式尋找梨与,有換行符的話(huà),就用“”括起來(lái)文狱,表示成一個(gè)字符串