FUNCTION ZF_REPLACE_STR.
*"----------------------------------------------------------------------
*"*"Local interface:
*" CHANGING
*" REFERENCE(STR) TYPE CLIKE
*"----------------------------------------------------------------------
*替换文本中的违规字符
*双引号 " 修改为 波浪号 ~
*单引号 ' 修改为 波浪号 ~
*双减号 -- 修改为 全角减号 -
*括号 () 修改为 尖角括号 []
*百分号 % 修改为 除号 #
*"----------------------------------------------------------------------
IF STR IS INITIAL.
RETURN.
ENDIF.
"去掉回车符
PERFORM FRM_REPLACE_SPCIL_CHAR USING '32' CHANGING P_STR.
"替代字符
REPLACE ALL OCCURRENCES OF '''' IN STR WITH '~'.
REPLACE ALL OCCURRENCES OF '--' IN STR WITH '-'.
REPLACE ALL OCCURRENCES OF '(' IN STR WITH '['.
REPLACE ALL OCCURRENCES OF ')' IN STR WITH ']'.
REPLACE ALL OCCURRENCES OF '%' IN STR WITH '#'.
REPLACE ALL OCCURRENCES OF '"' IN STR WITH ''.
REPLACE ALL OCCURRENCES OF '"' IN STR WITH ''.
CONDENSE P_STR NO-GAPS. "压缩空格
ENDFUNCTION.
*&---------------------------------------------------------------------*
*& Form FRM_REPLACE_SPCIL_CHAR*&---------------------------------------------------------------------*
* 去掉字符串中的回车符
*----------------------------------------------------------------------*
* -->P_STR text
*----------------------------------------------------------------------*
FORM FRM_REPLACE_SPCIL_CHAR USING P_ASCILI CHANGING P_STR.
DATA:FRM_STR(100),
FRM_CODEPAGE LIKE TCP00-CPCODEPAGE .
CALL FUNCTION 'NLS_GET_FRONTEND_CP'
EXPORTING
LANGU = SY-LANGU
IMPORTING
FRONTEND_CODEPAGE = FRM_CODEPAGE
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 = P_STR
INTER_CP = FRM_CODEPAGE
REPLACEMENT = P_ASCILI
IMPORTING
OUTTEXT = FRM_STR
EXCEPTIONS
INVALID_CODEPAGE = 1
CODEPAGE_MISMATCH = 2
INTERNAL_ERROR = 3
CANNOT_CONVERT = 4
FIELDS_NOT_TYPE_C = 5
OTHERS = 6.
P_STR = FRM_STR.
ENDFORM. "FRM_REPLACE_SPCIL_CHAR