2021 Jun 24 5:51 PM
Hello Gurus,
I have the requirement on selection screen such that I need to create a text editor and display the text which maintained in SO10 in display mode on selection screen based on dropdown list.
First, I have created instance for docking container, created instance for splitter container and assigned the parent as docking container and instantiated text editor with parent as one of the container of the splitter container.
Everything is working fine for the first time after choosing dropdown list value and press enter. When I chose another dropdown list and press enter it should show different text. It is showing different text along with previous text. Here I need to clear the Previous text. I tried the method call method splitter->free, also tried text_editor->free, didnt work for me. How can I achieve this?
Thanks and Regards,
Muralikrishna Peravali.
2021 Jun 24 8:11 PM
Hi Murali,
Try out below code snippet. It is working fine now. The issue was, the reference data object that you have declarated is inside the subroutine. So, once the control goes out from subroutine, the values are lost. Hence, the condition "IF lo_text_editor IS NOT BOUND", will fail every time and a new docking container will be created. This can be fixed by declaring the reference variables as global, so that once the control goes out from the subrounine, the reference will be there and "IF lo_text_editor IS NOT BOUND" will work and a new container will not be created. Rather it will just refresh it.
*&---------------------------------------------------------------------*
*& Report ZTEST_1234
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztest_1234.
DATA:
gt_values TYPE vrm_values,
gwa_values LIKE LINE OF gt_values.
TYPES : BEGIN OF lty_text,
text TYPE tdline,
END OF lty_text.
DATA : lo_splitter_container TYPE REF TO cl_gui_splitter_container,
lo_bottom_container TYPE REF TO cl_gui_container,
lo_docking_container TYPE REF TO cl_gui_docking_container,
lv_text_name TYPE thead-tdname,
lt_text_editor TYPE STANDARD TABLE OF lty_text,
lwa_text TYPE lty_text,
lo_text_editor TYPE REF TO cl_gui_textedit,
lt_text TYPE TABLE OF tline..
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-t03.
PARAMETERS: p_sum TYPE char8 AS LISTBOX VISIBLE LENGTH 10.
SELECTION-SCREEN END OF BLOCK b3.
INITIALIZATION.
** Drop down
gwa_values-key = 'Option-1'.
APPEND gwa_values TO gt_values.
CLEAR : gwa_values.
gwa_values-key = 'Option-2'.
APPEND gwa_values TO gt_values.
* Call the FM: VRM_SET_VALUES to set in selection screen
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_SUM'
values = gt_values
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
IF sy-subrc IS INITIAL.
" Do nothing.
ENDIF.
AT SELECTION-SCREEN.
** Display Text editor with disable mode in Selection screen.
PERFORM f_display_text_editor.
FORM f_display_text_editor .
** For Text editor
** Get the text based on options chosen by business
IF p_sum EQ 'OPTION-1'.
lv_text_name = 'ZCOC_COM_DECL_OPT1'.
ELSE.
lv_text_name = 'ZCOC_COM_DECL_OPT2'.
ENDIF.
*FI_CASH_EB
*FI_CASH_SI
* Get the Text by calling FM: READ_TEXT
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = 'ST'
language = sy-langu
name = lv_text_name
object = 'TEXT'
TABLES
lines = lt_text[]
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
** Create Docking container Object.
IF lo_docking_container IS NOT BOUND. "INITIAL.
CREATE OBJECT lo_docking_container
EXPORTING
* parent =
repid = sy-repid
dynnr = '1000'
side = cl_gui_docking_container=>dock_at_bottom
extension = 50
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.
ENDIF.
* Instantiate the Splitter container with reference of Docking contanet
IF lo_splitter_container IS NOT BOUND. "INITIAL.
CREATE OBJECT lo_splitter_container
EXPORTING
parent = lo_docking_container
rows = 1
columns = 2
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* Reduce the border size
CALL METHOD lo_splitter_container->set_row_sash
EXPORTING
id = 1
type = cl_gui_splitter_container=>type_sashvisible
value = cl_gui_splitter_container=>false
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDIF.
* Get the GUI Containers to display in selection screen.
* IF lo_bottom_container IS INITIAL.
CALL METHOD lo_splitter_container->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = lo_bottom_container.
* ENDIF.
* Create the object for text edior.
IF lo_text_editor IS NOT BOUND. "INITIAL.
CREATE OBJECT lo_text_editor
EXPORTING
wordwrap_mode = 0
parent = lo_bottom_container
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.
ELSE.
** Disable the tool bar and status bar.
CALL METHOD lo_text_editor->set_toolbar_mode
EXPORTING
toolbar_mode = '0'
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CALL METHOD lo_text_editor->set_statusbar_mode
EXPORTING
statusbar_mode = '0'
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDIF.
* Display the Text in Selection screen text editor.
IF NOT lt_text IS INITIAL.
REFRESH lt_text_editor.
LOOP AT lt_text INTO DATA(lwa_line).
MOVE lwa_line-tdline TO lwa_text-text.
APPEND lwa_text TO lt_text_editor.
CLEAR : lwa_line, lwa_text.
ENDLOOP.
CALL METHOD lo_text_editor->delete_text.
cl_gui_cfw=>flush( ).
** Set the Text into Text editor
CALL METHOD lo_text_editor->set_text_as_r3table
EXPORTING
table = lt_text_editor[]
EXCEPTIONS
error_dp = 1
error_dp_create = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* Set the Editor in Display mode
CALL METHOD lo_text_editor->set_readonly_mode
EXPORTING
readonly_mode = 1
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDFORM.
Hope this clears your doubt.
Thanks,
Gourab
2021 Jun 24 6:14 PM
Hi Muralisrishna,
I am assuming you are using textedit(CL_GUI_TEXTEDIT). To clear the text, there is a method available in the class "DELETE_TEXT". Have you tried using that?
Also, after writting your code, try using the method "flush" of class cl_gui_cfw. Sometime, the changes does not reflect immediately, so this method should be used.
CL_GUI_CFW=>FLUSH( ).
Let me know if this still doesnot work.
Thanks,
Gourab
2021 Jun 24 6:26 PM
Hello Gourab,
Thank you for your quick response.
Yes, i am using CL_GUI_TEXTEDIT. I have called the method CALL METHOD text_editor->delete_text before mehod: set_text_as_r3table and called cl_gui_cfw=>flush( ) at the end.
But still it is not working.
Thanks and Regards,
Muralikrishna Peravali.
2021 Jun 24 6:37 PM
It should work. Can you check your internal table. Is you internal table has existing value?
If still this is not working, attach you code. Will check it.
Thanks,
Gourab
2021 Jun 24 6:41 PM
2021 Jun 24 6:56 PM
Hi Murali,
You only shared the code related to docking text edit, which not executable. Please share the complete program.
From the code you have shared, I see 2 error. You have compared the "IF lo_docking_container IS INITIAL.", which is wrong,bcoz it's a reference data object.
The correct syntax is :
IF lo_docking_container IS BOUND.
ENDIF.Next, call cl_gui_cfw=>flush( ) after delete text
CALL METHOD lo_text_editor->delete_text.
cl_gui_cfw=>flush( ).Thanks,
Gourab
2021 Jun 24 7:51 PM
Hello Gourab,
When i change the docking_container is bound then system is throwing dump. So, I made it as docking_container is not bound.
As suggested by you I have changed the code but still it is not working. The text should be clear on selection screen only.
Attached the code with parameter which i defined and logic. Once this is resolved I need to write further logic.
Thanks and Regards,
Muralikrishna Peravali.
2021 Jun 24 8:01 PM
As per your code that you attached in the other answer, your error is to have defined the references to the GUI controls as local variables. Every time the subroutine is executed, the references are not bound. You would see that if you had used the debug.
Define them as global variables.
2021 Jun 24 8:24 PM
Hello Sandra,
Yes, I did a mistake to define the reference variables in subroutine thats why issue.
Now, I have corrected as per Gourab and it is working fine.
Thank you for your valuable time.
Thanks and Regards,
Muralikrishna Peravali.
2021 Jun 24 8:11 PM
Hi Murali,
Try out below code snippet. It is working fine now. The issue was, the reference data object that you have declarated is inside the subroutine. So, once the control goes out from subroutine, the values are lost. Hence, the condition "IF lo_text_editor IS NOT BOUND", will fail every time and a new docking container will be created. This can be fixed by declaring the reference variables as global, so that once the control goes out from the subrounine, the reference will be there and "IF lo_text_editor IS NOT BOUND" will work and a new container will not be created. Rather it will just refresh it.
*&---------------------------------------------------------------------*
*& Report ZTEST_1234
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztest_1234.
DATA:
gt_values TYPE vrm_values,
gwa_values LIKE LINE OF gt_values.
TYPES : BEGIN OF lty_text,
text TYPE tdline,
END OF lty_text.
DATA : lo_splitter_container TYPE REF TO cl_gui_splitter_container,
lo_bottom_container TYPE REF TO cl_gui_container,
lo_docking_container TYPE REF TO cl_gui_docking_container,
lv_text_name TYPE thead-tdname,
lt_text_editor TYPE STANDARD TABLE OF lty_text,
lwa_text TYPE lty_text,
lo_text_editor TYPE REF TO cl_gui_textedit,
lt_text TYPE TABLE OF tline..
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-t03.
PARAMETERS: p_sum TYPE char8 AS LISTBOX VISIBLE LENGTH 10.
SELECTION-SCREEN END OF BLOCK b3.
INITIALIZATION.
** Drop down
gwa_values-key = 'Option-1'.
APPEND gwa_values TO gt_values.
CLEAR : gwa_values.
gwa_values-key = 'Option-2'.
APPEND gwa_values TO gt_values.
* Call the FM: VRM_SET_VALUES to set in selection screen
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_SUM'
values = gt_values
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
IF sy-subrc IS INITIAL.
" Do nothing.
ENDIF.
AT SELECTION-SCREEN.
** Display Text editor with disable mode in Selection screen.
PERFORM f_display_text_editor.
FORM f_display_text_editor .
** For Text editor
** Get the text based on options chosen by business
IF p_sum EQ 'OPTION-1'.
lv_text_name = 'ZCOC_COM_DECL_OPT1'.
ELSE.
lv_text_name = 'ZCOC_COM_DECL_OPT2'.
ENDIF.
*FI_CASH_EB
*FI_CASH_SI
* Get the Text by calling FM: READ_TEXT
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = 'ST'
language = sy-langu
name = lv_text_name
object = 'TEXT'
TABLES
lines = lt_text[]
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
** Create Docking container Object.
IF lo_docking_container IS NOT BOUND. "INITIAL.
CREATE OBJECT lo_docking_container
EXPORTING
* parent =
repid = sy-repid
dynnr = '1000'
side = cl_gui_docking_container=>dock_at_bottom
extension = 50
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.
ENDIF.
* Instantiate the Splitter container with reference of Docking contanet
IF lo_splitter_container IS NOT BOUND. "INITIAL.
CREATE OBJECT lo_splitter_container
EXPORTING
parent = lo_docking_container
rows = 1
columns = 2
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* Reduce the border size
CALL METHOD lo_splitter_container->set_row_sash
EXPORTING
id = 1
type = cl_gui_splitter_container=>type_sashvisible
value = cl_gui_splitter_container=>false
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDIF.
* Get the GUI Containers to display in selection screen.
* IF lo_bottom_container IS INITIAL.
CALL METHOD lo_splitter_container->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = lo_bottom_container.
* ENDIF.
* Create the object for text edior.
IF lo_text_editor IS NOT BOUND. "INITIAL.
CREATE OBJECT lo_text_editor
EXPORTING
wordwrap_mode = 0
parent = lo_bottom_container
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.
ELSE.
** Disable the tool bar and status bar.
CALL METHOD lo_text_editor->set_toolbar_mode
EXPORTING
toolbar_mode = '0'
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CALL METHOD lo_text_editor->set_statusbar_mode
EXPORTING
statusbar_mode = '0'
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDIF.
* Display the Text in Selection screen text editor.
IF NOT lt_text IS INITIAL.
REFRESH lt_text_editor.
LOOP AT lt_text INTO DATA(lwa_line).
MOVE lwa_line-tdline TO lwa_text-text.
APPEND lwa_text TO lt_text_editor.
CLEAR : lwa_line, lwa_text.
ENDLOOP.
CALL METHOD lo_text_editor->delete_text.
cl_gui_cfw=>flush( ).
** Set the Text into Text editor
CALL METHOD lo_text_editor->set_text_as_r3table
EXPORTING
table = lt_text_editor[]
EXCEPTIONS
error_dp = 1
error_dp_create = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* Set the Editor in Display mode
CALL METHOD lo_text_editor->set_readonly_mode
EXPORTING
readonly_mode = 1
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDFORM.
Hope this clears your doubt.
Thanks,
Gourab
2021 Jun 24 8:22 PM
Thank you, gourab. It is working fine now. I did a mistake that the reference object declared as local. As you said it will always create a new container.
Thanks and Regards,
Muralikrishna Peravali.