&字符自动转换问题
一、问题描述
-
用函数Read_text()读取长文时,出现了<(>&<)>符号,其实这是SAP系统自动转换后的’&'符号,其他还有一些特殊符号也有同样的问题。
-
ead_text()长文本后,发现’&'转换成<(>&<)>符号,
二、解决办法
-
这个<(>&<)>符号可以通过CONVERT_ITF_TO_STREAM_TEXT转回‘&’
-
执行结果
三、代码如下
FORM READ_TEXT USING PI_THEAD TYPE THEAD
CHANGING PC_OUTPUT.
TYPES: BEGIN OF STREAM,
DEFAULT TYPE CHAR100,
END OF STREAM.
DATA: LT_TLINE TYPE TABLE OF TLINE,
LT_STREAM TYPE TABLE OF STREAM,
LW_STREAM TYPE STREAM,
LT_TEXT TYPE TABLE OF TLINE,
LW_TEXT TYPE TLINE,
LW_TLINE TYPE TLINE.
*->Read text
CLEAR LT_TLINE.
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = PI_THEAD-TDID
LANGUAGE = PI_THEAD-TDSPRAS
NAME = PI_THEAD-TDNAME
OBJECT = PI_THEAD-TDOBJECT
TABLES
LINES = LT_TLINE
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ELSE.
LOOP AT LT_TLINE INTO LW_TLINE.
"将读出的文本中的<(>&<)> 符号转换成& START
LW_TEXT-TDLINE = LW_TLINE-TDLINE.
APPEND LW_TEXT TO LT_TEXT.
ENDLOOP.
CALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'
EXPORTING
LANGUAGE = PI_THEAD-TDSPRAS
TABLES
ITF_TEXT = LT_TEXT
TEXT_STREAM = LT_STREAM.
LOOP AT LT_STREAM INTO LW_STREAM.
IF PC_OUTPUT IS INITIAL.
PC_OUTPUT = LW_STREAM-DEFAULT.
ELSE.
PC_OUTPUT = PC_OUTPUT && CL_ABAP_CHAR_UTILITIES=>NEWLINE && LW_STREAM-DEFAULT .
ENDIF.
CLEAR:LW_TLINE ,LW_STREAM.
ENDLOOP.
ENDIF.
ENDFORM.