1.1. 长文本处理
1.1.1. 读取长文本
这里以抓取DeliveryNote的Item上的长文本作为例子。
1.1.1.1. 查找长文本的Text ID,TextObject
VL02N修改Delivery Note: 80000023
按回车键或者点击,
选中要一行资料,然后点击菜单Goto->Item->Texts
点击,
然后点击菜单:Goto->Header
在这里显示的Text ID:0001,Text Object:VBBP,以及Text Name:0080000023000010,这几个字段在后面取值时要使用到
1.1.1.2. 编写程序
*&---------------------------------------------------------------------*
*& Report Y10028
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Y10028.
DATA IT_DATA TYPE STANDARD TABLE OF TLINE .
DATA W_DATA TYPE TLINE.
DATA ID LIKE THEAD-TDID.
DATA LANGUAGE LIKE THEAD-TDSPRAS.
DATA NAME LIKE THEAD-TDNAME.
DATA OBJECT LIKE THEAD-TDOBJECT.
START-OF-SELECTION.
ID = '0001'.
LANGUAGE = 'EN'.
NAME = '0080000023000010'.
OBJECT = 'VBBP'.
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
ID = ID
LANGUAGE = LANGUAGE
NAME = NAME
OBJECT = OBJECT
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
TABLES
LINES = IT_DATA
* 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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT IT_DATA INTO W_DATA.
WRITE:/ W_DATA-TDLINE.
ENDLOOP.
1.1.1.3. 显示结果
1.1.2. 写入长文本
有时需要将其他的系统的资料Upload到长文本字段中,或者将资料从文字档、Excel档Upload到长文本字段中,使用BDC比较麻烦,这个时候可以使用SAVE_TEXT Function来写入长文本。查找TextID,Text Object的方法在上一个章节已经说明,这里不再重复。
REPORT Y10028.
DATA HEADER LIKETHEAD.
data LINES LIKE TABLE OF TLINE WITH HEADER LINE.
DATA W_LINE TYPETLINE.
START-OF-SELECTION.
HEADER -TDOBJECT = 'VBBK' .
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
* CLIENT = SY-MANDT
HEADER = HEADER
INSERT = 'X'
SAVEMODE_DIRECT = 'X'
* OWNER_SPECIFIED = ' '
* LOCAL_CAT = ' '
* IMPORTING
* FUNCTION =
* NEWHEADER =
TABLES
LINES = LINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
OBJECT = 4
OTHERS = 5
.
IF SY-SUBRC <> 0.
* MESSAGE IDSY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3SY-MSGV4.
ENDIF.
COMMIT WORK.
结果显示为:
1.1.3. 删除长文本
CALL FUNCTION 'DELETE_TEXT'
EXPORTING
* CLIENT = SY-MANDT
ID = ID
LANGUAGE = LANGUAGE
NAME = NAME
OBJECT = OBJECT
* 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.