Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sample code using CL_GUI_TEXTEDIT

Former Member
0 Likes
17,242

Hi gurus,

I have a requirement to create a text editor in a screen using which data can be save multiple lines in a custom table and can view in display mode. how to use class CL_GUI_TEXTEDIT for this.

thanks.

5 REPLIES 5
Read only

uwe_schieferstein
Active Contributor
4,742

Hello Sudipa

Sample report ZUS_SDN_TEXTEDIT_CONTROL shows you the basics of dealing with the textedit control. By entering TOGGLE into the command window you can switch between edit mode and read-only mode.

Further reading: thread


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_TEXTEDIT_CONTROL
*&
*&---------------------------------------------------------------------*
*& Thread: sample code using CL_GUI_TEXTEDIT
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1149007"></a>
*&
*& Thread: how to clear the text in the Text Editor
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1145272"></a>
*&---------------------------------------------------------------------*
*& By default the itab GT_OUTTAB contains texts in DE and EN.
*& To switch the language directly enter into the command window:
*& LANGU=DE, LANGU=EN or LANGU=FR
*&
*& ok-code TOGGLE: switch edit/read-only mode
*&---------------------------------------------------------------------*
REPORT  zus_sdn_textedit_control.


TYPE-POOLS: abap.


TYPES: ty_t_text     TYPE TABLE OF as4text
                     WITH DEFAULT KEY.

TYPES: BEGIN OF ty_s_outtab.
TYPES: language TYPE spras.
TYPES: text     TYPE ty_t_text.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                      WITH DEFAULT KEY.

DATA: gt_outtab       TYPE ty_t_outtab,
      gs_outtab       TYPE ty_s_outtab.
DATA: gd_language     TYPE spras.


DATA: go_docking      TYPE REF TO cl_gui_docking_container,
      go_textedit     TYPE REF TO cl_gui_textedit,
      gd_mode         type i  VALUE cl_gui_textedit=>false.

DATA: gd_okcode       TYPE ui_func,
      gd_repid        TYPE syst-repid.


START-OF-SELECTION.

  PERFORM fill_texts.
  gd_language = syst-langu.

  PERFORM init_controls.

* Link the docking container to the target dynpro
  gd_repid  = syst-repid.
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = gd_repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      OTHERS                      = 4.
  IF sy-subrc NE 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  PERFORM set_text_editor.


* NOTE: dynpro does not contain any elements
  "       ok-code => GD_OKCODE
  CALL SCREEN '0100'.
* Flow logic of dynpro (does not contain any dynpro elements):
*
*PROCESS BEFORE OUTPUT.
*  MODULE STATUS_0100.
**
*PROCESS AFTER INPUT.
*  MODULE USER_COMMAND_0100.


END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.  " contains push button "DETAIL"
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  TRANSLATE gd_okcode TO UPPER CASE.

  CASE gd_okcode.
    WHEN 'BACK'  OR
         'EXIT'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.

    WHEN 'TOGGLE'.
      PERFORM toggle_mode.

    WHEN 'LANGU=DE' OR
         'LANGU=EN' OR
         'LANGU=FR'.

      PERFORM get_text_editor.

      SPLIT gd_okcode AT '=' INTO gd_okcode gd_language.

      PERFORM set_text_editor.

    WHEN OTHERS.
  ENDCASE.

  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT


*&---------------------------------------------------------------------*
*&      Form  FILL_TEXTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_texts .
* define local data
  DATA: ld_string   TYPE string.

  gs_outtab-language = 'EN'. REFRESH: gs_outtab-text.
  ld_string = 'Good morning'.
  APPEND ld_string TO gs_outtab-text.
  APPEND gs_outtab TO gt_outtab.

  gs_outtab-language = 'DE'. REFRESH: gs_outtab-text.
  ld_string = 'Guten Morgen'.
  APPEND ld_string TO gs_outtab-text.
  APPEND gs_outtab TO gt_outtab.

  gs_outtab-language = 'FR'. REFRESH: gs_outtab-text.
  ld_string = space.
  APPEND ld_string TO gs_outtab-text.
  APPEND gs_outtab TO gt_outtab.

ENDFORM.                    " FILL_TEXTS

*&---------------------------------------------------------------------*
*&      Form  INIT_CONTROLS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM init_controls .

  CREATE OBJECT go_docking
    EXPORTING
      parent                      = cl_gui_container=>screen0
*      repid                       =
*      dynnr                       =
*      side                        = dock_at_left
*      extension                   = 50
*      style                       =
*      lifetime                    = lifetime_default
*      caption                     =
*      metric                      = 0
      ratio                       = 90
*      no_autodef_progid_dynnr     =
*      name                        =
    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.

  CREATE OBJECT go_textedit
    EXPORTING
*      max_number_chars       =
*      style                  = 0
*      wordwrap_mode          = wordwrap_at_windowborder
*      wordwrap_position      = -1
*      wordwrap_to_linebreak_mode = false
*      filedrop_mode          = dropfile_event_off
      parent                 = go_docking
*      lifetime               =
*      name                   =
    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.
  ENDIF.


ENDFORM.                    " INIT_CONTROLS


*&---------------------------------------------------------------------*
*&      Form  SET_TEXT_EDITOR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_text_editor .


  CLEAR: gs_outtab.
  READ TABLE gt_outtab INTO gs_outtab
       WITH KEY language = gd_language.


  CALL METHOD go_textedit->set_text_as_stream
    EXPORTING
      text            = gs_outtab-text
    EXCEPTIONS
      error_dp        = 1
      error_dp_create = 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.
  ENDIF.


ENDFORM.                    " SET_TEXT_EDITOR


*&---------------------------------------------------------------------*
*&      Form  GET_TEXT_EDITOR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_text_editor .

  CLEAR: gs_outtab.

  CALL METHOD go_textedit->get_text_as_stream
    EXPORTING
      only_when_modified     = cl_gui_textedit=>true
    IMPORTING
      text                   = gs_outtab-text
*      is_modified            =
    EXCEPTIONS
      error_dp               = 1
      error_cntl_call_method = 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.
  ENDIF.

  MODIFY gt_outtab FROM gs_outtab
    TRANSPORTING text
    WHERE ( language = gd_language ).


ENDFORM.                    " GET_TEXT_EDITOR


*&---------------------------------------------------------------------*
*&      Form  TOGGLE_MODE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM toggle_mode .
* define local data
  DATA: ld_mode     TYPE i.


  if ( gd_mode = cl_gui_textedit=>true ).
    gd_mode = cl_gui_textedit=>false.
    else.
      gd_mode = cl_gui_textedit=>true.
      endif.


  CALL METHOD go_textedit->set_readonly_mode
    EXPORTING
      readonly_mode          = gd_mode
    EXCEPTIONS
      error_cntl_call_method = 1
      invalid_parameter      = 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.
  ENDIF.


ENDFORM.                    " TOGGLE_MODE

Regards

Uwe

Read only

Former Member
0 Likes
4,742

Hi Sudipa,

Also there are few SAP's demo programs... search them using the search strings

TEXTEDITTEST* and TEXTEDITDEMO* ...

This one SAPTEXTEDIT_TEST_1 explains how to use all its functions

Cheers,

Jose.

Read only

Former Member
0 Likes
4,742

You can also find example in RSDEMO_DRAG_DROP_EDIT_TREE program.

Regards,

Mohaiyuddin

Read only

rajendra_sv
Advisor
Advisor
0 Likes
4,742

Hi Sudipa,

There are two methods to get the text from textedit control (CL_GUI_TEXTEDIT) GET_TEXT_AS_STREAM and GET_TEXT_AS_R3TABLE.

In demo program "SAPTEXTEDIT_TEST_2", if you enter some text and press the first button (which says "Save to R3table, when you keep the mouse over it) GET_TEXT_AS_STREAM method is called where the text contents are obtained from textedit control to table.

CALL METHOD editor->get_text_as_stream

EXPORTING

only_when_modified = cl_gui_textedit=>true

IMPORTING

text = p_table

In demo program "SAPTEXTEDIT_DEMO_1", if you enter some text and press the first button (which says "Save to R3table, when you keep the mouse over it) GET_TEXT_AS_R3Table method is called where the text contents are obtained from textedit control to table.

CALL METHOD g_editor->get_text_as_r3table

IMPORTING table = g_mytable.

For more information on these methods please checkout the methods in

http://help.sap.com/saphelp_nw70/helpdata/EN/f1/549e36cf0ecb7de10000009b38f889/frameset.htm

Best Regards

Rajendra

Read only

0 Likes
4,742

hi,

thanks a lot . The SAPTEXTEDIT development class ( or package as for the last naming convention of sap netweaver 7.0 ) has a lot of usefull examaples that can help you to learn the use of as TEXT EDITOR.

I have put ii in a subscreen of a tabstrip.

Best Regards luigi.

Edited by: luigi la motta on Jan 19, 2011 5:48 PM