首页 > 代码库 > ABAP程序中关于长文本的处理方法
ABAP程序中关于长文本的处理方法
现象描述
长文本在SAP的运用主要体现在一些notes的记录,或者一些比较长的文本的存取,比如工作流的审批意见,采购申请和采购订单的附加说明等等。如下图:
处理过程
1:SAP中所有的长文本都存在两张表中:
STXH 长文本的抬头信息
STXL 长文本的明细信息
但是长文本在使用前,需要先进行配置,如果不配置是不可能往表STXH和STXL中写入文本值的。配置在视图V_TTXIDI和视图V_TTXOBI中进行。
SE16维护视图V_TTXOBI
SE16维护视图V_TTXIDI
2:在上图中,找到我们维护了需要写入长文本的对象Z_TEST01,这样,我们就能往对象中写入长文本了,如下图:
3:相应的对长文本进行增加、保存、删除的代码示例如下:
首先是变量的声明
DATA: lines TYPE STANDARD TABLE OF tline ,
it_line TYPE TABLE OF line,
header LIKE thead .
DATA: container1 TYPE REF TO cl_gui_custom_container,
editor1 TYPE REF TO cl_gui_textedit.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
长文本的初始化:
IF container1 IS INITIAL.
CREATE OBJECT:container1 EXPORTING container_name = ‘COMMENT1‘,
editor1 EXPORTING parent = container1.
CALL METHOD editor1->set_statusbar_mode
EXPORTING
statusbar_mode = 0.
CALL METHOD editor1->set_toolbar_mode
EXPORTING
toolbar_mode = 0.
ENDIF.
CALL METHOD editor1->set_text_as_stream
EXPORTING
text = it_line.
长文本的保存:
REFRESH it_line.
CALL METHOD editor1->get_text_as_stream
IMPORTING
text = it_line.
*--长文本保存
header-tdobject = ‘Z_TEST01‘. "object
header-tdname = ‘001‘.
header-tdid = ‘LTXT‘.
header-tdspras = sy-langu.
CALL FUNCTION ‘CONVERT_STREAM_TO_ITF_TEXT‘
EXPORTING
language = sy-langu
TABLES
text_stream = it_line
itf_text = lines.
CALL FUNCTION ‘SAVE_TEXT‘
EXPORTING
header = header
savemode_direct = ‘X‘
TABLES
lines = lines
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5.
CLEAR header.
REFRESH lines.
长文本的显示:
header-tdobject = ‘Z_TEST01‘. "object
header-tdname = ‘001‘.
header-tdid = ‘LTXT‘.
header-tdspras = sy-langu.
CALL FUNCTION ‘READ_TEXT‘
EXPORTING
id = header-tdid
language = sy-langu
name = header-tdname
object = header-tdobject
TABLES
lines = lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
CALL FUNCTION ‘CONVERT_ITF_TO_STREAM_TEXT‘
EXPORTING
language = sy-langu
TABLES
itf_text = lines
text_stream = it_line.
CALL METHOD editor1->set_statusbar_mode
EXPORTING
statusbar_mode = 0.
CALL METHOD editor1->set_toolbar_mode
EXPORTING
toolbar_mode = 0.
CALL METHOD editor1->set_text_as_stream
EXPORTING
text = it_line.
CALL METHOD editor1->set_readonly_mode
EXPORTING
readonly_mode = ‘1‘.
长文本的删除:
header-tdobject = ‘Z_TEST01‘. "object
header-tdname = ‘001‘.
header-tdid = ‘LTXT‘.
header-tdspras = sy-langu.
CALL FUNCTION ‘DELETE_TEXT‘
EXPORTING
id = header-tdid
language = sy-langu
name = header-tdname
object = header-tdobject
* SAVEMODE_DIRECT = ‘ ‘
* TEXTMEMORY_ONLY = ‘ ‘
* LOCAL_CAT = ‘ ‘
* EXCEPTIONS
* NOT_FOUND = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
在ABAP的长文本操作中,我们是无法直接看到存储的长文本的,只能通过程序读取长文本在界面中显示,这点是和其他类型的变量区别开来的。