ABAP文本编辑框操作

 * 1、创建文本框

 DATA: g_container TYPE REF TO cl_gui_custom_container,
g_editor TYPE REF TO cl_gui_textedit. IF g_container IS INITIAL. "创建 协查处理需求 编辑框
CREATE OBJECT g_container
EXPORTING
container_name = 'GC_CCTRL'
EXCEPTIONS
cntl_error =
cntl_system_error =
create_error =
lifetime_error =
lifetime_dynpro_dynpro_link = .
IF sy-subrc <> .
EXIT .
ENDIF . CREATE OBJECT g_editor
EXPORTING
max_number_chars = "字数限制
parent = g_container
wordwrap_mode = "边框模式,设置为0可以去掉编辑框的滚动条
wordwrap_position = "换行宽度
EXCEPTIONS
error_cntl_create =
error_cntl_init =
error_cntl_link =
error_dp_create =
gui_type_not_supported =
OTHERS = .
IF sy-subrc <> .
MESSAGE e000(oo ) WITH '创建编辑框失败 !' .
ENDIF .
ENDIF .
"wordwrap_mode:边框模式,设置为0可以去掉编辑框的滚动条设置为2可以自动换行 * 2、设置文本框的内容
* PS: set_text_as_stream 无法设置多行,需要设置多行,用 set_text_as_r3table FORM frm_set_text USING pi_text TYPE char100 .
DATA:
BEGIN OF ls_text ,
line TYPE char255,
END OF ls_text ,
lt_text LIKE TABLE OF ls_text . CHECK pi_text IS NOT INITIAL .
ls_text-line = pi_text . APPEND ls_text TO lt_text . CALL METHOD g_editor->delete_text. CALL METHOD g_editor->set_text_as_stream
EXPORTING
text = lt_text
EXCEPTIONS
error_dp =
error_dp_create =
OTHERS = . ENDFORM. * 3、读取文本
FORM frm_get_text CHANGING pc_text TYPE char100 .
DATA:
BEGIN OF ls_lines,
line () TYPE c,
END OF ls_lines,
lt_lines LIKE TABLE OF ls_lines. DATA: ls_textlines TYPE tline,
lt_textlines TYPE STANDARD TABLE OF tline. DATA: l_string TYPE string. CALL METHOD g_editor->get_text_as_stream
IMPORTING
text = lt_lines
EXCEPTIONS
error_dp =
error_cntl_call_method =
OTHERS = . CALL FUNCTION 'CONVERT_STREAM_TO_ITF_TEXT'
EXPORTING
language = sy-langu
TABLES
text_stream = lt_lines
itf_text = lt_textlines. CLEAR: l_string .
LOOP AT lt_textlines INTO ls_textlines.
CONCATENATE l_string ls_textlines INTO l_string .
ENDLOOP. IF l_string IS NOT INITIAL .
pc_text = l_string.
ENDIF. ENDFORM. * 4、清除文本内容 CALL METHOD g_editor_xcclxq->delete_text. * 5、g_editor->set_statusbar_mode( 0 ). "去除状态栏
g_editor->set_toolbar_mode( ). "去除工具栏
g_editor->set_readonly_mode ( ). "只读
上一篇:移动端App开发 - 02 - iPhone/iPad/Android UI尺寸规范


下一篇:.net core 程序退出事件