1、如果要使用自定义的文本对象和识别码,需要先用se75创建文本对象和识别码。
2、在屏幕中拖个自定义控件,拖放适当的大小,激活。
3、在代码中申明一个cl_gui_custom_container类型的变量和一个cl_gui_textedit类型的变量。
data:gv_container type REF TO cl_gui_custom_container,
gv_editor type ref to cl_gui_textedit.
gv_editor type ref to cl_gui_textedit.
4、创建上面两个变量的实例。
if gv_container is initial.
CREATE OBJECT gv_container
EXPORTING
* parent =
container_name = 'GV_CONTAINER_TXT' "一定要是屏幕中自定义控件的名字
* style =
* lifetime = lifetime_default
* repid =
* dynnr =
* no_autodef_progid_dynnr =
* EXCEPTIONS
* cntl_error = 1
* cntl_system_error = 2
* create_error = 3
* lifetime_error = 4
* lifetime_dynpro_dynpro_link = 5
* others = 6
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT gv_container
EXPORTING
* parent =
container_name = 'GV_CONTAINER_TXT' "一定要是屏幕中自定义控件的名字
* style =
* lifetime = lifetime_default
* repid =
* dynnr =
* no_autodef_progid_dynnr =
* EXCEPTIONS
* cntl_error = 1
* cntl_system_error = 2
* create_error = 3
* lifetime_error = 4
* lifetime_dynpro_dynpro_link = 5
* others = 6
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
if gv_editor is initial.
CREATE OBJECT gv_editor
EXPORTING
* max_number_chars =
* style = 0
wordwrap_mode = cl_gui_textedit=>WORDWRAP_AT_FIXED_POSITION
wordwrap_position = -1
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
* filedrop_mode = DROPFILE_EVENT_OFF
parent = gv_container
* lifetime =
* name =
* EXCEPTIONS
* error_cntl_create = 1
* error_cntl_init = 2
* error_cntl_link = 3
* error_dp_create = 4
* gui_type_not_supported = 5
* others = 6
.
CREATE OBJECT gv_editor
EXPORTING
* max_number_chars =
* style = 0
wordwrap_mode = cl_gui_textedit=>WORDWRAP_AT_FIXED_POSITION
wordwrap_position = -1
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
* filedrop_mode = DROPFILE_EVENT_OFF
parent = gv_container
* lifetime =
* name =
* EXCEPTIONS
* error_cntl_create = 1
* error_cntl_init = 2
* error_cntl_link = 3
* error_dp_create = 4
* gui_type_not_supported = 5
* others = 6
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endif.
endif.
endif.
运行下就可以看到文本编辑框了。怎么读写文本呢,先申明下面的变量
data:fid like THEAD-TDID,
fNAME like THEAD-TDNAME,
fobject like THEAD-TDOBJECT,
it_line like STANDARD TABLE OF line WITH HEADER LINE,
it_tline like STANDARD TABLE OF tline WITH HEADER LINE,
it_header like THEAD.
fNAME like THEAD-TDNAME,
fobject like THEAD-TDOBJECT,
it_line like STANDARD TABLE OF line WITH HEADER LINE,
it_tline like STANDARD TABLE OF tline WITH HEADER LINE,
it_header like THEAD.
从
数据库中读文本和写文本使用read_text、create_text这两个FM,他们有个table参数是tline类型的。
从文本编辑框中读、写文本使用