前置作業是建立一個 Screen,並且建立 Status 與相關 PBO/PAI,接下來在 Screen 中加入 Custom Control 物件,目前取名為 G_MLINE_TEXT。
CONSTANTS: line_length TYPE i VALUE 58. "Custom Control length - 2
DATA: g_editor TYPE REF TO cl_gui_textedit,
g_editor_container TYPE REF TO cl_gui_custom_container.
MODULE INIT_SCREEN_0100 OUTPUT.
IF g_editor_container IS INITIAL.
"create editor container on custom control
CREATE OBJECT g_editor_container
EXPORTING
container_name = 'G_MLINE_TEXT'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
"Error Handling
ELSE.
"create text editor object on editor container
CREATE OBJECT g_editor
EXPORTING
parent = g_editor_container
wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position "使用此 type 才能 g_editor->get_text_as_r3table
"cl_gui_textedit=>wordwrap_off
"cl_gui_textedit=>wordwrap_at_fixed_position
"cl_gui_textedit=>WORDWRAP_AT_WINDOWBORDER
wordwrap_position = line_length "限定寬度
wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
"hide toolbar
CALL METHOD g_editor->set_toolbar_mode
EXPORTING
toolbar_mode = cl_gui_textedit=>false.
"show Status Bar
CALL METHOD g_editor->set_statusbar_mode
EXPORTING
statusbar_mode = cl_gui_textedit=>true.
ENDIF.
ENDIF.
ENDMODULE. " INIT_SCREEN_0100 OUTPUT
MODULE USER_COMMAND_0100 INPUT.
TYPES: BEGIN OF it_txline,
line(line_length) TYPE c,
END OF it_txline.
DATA: it_tline TYPE STANDARD TABLE OF txline.
IF g_editor IS NOT INITIAL.
CALL METHOD g_editor->get_text_as_r3table
IMPORTING table = it_tline.
ENDIF.
CASE OK_CODE.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
IF g_editor IS NOT INITIAL.
CALL METHOD g_editor->free
EXCEPTIONS
OTHERS = 1.
FREE g_editor.
ENDIF.
IF g_editor_container IS NOT INITIAL.
CALL METHOD g_editor_container->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2.
FREE g_editor_container.
ENDIF.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
LOOP it_tline TO <work area>.
ENDLOOP.
取得 Internal Table 中的值
REPORT Z_EX_TEXT_MUTILINE.
DATA: OK_CODE LIKE SY-UCOMM.
CONSTANTS: line_length TYPE i VALUE 58. "Customer Container 寬度 - 2
DATA: g_editor TYPE REF TO cl_gui_textedit,
g_editor_container TYPE REF TO cl_gui_custom_container.
DATA: p_Text.
START-OF-SELECTION.
CALL SCREEN 0100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'S0100'.
SET TITLEBAR 'T0100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
TYPES: BEGIN OF it_txline,
line(line_length) TYPE c,
END OF it_txline.
DATA: it_tline TYPE STANDARD TABLE OF txline.
IF g_editor IS NOT INITIAL.
CALL METHOD g_editor->get_text_as_r3table
IMPORTING table = it_tline.
ENDIF.
CASE OK_CODE.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
IF g_editor IS NOT INITIAL.
CALL METHOD g_editor->free
EXCEPTIONS
OTHERS = 1.
FREE g_editor.
ENDIF.
IF g_editor_container IS NOT INITIAL.
CALL METHOD g_editor_container->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2.
FREE g_editor_container.
ENDIF.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
MODULE INIT_SCREEN_0100 OUTPUT.
IF g_editor_container IS INITIAL.
"create editor container on custom control
CREATE OBJECT g_editor_container
EXPORTING
container_name = 'G_MLINE_TEXT'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
"Error Handling
ELSE.
"create text editor object on editor container
CREATE OBJECT g_editor
EXPORTING
parent = g_editor_container
wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position "使用此 type 才能 g_editor->get_text_as_r3table
"cl_gui_textedit=>wordwrap_off
"cl_gui_textedit=>wordwrap_at_fixed_position
"cl_gui_textedit=>WORDWRAP_AT_WINDOWBORDER
wordwrap_position = line_length "限定寬度
wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
"hide toolbar
CALL METHOD g_editor->set_toolbar_mode
EXPORTING
toolbar_mode = cl_gui_textedit=>false.
"show Status Bar
CALL METHOD g_editor->set_statusbar_mode
EXPORTING
statusbar_mode = cl_gui_textedit=>true.
ENDIF.
ENDIF.
ENDMODULE. " INIT_SCREEN_0100 OUTPUT
TYPES: BEGIN OF it_txline,
line(line_length) TYPE c,
END OF it_txline.
DATA: it_tline TYPE TABLE OF it_txline.
CALL METHOD cl_gui_textedit->set_text_as_r3table
EXPORTING
table = it_tline
EXCEPTIONS
error_dp = 1
error_dp_create = 2
others = 3.
REPORT Z_EX_TEXT_MUTILINE.
DATA: OK_CODE LIKE SY-UCOMM.
CONSTANTS: line_length TYPE i VALUE 58. "Customer Container 寬度 - 2
DATA: g_editor TYPE REF TO cl_gui_textedit,
g_editor_container TYPE REF TO cl_gui_custom_container.
DATA: p_Text TYPE STRING.
START-OF-SELECTION.
CALL SCREEN 0100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'S0100'.
SET TITLEBAR 'T0100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
TYPES: BEGIN OF it_txline,
line(line_length) TYPE c,
END OF it_txline.
DATA: it_tline TYPE TABLE OF it_txline,
wa_tline TYPE it_txline.
IF g_editor IS NOT INITIAL.
CALL METHOD g_editor->get_text_as_r3table
IMPORTING table = it_tline.
ENDIF.
CASE OK_CODE.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
IF g_editor IS NOT INITIAL.
CALL METHOD g_editor->free
EXCEPTIONS
OTHERS = 1.
FREE g_editor.
ENDIF.
IF g_editor_container IS NOT INITIAL.
CALL METHOD g_editor_container->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2.
FREE g_editor_container.
ENDIF.
LEAVE TO SCREEN 0.
WHEN 'BUT2'.
CLEAR: P_TEXT.
PERFORM f_multi_line_set_value USING g_editor P_TEXT.
WHEN 'BUT1'.
CONCATENATE 'AAAAA' 'BBBB' 'CCCC' INTO P_TEXT
SEPARATED BY cl_abap_char_utilities=>CR_LF.
PERFORM f_multi_line_set_value USING g_editor P_TEXT.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module INIT_SCREEN_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE INIT_SCREEN_0100 OUTPUT.
IF g_editor_container IS INITIAL.
"填入 Customer Container 的 Editer Container
CREATE OBJECT g_editor_container
EXPORTING
container_name = 'G_MLINE_TEXT'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
"Error 則繼續呈現畫面不顯示 Remark (理論上不會 Error,除非傳錯 Container)
ELSE.
"產生 Multi Line Edit
CREATE OBJECT g_editor
EXPORTING
parent = g_editor_container
"使用此 type 才能 g_editor->get_text_as_r3table
wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
"cl_gui_textedit=>wordwrap_off
"cl_gui_textedit=>wordwrap_at_fixed_position
"cl_gui_textedit=>WORDWRAP_AT_WINDOWBORDER
wordwrap_position = line_length "限定寬度
wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
"不要 toolbar
CALL METHOD g_editor->set_toolbar_mode
EXPORTING
toolbar_mode = cl_gui_textedit=>false.
"要 Status Bar
CALL METHOD g_editor->set_statusbar_mode
EXPORTING
statusbar_mode = cl_gui_textedit=>true.
ENDIF.
ENDIF.
ENDMODULE. " INIT_SCREEN_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Form F_MULTI_LINE_SET_VALUE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM F_MULTI_LINE_SET_VALUE USING p_editor TYPE REF TO cl_gui_textedit
p_value.
TYPES: BEGIN OF it_txline,
line(line_length) TYPE c,
END OF it_txline.
DATA: it_tline TYPE TABLE OF it_txline,
wa_tline TYPE it_txline.
IF p_value IS INITIAL.
CLEAR: it_tline[].
ELSE.
SPLIT p_value AT cl_abap_char_utilities=>CR_LF INTO TABLE it_tline.
ENDIF.
CALL METHOD p_editor->set_text_as_r3table
EXPORTING
table = it_tline
EXCEPTIONS
error_dp = 1
error_dp_create = 2
others = 3.
ENDFORM. " F_MULTI_LINE_SET_VALUE
沒有留言:
張貼留言