Introduction
Sometimes there is requirement to enter more than 255 characters in a select-option/parameter on the selection screen. During such scenario we can make use of edit text control. Edit Text Control can be called on pressing the pushbutton which can be provided against the required select-option/parameter.
This document provides the steps for creating Edit Text Control (Editable and Non-Editable) on the selection screen.
Steps
1) Selection Screen creation
Create Parameter and corresponding pushbutton in the selection screen for which text control needs to be created.
.
*/.. Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
*/.. Parameter for Text Edit Control
PARAMETERS: P_TEXT TYPE char40 MODIF ID md1.
SELECTION-SCREEN PUSHBUTTON 75(8) but1 USER-COMMAND click MODIF ID md1.
SELECTION-SCREEN END OF BLOCK b1.
For the Parameter P_TEXT provide pushbutton "BUT1".On pressing this pushbutton "Edit Text Control" should be displayed in which text more than 255 characters can be entered and used accordingly.
The above selection screen would be displayed as:-
2) The next step is to provide ICON/Text for the above declared Pushbutton.
Call FM "ICON_CREATE" to provide the ICON for the pushbutton. This FM should be called at " INITIALIZATION".
gv_icon_name = 'ICON_DISPLAY_MORE'.
gv_quickinfo = 'TE'.
CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = gv_icon_name
text = 'TE'
info = gv_quickinfo
IMPORTING
RESULT = gv_icon_result
EXCEPTIONS
icon_not_found = 1
outputfield_too_short = 2
OTHERS = 3.
IF sy-subrc EQ 0.
but1 = gv_icon_result.
ENDIF.
Selection Screen after the above Step:-
3) On clicking this pushbutton, edit text control should be displayed. For this Call the screen (can be any number) 9001 in "AT SELECTION-SCREEN" .
IF sscrfields-ucomm EQ 'CLICK'.
CALL SCREEN 9001 STARTING AT 10 5.
ENDIF.
4) Create screen 9001 (Modal Screen in this case) by double clicking on "9001".
Create a custom control on the screen with name "CONTAINER".
Now, add the logic for displaying the edit control in PBO and PAI Modules of screen 9001.
5) In PBO, create object container GV_CONTAINER. Then create text editor object by exporting
the container GV_CONTAINER.
IF gv_container IS INITIAL.
CREATE OBJECT gv_container
EXPORTING
container_name = 'CONTAINER'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
ENDIF.
CREATE OBJECT gv_text_editor
EXPORTING
parent = gv_container
wordwrap_mode = '2'
wordwrap_position = '250'
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
gui_type_not_supported = 5.
gv_text_newtxt = p_text.
IF gv_text_newtxt <> gv_text_oldtxt.
REFRESH gi_texttab.
APPEND gv_text_newtxt TO gi_texttab.
ENDIF.
gv_text_editor->set_text_as_r3table( EXPORTING table = gi_texttab[] ).
gv_text_oldtxt = gv_text_newtxt.
*/.. Set focus on the editor.
CALL METHOD cl_gui_docking_container=>set_focus
EXPORTING
control = gv_text_editor.
CALL METHOD gv_text_editor->set_readonly_mode
EXPORTING
readonly_mode = 0
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
Note- In case u want to make this text edit control read only i.e. non editable then pass import parameter readonly_mode = "1" instead of "0" in the method gv_text_editor->set_readonly_mode.
6) Define and Create GUI Status and Title Bar in the PBO.
set pf-status 'POPUP'.
set titlebar 'POPUP'.
7) In PAI of Screen 9001, User Commands of the screen will be handled:-
case sy-ucomm.
when 'OK'.
gv_text_editor->get_text_as_r3table( importing table =
gi_texttab[] ).
export tab from gi_texttab[] to memory id 'ABC' compression on.
call method cl_gui_cfw=>flush
exceptions
others = 3.
set screen 0.leave screen.
when 'CANCEL'.
set screen 0.leave screen.
endcase.
The Text which is written in text edit control is collected into the internal table GI_TEXTTAB[] and can be used as per the requirement.
Summary - In the above example, steps for creating edit text control on the selection screen both in editable and non-editable form has been explained.
Source Code - The complete coding of the executable program is given below.
REPORT ZTEST_EDITCONTROL.
*/.. Data DeclarationTABLES : sscrfields.
DATA : gv_icon_name TYPE iconname,
gv_quickinfo LIKE smp_dyntxt-quickinfo,
gv_okcode TYPE sy-ucomm,
gv_icon_result(255) TYPE c.
DATA: gv_container TYPE REF TO cl_gui_custom_container,
gv_text_editor TYPE REF TO cl_gui_textedit,
gv_text_newtxt TYPE string,
gv_text_oldtxt TYPE string,
gi_texttab TYPE soli_tab.
CONSTANTS : gc_button_text TYPE c LENGTH 10 VALUE 'TE'.
*/.. Selection ScreenSELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.*/.. Parameter for Text Edit Control
PARAMETERS: p_text TYPE char40 MODIF ID md1.SELECTION-SCREEN PUSHBUTTON 75(8) but1 USER-COMMAND click MODIF ID md1.SELECTION-SCREEN END OF BLOCK b1.
************************************************************************ I N I T I A L I Z A T I O N ************************************************************************
INITIALIZATION.
gv_icon_name = 'ICON_DISPLAY_MORE'.
gv_quickinfo = 'TE'.
CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = gv_icon_name
text = gc_button_text
info = gv_quickinfo
IMPORTING
RESULT = gv_icon_result
EXCEPTIONS
icon_not_found = 1
outputfield_too_short = 2
OTHERS = 3.
IF sy-subrc EQ 0.
but1 = gv_icon_result.
ENDIF.
*---------------------------------------------------------------------** At selection-screen*---------------------------------------------------------------------*at selection-screen.*/.. Open text editor on click of the button.
IF sscrfields-ucomm EQ 'CLICK'.
CALL SCREEN 9001 STARTING AT 10 5.
ENDIF.*&---------------------------------------------------------------------**& Module STATUS_9001 OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE status_9001 OUTPUT.
SET PF-STATUS 'POPUP'.
SET TITLEBAR 'POPUP'.
IF gv_container IS INITIAL.
CREATE OBJECT gv_container
EXPORTING
container_name = 'CONTAINER'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
ENDIF.
CREATE OBJECT gv_text_editor
EXPORTING
parent = gv_container
wordwrap_mode = '2'
wordwrap_position = '250'
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
gui_type_not_supported = 5.
gv_text_newtxt = p_text.
IF gv_text_newtxt <> gv_text_oldtxt.
REFRESH gi_texttab.
APPEND gv_text_newtxt TO gi_texttab.
ENDIF.
gv_text_editor->set_text_as_r3table( EXPORTING table = gi_texttab[] ).
gv_text_oldtxt = gv_text_newtxt.
*/.. Set focus on the editor.
CALL METHOD cl_gui_docking_container=>set_focus
EXPORTING
control = gv_text_editor.
CALL METHOD gv_text_editor->set_readonly_mode
EXPORTING
readonly_mode = 0
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
ENDMODULE. " STATUS_9001 OUTPUT*&---------------------------------------------------------------------**& Module USER_COMMAND_9001 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9001 INPUT.
CASE sy-ucomm.
WHEN 'OK'.
gv_text_editor->get_text_as_r3table( IMPORTING table =
gi_texttab[] ).
EXPORT tab FROM gi_texttab[] TO MEMORY ID 'ABC' COMPRESSION ON.
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
OTHERS = 3.
SET SCREEN 0.LEAVE SCREEN.
WHEN 'CANCEL'.
SET SCREEN 0.LEAVE SCREEN.
ENDCASE.
ENDMODULE. " USER_COMMAND_9001 INPUT
On Executing the above Program: -
Press the pushbutton as highlighted above.
Text Edit Control is displayed in which text will be entered and used as per the requirement.
In case you want to make this text edit control non-editable, then in the PBO just replace the code
CALL METHOD gv_text_editor->set_readonly_mode
EXPORTING
readonly_mode = 0
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
with
CALL METHOD gv_text_editor->set_readonly_mode
EXPORTING
readonly_mode = 1
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
On pressing the pushbutton,