現象描述ui
長文本在SAP的運用主要體如今一些notes的記錄,或者一些比較長的文本的存取,好比工做流的審批意見,採購申請和採購訂單的附加說明等等。以下圖:code
處理過程對象
1:SAP中全部的長文本都存在兩張表中:blog
STXH 長文本的擡頭信息get
STXL 長文本的明細信息工作流
可是長文本在使用前,須要先進行配置,若是不配置是不可能往表STXH和STXL中寫入文本值的。配置在視圖V_TTXIDI和視圖V_TTXOBI中進行。it
SE16維護視圖V_TTXOBIgui
SE16維護視圖V_TTXIDIstream
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的長文本操做中,咱們是沒法直接看到存儲的長文本的,只能經過程序讀取長文本在界面中顯示,這點是和其餘類型的變量區別開來的。