ABAP长文本
在ABAP中,我們經(jīng)常會用到長文本來描述詳細信息。
?
長文本存儲在表格:STXH(抬頭),STXL(行項目)中。
?
長文本中有四個關(guān)鍵屬性:
object、id、name、langguge
即:
?
TDOBJECT
TDNAME
TDID
TDSPRAS
?
其中l(wèi)anguage不必解釋,object 和 id 可以在se75中進行配置,一個object 可以對一個多個ID,比如我們常用的 TEXT + ST
name 一般用對象號。
?
而對長文本的操作主要是? READ_TEXT? 和 SAVE_TEXT
?
分別實現(xiàn)長文本的讀取和寫入,例如:
?
REPORT? ZLJC9999.
DATA:? TD_NAME?? LIKE STXH-TDNAME.
DATA ITAB_LINE LIKE TLINE OCCURS 0 WITH HEADER LINE.
TD_NAME = 'LJC0000001'.
CLEAR ITAB_LINE.
REFRESH ITAB_LINE.
ITAB_LINE-TDLINE = 'ARE YOU DOG?'.??? "把多行長文本加在一起
APPEND? ITAB_LINE.
?
DATA:L_THEAD? TYPE THEAD.
L_THEAD-TDOBJECT = 'ZLJC'.
L_THEAD-TDNAME = TD_NAME.
L_THEAD-TDID???? = 'SB'.
L_THEAD-TDSPRAS? = SY-LANGU.
CALL FUNCTION 'SAVE_TEXT'
? EXPORTING
??? HEADER = L_THEAD
? TABLES
??? LINES? = ITAB_LINE.
COMMIT WORK.
CALL FUNCTION 'READ_TEXT'???????????????????????????????????????????????
?????? EXPORTING
????????????? CLIENT?????????????????????? = SY-MANDT
????????????? ID?????????????????????????? = L_THEAD-TDID
????????????? LANGUAGE???????????????????? = SY-LANGU
????????????? NAME???????????????????????? =? TD_NAME
????????????? OBJECT?????????????????????? = L_THEAD-TDOBJECT
??????????? TABLES
????????????? LINES???????????????????????? = ITAB_LINE
?????????? EXCEPTIONS
??????????? NOT_FOUND???????????????????? = 4.
IF SY-SUBRC = 0.
? LOOP AT ITAB_LINE.
??? WRITE: ITAB_LINE-TDLINE .??? "把多行長文本加在一起
? ENDLOOP.
ENDIF.
?
?
?
一般我們還會提供長文本的錄入、編輯、顯示界面。這個需要用面向OO的組件。在屏幕上畫一個Container。
初始化長文本界面的例子:
?
DATA:ppcont_desc1?TYPE?REF?TO?cl_gui_custom_container,
??????ppedit_desc1????TYPE?REF?TO?cl_gui_textedit,
????create?object:?ppcont_desc1?exporting?container_name?=?'LONGTEXT1',
??????????????????????ppedit_desc1????exporting?parent?=?ppcont_desc1.
????????call?method?ppedit_desc1->set_toolbar_mode
??????????exporting
????????????toolbar_mode?=?cl_gui_textedit=>true.??????"長文本?菜單加載?FALSE?取消菜單
????????call?method?ppedit_desc1->set_statusbar_mode
??????????exporting
????????????statusbar_mode?=?cl_gui_textedit=>false.
????????call?method?ppedit_desc1->register_event_dblclick
??????????exporting
????????????appl_event?=?'X'.
???
??????????call?method?ppedit_desc1->set_visible
????????????exporting
??????????????visible?=?'X'.
??????
長文本寫到編輯區(qū)域的例子:
?
?l_tdid?=?'ST'.
??l_tdobject?=?'TEXT'.
??refresh:?it_tab3[],
???????????text_tab[].
??clear?it_tab3.
??call?function?'READ_TEXT'
????exporting
??????id??????????????????????=?l_tdid
??????language????????????????=?sy-langu
??????name????????????????????=?p_tdname
??????object??????????????????=?l_tdobject
????tables
??????lines???????????????????=?it_tab3
????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.
??endif.
??loop?at?it_tab3.
????line?=?it_tab3-tdline.
????append?line?to?text_tab.
??endloop.
??refresh?it_tab3[].
??call?method?ppedit_desc1->set_text_as_r3table
????exporting
??????table?=?text_tab
*????EXCEPTIONS
*??????error_dp???????????????=?1
*??????error_cntl_call_method?=?2
*??????error_dp_create????????=?3
*??????potential_data_loss????=?4
*??????OTHERS?????????????????=?5
??????.
??refresh??text_tab[].
?
將界面中的長文本保存的例子:
break?ljc.
??refresh:??text_tab[],
??????????it_tab3.
*??CALL?METHOD?ppedit_desc->get_text_as_r3table
*????IMPORTING
*??????table?=?text_tab.
??call?method?ppedit_desc->get_text_as_r3table
???exporting
?????only_when_modified?????=?''
???importing
*??????TEXT?=?TEXT_TAB.
??????table?=?text_tab
???exceptions
?????error_dp???????????????=?1
?????error_cntl_call_method?=?2
?????error_dp_create????????=?3
?????potential_data_loss????=?4
?????others?????????????????=?5.
??loop?at?text_tab?into?field.
????it_tab3-tdline?=?field.
????append?it_tab3.
????clear:?field,it_tab3.
??endloop.
****?保存長文本
??l_thead-tdobject?=?'TEXT'.
??clear?l_thead-tdname.
*??concatenate?'PP'?ZPLM090_PP-PPNUM??into?L_THEAD-TDNAME.
??l_thead-tdname?=?tab_check-objnr.
??l_thead-tdid?????=?'ST'.
??l_thead-tdspras??=?sy-langu.
??call?function?'SAVE_TEXT'
????exporting
??????header?=?l_thead
????tables
??????lines??=?it_tab3.
??commit?work.
總結(jié)
- 上一篇: Message LongText(消息的
- 下一篇: PO增强,明细动抬头动