[ABAP] TextEdit Control (cl_gui_textedit) in einem cl_gui_docking_container verwenden, variable Zeilenlänge

DATA: o_dock TYPE REF TO cl_gui_docking_container.
DATA: o_edit TYPE REF TO cl_gui_textedit.

PARAMETERS: p_text TYPE string.

START-OF-SELECTION.

* Container-Objekt erzeugen
  o_dock = NEW #( no_autodef_progid_dynnr = abap_true
                  side = cl_gui_docking_container=>dock_at_bottom
                  ratio = 50 ).

* Editorobjekt erzeugen, Zeilenumbruch am rechten Fensterrand
  o_edit = NEW #( wordwrap_mode = cl_gui_textedit=>wordwrap_at_windowborder
                  wordwrap_to_linebreak_mode = cl_gui_textedit=>true
                  parent = o_dock ).

* feste Zeichenbreite
  o_edit->set_font_fixed( mode = cl_gui_textedit=>true ).
  
* Text setzen
  o_edit->set_textstream( p_text ).

  WRITE space.

[ABAP] TextEdit Control (cl_gui_textedit) in einem cl_gui_docking_container verwenden

Variante 1 (feste Zeilenlänge)

* Textlänge 1024 Zeichen
CONSTANTS: c_textlength TYPE i VALUE 1024.

TYPES: ty_edit_text TYPE c LENGTH c_textlength.

DATA: o_edit TYPE REF TO cl_gui_textedit.
DATA: o_dock TYPE REF TO cl_gui_docking_container.

DATA: it_tab TYPE STANDARD TABLE OF ty_edit_text.

START-OF-SELECTION.

* Testtext
  WRITE: / 'Zeile 1'.
  WRITE: / 'Zeile 2'.
  WRITE: / 'Zeile 3'.

* Container-Objekt erzeugen
  o_dock = NEW #( no_autodef_progid_dynnr = abap_true
                  side = cl_gui_docking_container=>dock_at_bottom
                  ratio = 50 ).

* Editorobjekt erzeugen wordwrap an fester Position
  o_edit = NEW #( wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
                  wordwrap_position = c_textlength
                  parent = o_dock ).

* feste Zeichenbreite
  o_edit->set_font_fixed( mode = cl_gui_textedit=>true ).

AT LINE-SELECTION.
* bei Doppelklick auf Zeile
  IF o_edit IS BOUND.
* Text aus dem Editor holen
    o_edit->get_text_as_r3table( IMPORTING table = it_tab ).
* akt. gewählte Zeile anfügen
    APPEND sy-lisel TO it_tab.
* Text wieder im Editor anzeigen
    o_edit->set_text_as_r3table( table = it_tab ).
  ENDIF.

Variante 2 (variable Zeilenlänge)

DATA: o_edit TYPE REF TO cl_gui_textedit.
DATA: o_dock TYPE REF TO cl_gui_docking_container.

DATA: it_tab TYPE STANDARD TABLE OF char1024.

START-OF-SELECTION.

* Testtext
  WRITE: / 'Zeile 1'.
  WRITE: / 'Zeile 2'.
  WRITE: / 'Zeile 3'.

* Container-Objekt erzeugen
  o_dock = NEW #( no_autodef_progid_dynnr = abap_true
                  side = cl_gui_docking_container=>dock_at_bottom
                  ratio = 50 ).

* Editorobjekt erzeugen wordwrap an fester Position
  o_edit = NEW #( wordwrap_mode = cl_gui_textedit=>wordwrap_at_windowborder
                  wordwrap_to_linebreak_mode = cl_gui_textedit=>true
                  parent = o_dock ).

* feste Zeichenbreite
  o_edit->set_font_fixed( mode = cl_gui_textedit=>true ).

AT LINE-SELECTION.
* bei Doppelklick auf Zeile
  IF o_edit IS BOUND.
* Text aus dem Editor holen
    o_edit->get_text_as_stream( IMPORTING text = it_tab ).
* akt. gewählte Zeile anfügen
    APPEND sy-lisel TO it_tab.
* Text wieder im Editor anzeigen
    o_edit->set_text_as_stream( text = it_tab ).
  ENDIF.

[ABAP] TextEdit Control (cl_gui_textedit) Text löschen und neu setzen

DATA: o_edit TYPE REF TO cl_gui_textedit.
DATA: o_dock TYPE REF TO cl_gui_docking_container.

START-OF-SELECTION.

  WRITE: / 'Zeile 1'.
  WRITE: / 'Zeile 2'.
  WRITE: / 'Zeile 3'.
  
* Container-Objekt erzeugen
  o_dock = NEW #( no_autodef_progid_dynnr = abap_true
                  side = cl_gui_docking_container=>dock_at_bottom
                  ratio = 50 ).

* Editorobjekt erzeugen wordwrap an fester Position
  o_edit = NEW #( wordwrap_mode = cl_gui_textedit=>wordwrap_at_windowborder
                  wordwrap_to_linebreak_mode = cl_gui_textedit=>true
                  parent = o_dock ).

* feste Zeichenbreite
  o_edit->set_font_fixed( mode = cl_gui_textedit=>true ).

AT LINE-SELECTION.
* bei Doppelklick auf Zeile
  IF o_edit IS BOUND.
* Inhalt des TextEdit löschen
    o_edit->delete_text( ).
* Neuen text einfügen
    o_edit->set_textstream( |{ sy-lisel }| ).
  ENDIF.

[ABAP] TextEdit Control (cl_gui_textedit) für Quellcodedarstellung in eigenem Dynpro anzeigen

DATA: ok_code TYPE sy-ucomm.
DATA: o_cont TYPE REF TO cl_gui_custom_container.
DATA: o_edit TYPE REF TO cl_gui_textedit.

START-OF-SELECTION.
  CALL SCREEN 100. " Screen 100 hat ein Custom-Control 'CNT_MAIN'

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'ST_100'.
  SET TITLEBAR 'ST_100_TITLE'.

  IF o_cont IS NOT BOUND.
    o_cont = NEW cl_gui_custom_container( container_name = 'CNT_MAIN' ).
  ENDIF.

  IF o_edit IS NOT BOUND.
    o_edit = NEW cl_gui_textedit( wordwrap_mode = cl_gui_textedit=>wordwrap_at_windowborder
                                  wordwrap_to_linebreak_mode = cl_gui_textedit=>true
                                  parent = o_cont ).
  ENDIF.

  IF o_cont IS BOUND AND o_edit IS BOUND.
* Text readonly
    o_edit->set_readonly_mode( readonly_mode = cl_gui_textedit=>true ).
* für Quellcodedarstellung z.B. Kommentare hervorheben
    o_edit->set_comments_string( comments_string = '*' ).
    o_edit->set_highlight_comments_mode( highlight_comments_mode = cl_gui_textedit=>true ).
* Anzeige von Toolbar und Statusbar des Texteditors unterdrücken
    " o_edit->set_toolbar_mode( toolbar_mode = cl_gui_textedit=>false ).
    " o_edit->set_statusbar_mode( statusbar_mode = cl_gui_textedit=>false ).
  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE ok_code.
    WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
      IF o_edit IS BOUND.
        o_edit->free( ).
      ENDIF.

      IF o_cont IS BOUND.
        o_cont->free( ).
      ENDIF.

      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

Weiterführende Infos: Link