Skip to Content
avatar image
Former Member

save and read data on TEXTEDIT

Dear all.

i have not used this class for textedit.

i've looked this article via this forum. but i am not clear on it.

what type do i use for this field be applied for textedit? string? or rawstring?

please correct my source to save data from textedit into ztable and read data from field of ztable.

save and read,,, please help me.

1. what type do i have to use for textedit? maybe string?

2. how to save data to ztable from textedit.

3. how to read data from ztable and then put on textedit?.

&----


*& Report Z_TEXTEDIT01

*&

&----


*&

*&

&----


report z_textedit01.

data : g_editor type ref to cl_gui_textedit,

g_editor_container type ref to cl_gui_custom_container,

g_ok_code like sy-ucomm,

ok_code like sy-ucomm,

g_repid like sy-repid.

types : begin of mytable_line,

line(256) type c,

end of mytable_line.

data : g_mytable type table of mytable_line.

start-of-selection.

call screen 100.

&----


*& Module START OUTPUT

&----


  • text

----


module start output.

if g_editor is initial.

set pf-status 'MAIN100'.

g_repid = sy-repid.

create object g_editor_container

exporting

container_name = 'TEXTEDITOR1'.

create object g_editor

exporting

parent = g_editor_container

wordwrap_mode = cl_gui_textedit=>wordwrap_at_windowborder.

endif.

endmodule. " START OUTPUT

&----


*& Module EXIT INPUT

&----


  • text

----


module exit input.

*Destroy Control.

if not g_editor is initial.

call method g_editor->free.

*free abap object also

free g_editor.

endif.

*destroy container

if not g_editor_container is initial.

call method g_editor_container->free.

*free abap object also

free g_editor_container.

endif.

*finally flush

call method cl_gui_cfw=>flush.

leave program.

endmodule. " EXIT INPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


module user_command_0100 input.

g_ok_code = ok_code.

clear ok_code.

case g_ok_code.

when 'CHAN'.

perform change_status.

when 'PROT'.

perform prot_status.

when 'INDT'.

perform indt_status.

when 'FIND'.

perform find_status.

when 'HIGH'.

perform high_status.

when 'DELE'.

perform dele_status.

when 'TOOL'.

perform tool_status.

endcase.

endmodule. " USER_COMMAND_0100 INPUT

&----


*& Form change_status

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form change_status .

data : readonly type i.

readonly = g_editor->m_readonly_mode.

if readonly <> g_editor->false.

readonly = g_editor->false.

else.

readonly = g_editor->true.

endif.

call method g_editor->set_readonly_mode

exporting

readonly_mode = readonly.

endform. " read_status

&----


*& Form prot_status

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form prot_status .

data g_mytable type table of mytable_line.

data n type i value 2.

call method g_editor->get_selected_text_as_r3table

importing

table = g_mytable.

describe table g_mytable lines n.

call method g_editor->protect_lines

exporting

from_line = 1

to_line = n

protect_mode = 1

enable_editing_protected_text = 0.

endform. " prot_status

&----


*& Form indt_status

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form indt_status .

data g_mytable type table of mytable_line.

data n type i.

call method g_editor->get_selected_text_as_r3table

importing

table = g_mytable.

describe table g_mytable lines n.

call method g_editor->indent_lines

exporting

from_line = 1

to_line = n

enable_editing_protected_text = 1.

endform. " indt_status

&----


*& Form find_status

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form find_status.

  • data g_mytable type table of mytable_line.

*

  • call method g_editor->find_and_select_text

  • exporting

  • search_string = search_string

  • case_sensitive_mode = 0

  • whole_word_mode = 1

  • changing

  • string_found = found.

endform. " find_status

&----


*& Form high_status

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form high_status .

data g_mytable type table of mytable_line.

data n type i.

call method g_editor->get_selected_text_as_r3table

importing

table = g_mytable.

describe table g_mytable lines n.

call method g_editor->highlight_lines

exporting

from_line = 0

to_line = n

highlight_mode = 1.

endform. " high_status

&----


*& Form dele_status

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form dele_status .

call method g_editor->delete_text.

endform. " dele_status

&----


*& Form tool_status

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form tool_status .

data : toolbar type i,

statusbar type i.

toolbar = g_editor->m_toolbar_mode.

statusbar = g_editor->m_statusbar_mode.

if ( ( toolbar <> g_editor->false ) or ( statusbar <> g_editor->false ) ).

toolbar = statusbar = g_editor->false.

else.

toolbar = statusbar = g_editor->true.

endif.

call method g_editor->set_toolbar_mode

exporting

toolbar_mode = toolbar.

call method g_editor->set_statusbar_mode

exporting

statusbar_mode = statusbar.

endform. " tool_status

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Aug 19, 2007 at 09:11 PM

    Hello Ogawa

    The following sample report <b>ZUS_SDN_PS_LONGTEXT_DISPLAY</b> shows you how to read and save <u>longtexts </u>of PSP elements. The same way you could save longtexts for objects in your custom tables.

    *&---------------------------------------------------------------------*
    *& Report  ZUS_SDN_PS_LONGTEXT_DISPLAY
    *&
    *&---------------------------------------------------------------------*
    *& Display and change of PSP element longtext
    *&
    *&---------------------------------------------------------------------*
    
    REPORT  zus_sdn_ps_longtext_display.
    
    
    TYPE-POOLS: cntl.  " Types for Controls
    
    DATA:
      gd_okcode      TYPE ui_func,
      go_docking     TYPE REF TO cl_gui_docking_container,
      go_textedit    TYPE REF TO cl_gui_textedit,
    *
      gd_name        TYPE thead-tdname,
      gs_header      TYPE thead,
      gd_langu       TYPE thead-tdspras,
      gt_itf_text    TYPE STANDARD TABLE OF tline,
      gt_stream      TYPE TABLE OF text1024.  " string not possible
    
    
    
    *---------------------------------------------------------------------*
    *       CLASS lcl_eventhandler DEFINITION
    *---------------------------------------------------------------------*
    *
    *---------------------------------------------------------------------*
    CLASS lcl_eventhandler DEFINITION.
      PUBLIC SECTION.
    
        CLASS-METHODS:
          handle_context_menu
            FOR EVENT context_menu OF cl_gui_textedit
              IMPORTING
                menu
                sender,
    
          handle_ctxmenu_selected
            FOR EVENT context_menu_selected OF cl_gui_textedit
              IMPORTING
                fcode
                sender.
    
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    
    
    
    *---------------------------------------------------------------------*
    *       CLASS lcl_eventhandler IMPLEMENTATION
    *---------------------------------------------------------------------*
    *
    *---------------------------------------------------------------------*
    CLASS lcl_eventhandler IMPLEMENTATION.
    
      METHOD handle_context_menu.
    
        CALL METHOD menu->add_function
          EXPORTING
            fcode       = 'MY_FUNC'
            text        = 'My Function'
    *        ICON        =
    *        FTYPE       =
    *        DISABLED    =
    *        HIDDEN      =
    *        CHECKED     =
    *        ACCELERATOR =
            .
    
      ENDMETHOD.                    "handle_context_menu
    
    
      METHOD handle_ctxmenu_selected.
    
        CASE fcode.
          WHEN 'MY_FUNC'.
            MESSAGE 'My function selected from ctxmenu' TYPE 'I'.
    
          WHEN OTHERS.
        ENDCASE.
    
      ENDMETHOD.                    "handle_ctxmenu_selected
    
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    
    
    
    
    PARAMETERS:
      p_pspnr    TYPE prps-pspnr.  "  default 'E-9990-4'.
    
    
    
    
    
    START-OF-SELECTION.
    
    * Get the text object (transaction SO10)
      gs_header-tdid = 'LTXT'.  " long text
      gs_header-tdspras = syst-langu.
      CONCATENATE syst-langu p_pspnr
          INTO gs_header-tdname.
      gs_header-tdobject = 'PMS'.
    
    
      CALL FUNCTION 'READ_TEXT'
        EXPORTING
    *     CLIENT                        = SY-MANDT
          id                            = gs_header-tdid
          language                      = gs_header-tdspras
          name                          = gs_header-tdname
          object                        = gs_header-tdobject
    *     ARCHIVE_HANDLE                = 0
    *     LOCAL_CAT                     = ' '
    *   IMPORTING
    *     HEADER                        =
        TABLES
          lines                         = gt_itf_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.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
      CALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'
    *   EXPORTING
    *     LANGUAGE          = SY-LANGU
        TABLES
          itf_text          = gt_itf_text
          text_stream       = gt_stream.
    "   NOTE: if gt_stream a string table the report would dump here
    
    
      CALL SCREEN '0100'.
    
    
    END-OF-SELECTION.
    
    
    
    *&---------------------------------------------------------------------*
    *&      Form  SET_REGISTERED_EVENTS
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM
    set_registered_events .
    * define local data
      DATA:
        lt_events      TYPE cntl_simple_events,
        ls_event       TYPE cntl_simple_event.
    
    
      TYPES: BEGIN OF cntl_simple_event,
           eventid TYPE i,
           appl_event TYPE c,
         END OF cntl_simple_event.
    
    
      ls_event-eventid = cl_gui_textedit=>event_context_menu.
      APPEND ls_event TO lt_events.
      ls_event-eventid = cl_gui_textedit=>event_context_menu_selected.
      APPEND ls_event TO lt_events.
    
      CALL METHOD go_textedit->set_registered_events
        EXPORTING
          events                    = lt_events
        EXCEPTIONS
          cntl_error                = 1
          cntl_system_error         = 2
          illegal_event_combination = 3
          OTHERS                    = 4.
      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_REGISTERED_EVENTS
    
    
    
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'MAIN_0100'.
    *  SET TITLEBAR 'xxx'.
    
    
      CLEAR: gd_okcode.
    
      IF ( go_textedit IS NOT BOUND ).
        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          =
                c_textedit_control=>wordwrap_at_windowborder
    *        WORDWRAP_POSITION      =
            wordwrap_to_linebreak_mode =
               c_textedit_control=>true
    *        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.
    
        CALL METHOD go_textedit->set_text_as_stream
          EXPORTING
            text            = gt_stream
          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.
    
        CALL METHOD go_textedit->set_enable
          EXPORTING
            enable            = cl_gui_cfw=>true
          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.
        ENDIF.
    
    
        PERFORM set_registered_events.
        SET HANDLER:
          lcl_eventhandler=>handle_context_menu     FOR go_textedit,
          lcl_eventhandler=>handle_ctxmenu_selected FOR go_textedit.
      ENDIF.
    
    ENDMODULE.                 " STATUS_0100  OUTPUT
    
    
    
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_0100 INPUT.
    
      CASE gd_okcode.
        WHEN 'BACK'  OR
             'EXIT'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
    
        WHEN 'SAVE'.
          PERFORM save_longtext.
    
        WHEN OTHERS.
      ENDCASE.
    
      CLEAR: gd_okcode.
    
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *&      Form  SAVE_LONGTEXT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM save_longtext .
    * define local data
      DATA:
       lx_modified    TYPE i.
    
    
      REFRESH: gt_itf_text,
               gt_stream.
    
      CALL METHOD go_textedit->get_text_as_stream
        EXPORTING
          only_when_modified     = cl_gui_textedit=>true
        IMPORTING
          text                   = gt_stream
          is_modified            = lx_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.
    
      CHECK ( lx_modified = cl_gui_textedit=>true ).
    
    
      CALL FUNCTION 'CONVERT_STREAM_TO_ITF_TEXT'
    *   EXPORTING
    *     LANGUAGE          = SY-LANGU
        TABLES
          text_stream       = gt_stream
          itf_text          = gt_itf_text.
    
    
    
      CALL FUNCTION 'SAVE_TEXT'
        EXPORTING
    *     CLIENT                = SY-MANDT
          header                = gs_header
    *     INSERT                = ' '
          SAVEMODE_DIRECT       = 'X'
    *     OWNER_SPECIFIED       = ' '
    *     LOCAL_CAT             = ' '
    *   IMPORTING
    *     FUNCTION              =
    *     NEWHEADER             =
        TABLES
          lines                 = gt_itf_text
        EXCEPTIONS
          id                    = 1
          language              = 2
          name                  = 3
          object                = 4
          OTHERS                = 5.
      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.                    " SAVE_LONGTEXT

    If you want to store long texts in your tables using a STRING field then you have to use methods <b>SET_TEXTSTREAM</b> and <b>GET_TEXTSTREAM</b> of the textedit control.

    Regards

    Uwe

    Add comment
    10|10000 characters needed characters exceeded