[隐藏]
1, Text Editor介绍
不同于一般的屏幕字段,Text Editor可以保存多行文本,它是SAP各种凭证中常用的控件之一,比如采购订单中,凭证头和行项目中都应用到text editor控件,如下:
2, 创建text editor控件
下面介绍如何在dailog程序中创建一个text editor控件,
2.1, SE80创建dialog程序
Tcode:se80,创建一个dialog程序,并且添加一个屏幕100
2.2, 创建custom control
在屏幕100的layout上,创建一个custom control,并输入名字Text_editor
2.3, 修改PBO代码
PBO:
- 创建pf status,详细参照-->http://www.baidusap.com/abap/dialog/1516
- 创建object container GO_EDITOR_CONTAINER. 然后再创建 text editor控件对象go_editor
数据对象定义:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
DATA: go_editor TYPE REF TO cl_gui_textedit, go_editor_container TYPE REF TO cl_gui_custom_container, ok_code LIKE sy-ucomm. " return code from screen CONSTANTS: c_line_length TYPE i VALUE 256. * 定义保存长文本用的内表 TYPES: BEGIN OF ty_mytable_line, line(c_line_length) TYPE c, END OF ty_mytable_line. DATA:git_mytable TYPE TABLE OF ty_mytable_line. * necessary to flush the automation queue CLASS cl_gui_cfw DEFINITION LOAD. |
module pbo_0100中代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
IF go_editor IS INITIAL. * 创建控件容器 CREATE OBJECT go_editor_container EXPORTING container_name = 'TEXTEDITOR1' EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. IF sy-subrc NE 0. * add your handling ENDIF. * 将Text editor和控件容器对象连接起来 CREATE OBJECT go_editor EXPORTING parent = go_editor_container wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position wordwrap_to_linebreak_mode = cl_gui_textedit=>true EXCEPTIONS OTHERS = 1. ENDIF. |
2.4, 修改PAI代码
PAI:创建Module user_command_0100
Module user_command_0100中的代码:
- 在退出程序的时候,free text editor控件以及控件容器的对象
- 在保存的时候读取在text editor中输入的长文内容到内表git_mytable中
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
MODULE user_command_0100 INPUT. CASE ok_code. WHEN '&F03'. IF NOT go_editor IS INITIAL. CALL METHOD go_editor->free EXCEPTIONS OTHERS = 1. * free ABAP object also FREE go_editor. ENDIF. * destroy container IF NOT go_editor_container IS INITIAL. CALL METHOD go_editor_container->free EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. ENDIF. * free ABAP object also FREE go_editor_container. ENDIF. * finally flush CALL METHOD cl_gui_cfw=>flush EXCEPTIONS OTHERS = 1. LEAVE PROGRAM. WHEN '&DATA_SAVE'. * retrieve table from control CALL METHOD go_editor->get_text_as_r3table IMPORTING table = git_mytable EXCEPTIONS OTHERS = 1. CALL METHOD cl_gui_cfw=>flush EXCEPTIONS OTHERS = 1. * no flush here: * the automatic flush at the end of PBO does the job ENDCASE. ENDMODULE. |
2.5, 创建Tcode
2.5, 运行测试
运行Tcode ztextedit, 在text editor控件中输入长文本,
点击保存按钮,在debug模式中,可以看到内表git_mytable中输入的内容line1,line2,line3.
以上。
发表评论