Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
raghu_ps
Explorer

In ABAP (Advanced Business Application Programming), cl_gui_textedit is a class used for creating and manipulating text editor controls in Object-Oriented ABAP (OOABAP). This class is part of the SAP GUI (Graphical User Interface) framework and is specifically designed for handling text editing within SAP GUI applications. 

Here's a brief explanation of how you can use cl_gui_textedit in OOABAP: 

cl_gui_custom_container class is used to embed custom controls or UI elements within a container on the SAP GUI screen. This class is part of the Object-Oriented ABAP (OOABAP) programming paradigm. The cl_gui_custom_container class is often used in combination with other classes and methods to create interactive and customized user interfaces. 

Creating an Instance:  

To use the cl_gui_textedit and cl_gui_custom_container class, you first need to create an instance of the class. You can do this using the create object statement. 

raghu_ps_0-1706508241105.png

Create screen 101 (Modal Screen in this case) by double clicking on “101”. 

Create a custom control on the screen with the name “CONTAINER”. 

raghu_ps_1-1706508423628.png

Now, add the logic for displaying the edit control in PBO and PAI Modules of screen 101. 

In pbo, create object container go_custom. Then create text editor object by exporting the container go_custom. 

    if go_custom initial 

raghu_ps_2-1706508537983.png

Create object for go_textedit 

raghu_ps_3-1706508601243.png

The cl_gui_textedit class in ABAP is used for displaying and editing text. The set_text_as_r3table method is used to set the content of the text editor as a table that is typically used in SAP R/3 systems. This method allows you to display tabular data within a cl_gui_textedit control in an Object-Oriented ABAP (OOABAP) program. 

raghu_ps_4-1706508662720.png

The method set_readonly_mode is used to set the read-only mode of the text editor. 

read-only mode; eq 0: off; ne 0: on 

raghu_ps_5-1706508820956.png

Database Table 

raghu_ps_6-1706508873893.png

Source CodeThe complete coding of the executable program is given below. 

*&---------------------------------------------------------------------*
*& Report ZPS_RP_TEXTEDIT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zps_rp_textedit.
PARAMETERS : p_textid TYPE zps_t_textedit-id. 
  
DATA :  go_custom    TYPE REF TO cl_gui_custom_container, 
        go_textedit TYPE REF TO cl_gui_textedit, 
        gt_text     TYPE TABLE OF char255, 
        gv_flag(1).

START-OF-SELECTION. 
  
SELECT FROM zps_t_textedit FIELDS text WHERE id = @p_textid INTO TABLE @GT_text. 
  CALL SCREEN 101. 

raghu_ps_7-1706509291210.png

PROCESS BEFORE OUTPUT 

*&---------------------------------------------------------------------* 
 *& Module STATUS_0101 OUTPUT 
 *&---------------------------------------------------------------------* 
 *& 
 *&---------------------------------------------------------------------* 
 MODULE STATUS_0101 OUTPUT. 
   SET PF-STATUS 'PF_STATUS'. 
   SET TITLEBAR 'Text editor'. 
 ENDMODULE. 

Create one edit button in application toolbar 

raghu_ps_8-1706509392750.png

Create function key for SAVE and BACK 

raghu_ps_9-1706509479415.png

MODULE create_container OUTPUT. 
 

MODULE create_container OUTPUT. 
  
  CREATE OBJECT go_custom 
     EXPORTING 
       container_name              = 'CONTAINER' 
       repid                       = sy-repid 
       dynnr                       = sy-dynnr 
     EXCEPTIONS 
       cntl_error                  = 1 
       cntl_system_error           = 2 
       create_error                = 3 
       lifetime_error              = 4 
       lifetime_dynpro_dynpro_link = 5 
       OTHERS                      = 6. 
  
ENDMODULE. 
MODULE create_text_edit OUTPUT. 
  
  IF go_textedit IS NOT BOUND. 
     CREATE OBJECT go_textedit 
       EXPORTING 
         parent                 = go_custom 
       EXCEPTIONS 
         error_cntl_create      = 1 
         error_cntl_init        = 2 
         error_cntl_link        = 3 
         error_dp_create        = 4 
         gui_type_not_supported = 5 
         OTHERS                 = 6. 
   ENDIF. 
  
  CALL METHOD go_textedit->set_text_as_r3table 
     EXPORTING 
       table           = gt_text 
     EXCEPTIONS 
       error_dp        = 1 
       error_dp_create = 2 
       OTHERS          = 3. 
  
  IF gv_flag IS INITIAL. 
  
    CALL METHOD go_textedit->set_readonly_mode 
       EXPORTING 
         readonly_mode          = 1 
       EXCEPTIONS 
         error_cntl_call_method = 1 
         invalid_parameter      = 2 
         OTHERS                 = 3. 
  
  ENDIF. 
  
  gv_flag = 1. 
  
ENDMODULE. 

PROCESS AFTER INPUT 

MODULE user_command_0101 INPUT. 
   CASE sy-ucomm. 
     WHEN TEXT-002.               " BACK. 
       LEAVE TO SCREEN 0. 
  
    WHEN TEXT-003 OR TEXT-004.   "EDIT and SAVE. 
  
      IF gv_flag IS NOT INITIAL. 
         CALL METHOD go_textedit->set_readonly_mode 
           EXPORTING 
             readonly_mode          = 0 
           EXCEPTIONS 
             error_cntl_call_method = 1 
             invalid_parameter      = 2 
             OTHERS                 = 3. 
       ENDIF. 
  
      CALL METHOD go_textedit->get_text_as_r3table 
         IMPORTING 
           table                  = gt_text 
         EXCEPTIONS 
           error_dp               = 1 
           error_cntl_call_method = 2 
           error_dp_create        = 3 
           potential_data_loss    = 4 
           OTHERS                 = 5. 
  
      DATA(ls_text) = gt_text[ 1 ].      "Read text from an internal table 
  
      UPDATE zps_t_textedit SET text =  ls_text . 
  
      IF sy-subrc = 0. 
         MESSAGE s001(zps_msg_text).       "Record Updateded Sucessfully 
       ENDIF. 
  
    WHEN OTHERS. 
   ENDCASE. 
 ENDMODULE. 

Before editing text in database table  

raghu_ps_10-1706509822042.png

Based on text id displaying text details 

raghu_ps_11-1706509822044.png

For Editing text 

Click edit button in Application Toolbar 

raghu_ps_12-1706509822045.png

Edit text and click on save button  

raghu_ps_13-1706509822046.png

After editing text in database table 

raghu_ps_14-1706509822047.png

 

4 Comments
Sandra_Rossi
Active Contributor

Please format your code via the option "..." and "</>" to make your blog post more attractive, e.g.

  CALL METHOD go_textedit->set_text_as_r3table 
     EXPORTING 
       table           = gt_text 
     EXCEPTIONS 
       error_dp        = 1 
       error_dp_create = 2 
       OTHERS          = 3. 

versus its ugly non-formatted version:

  CALL METHOD go_textedit->set_text_as_r3table 
     EXPORTING 
       table           = gt_text 
     EXCEPTIONS 
       error_dp        = 1 
       error_dp_create = 2 
       OTHERS          = 3. 

ennowulff
Active Contributor

If you don't do any error handling, you can delete the EXCEPTIONS. If any of these exceptions occur, there is a GUI problem and the program will dump. IMO this is a valid error handling in this case because the program cannot be continued anyway.

You should use the modern way of calling methods to save disk space and enhance readability:

go_textedit->set_readonly_mode( 0 ).

 It is not a good way to use TEXT strings for the user commands. Instead you should use literals or constants.

thomas_mller13
Participant
0 Kudos

ABAP = "Allgemeiner Berichtsaufbereitungsprozessor". Advanced ... is your invention?

By the way: These are well known topics in GUI programming. You should not code directly in modules, since all variables are global there. Furthermore it is in general enough to have 2 modules. PAI and PBO. Finally you have to free the OCX by calling the method "free" on the control object. 

 

Sandra_Rossi
Active Contributor
0 Kudos

@thomas_mller13 No need to ask, search and you'll get the answer at many places, even in the English Wikipedia.