标签:
不同于一般的屏幕字段,Text Editor可以保存多行文本,它是SAP各种凭证中常用的控件之一,比如采购订单中,凭证头和行项目中都应用到text editor控件,如下:
下面介绍如何在dailog程序中创建一个text editor控件,
Tcode:se80,创建一个dialog程序,并且添加一个屏幕100
在屏幕100的layout上,创建一个custom control,并输入名字Text_editor
PBO:
数据对象定义:
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中代码如下:
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.
PAI:创建Module user_command_0100
Module user_command_0100中的代码:
代码如下:
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
运行Tcode ztextedit, 在text editor控件中输入长文本,
点击保存按钮,在debug模式中,可以看到内表git_mytable中输入的内容line1,line2,line3.
以上。
标签:
原文地址:http://www.cnblogs.com/baidusap/p/5859488.html