1 * 1、创建文本框 2 3 DATA: g_container TYPE REF TO cl_gui_custom_container, 4 g_editor TYPE REF TO cl_gui_textedit. 5 6 IF g_container IS INITIAL. 7 8 "创建 协查处理需求 编辑框 9 CREATE OBJECT g_container 10 EXPORTING 11 container_name = 'GC_CCTRL' 12 EXCEPTIONS 13 cntl_error = 1 14 cntl_system_error = 2 15 create_error = 3 16 lifetime_error = 4 17 lifetime_dynpro_dynpro_link = 5 . 18 IF sy-subrc <> 0. 19 EXIT . 20 ENDIF . 21 22 CREATE OBJECT g_editor 23 EXPORTING 24 max_number_chars = 255 "字数限制 25 parent = g_container 26 wordwrap_mode = 0 "边框模式,设置为0可以去掉编辑框的滚动条 27 wordwrap_position = 95 "换行宽度 28 EXCEPTIONS 29 error_cntl_create = 1 30 error_cntl_init = 2 31 error_cntl_link = 3 32 error_dp_create = 4 33 gui_type_not_supported = 5 34 OTHERS = 6. 35 IF sy-subrc <> 0. 36 MESSAGE e000(oo ) WITH '创建编辑框失败 !' . 37 ENDIF . 38 ENDIF . 39 "wordwrap_mode:边框模式,设置为0可以去掉编辑框的滚动条设置为2可以自动换行 40 41 42 43 * 2、设置文本框的内容 44 * PS: set_text_as_stream 无法设置多行,需要设置多行,用 set_text_as_r3table 45 46 FORM frm_set_text USING pi_text TYPE char100 . 47 DATA: 48 BEGIN OF ls_text , 49 line TYPE char255, 50 END OF ls_text , 51 lt_text LIKE TABLE OF ls_text . 52 53 CHECK pi_text IS NOT INITIAL . 54 ls_text-line = pi_text . 55 56 APPEND ls_text TO lt_text . 57 58 CALL METHOD g_editor->delete_text. 59 60 CALL METHOD g_editor->set_text_as_stream 61 EXPORTING 62 text = lt_text 63 EXCEPTIONS 64 error_dp = 1 65 error_dp_create = 2 66 OTHERS = 3. 67 68 ENDFORM. 69 70 * 3、读取文本 71 FORM frm_get_text CHANGING pc_text TYPE char100 . 72 DATA: 73 BEGIN OF ls_lines, 74 line (255) TYPE c, 75 END OF ls_lines, 76 lt_lines LIKE TABLE OF ls_lines. 77 78 DATA: ls_textlines TYPE tline, 79 lt_textlines TYPE STANDARD TABLE OF tline. 80 81 DATA: l_string TYPE string. 82 83 CALL METHOD g_editor->get_text_as_stream 84 IMPORTING 85 text = lt_lines 86 EXCEPTIONS 87 error_dp = 1 88 error_cntl_call_method = 2 89 OTHERS = 3. 90 91 CALL FUNCTION 'CONVERT_STREAM_TO_ITF_TEXT' 92 EXPORTING 93 language = sy-langu 94 TABLES 95 text_stream = lt_lines 96 itf_text = lt_textlines. 97 98 CLEAR: l_string . 99 LOOP AT lt_textlines INTO ls_textlines. 100 CONCATENATE l_string ls_textlines INTO l_string . 101 ENDLOOP. 102 103 IF l_string IS NOT INITIAL . 104 pc_text = l_string. 105 ENDIF. 106 107 ENDFORM. 108 109 110 * 4、清除文本内容 111 112 CALL METHOD g_editor_xcclxq->delete_text. 113 114 * 5、g_editor->set_statusbar_mode( 0 ). "去除状态栏 115 g_editor->set_toolbar_mode( 0 ). "去除工具栏 116 g_editor->set_readonly_mode ( 1 ). "只读
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19202.html