[ABAP] Verwendung von Buttons, Links, Comboboxen, Editfeldern in cl_dd_document (Dynamische Dokumente), Eventhandling

DATA: o_doc TYPE REF TO cl_dd_document.
DATA: o_form_area TYPE REF TO cl_dd_form_area.
DATA: o_input TYPE REF TO cl_dd_input_element.
DATA: o_combo TYPE REF TO cl_dd_select_element.
DATA: o_btn TYPE REF TO cl_dd_button_element.
DATA: o_link TYPE REF TO cl_dd_link_element.

DATA: it_options TYPE sdydo_option_tab.

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      on_button_clicked FOR EVENT clicked OF cl_dd_button_element
        IMPORTING
            sender.
    CLASS-METHODS:
      on_selected FOR EVENT selected OF cl_dd_select_element
        IMPORTING
            sender.
    CLASS-METHODS:
      on_enter FOR EVENT entered OF cl_dd_input_element
        IMPORTING
            sender.
    CLASS-METHODS:
      on_f1 FOR EVENT help_f1 OF cl_dd_input_element
        IMPORTING
            sender.
    CLASS-METHODS:
      on_link_clicked FOR EVENT clicked OF cl_dd_link_element
        IMPORTING
            sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.
  METHOD on_button_clicked.
    MESSAGE |{ sender->name }: { o_input->value } und { o_combo->value }| TYPE 'I'.
  ENDMETHOD.

  METHOD on_selected.
    MESSAGE sender->value TYPE 'I'.
  ENDMETHOD.

  METHOD on_enter.
    MESSAGE |{ sender->name }: { sender->value }| TYPE 'I'.
  ENDMETHOD.

  METHOD on_f1.
    MESSAGE |{ sender->name }: { sender->value }| TYPE 'I'.
  ENDMETHOD.

  METHOD on_link_clicked.
    MESSAGE |{ sender->name }| TYPE 'I'.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
* Dokument
  o_doc = NEW cl_dd_document( ).
  o_doc->add_text( text      = 'Eingabefelder'
                   sap_style = cl_dd_area=>heading ).
* Formular
  o_doc->add_form( IMPORTING formarea = o_form_area ).

* Editfeld
  o_form_area->add_input_element( EXPORTING
                                    value         = 'Wert'
                                    name          = 'EDINPUT'
                                    size          = '40'
                                    maxlength     = '40'
                                    tooltip       = 'Bitte einen Wert eingeben'
                                  IMPORTING
                                    input_element = o_input ).

  SET HANDLER lcl_events=>on_enter FOR o_input.
  SET HANDLER lcl_events=>on_f1 FOR o_input.

* Combobox
  it_options = VALUE #( ( value = 'P1' text = 'Punkt1' )
                        ( value = 'P2' text = 'Punkt2' )
                        ( value = 'P3' text = 'Punkt3' ) ).

  o_form_area->add_select_element( EXPORTING
                                     name           = 'CBTEST'
                                     value          = 'P2'
                                     options        = it_options
                                   IMPORTING
                                     select_element = o_combo ).

  SET HANDLER lcl_events=>on_selected FOR o_combo.

* Button
  o_form_area->add_button( EXPORTING
                             sap_icon = 'ICON_LED_GREEN'
                             label    = 'Klick'
                             name     = 'BTN_TEST'
                           IMPORTING
                             button   = o_btn ).

  SET HANDLER lcl_events=>on_button_clicked FOR o_btn.

* Link
  o_form_area->add_link( EXPORTING
                           text    = 'Linktext'
                           name    = 'LINK1'
                           tooltip = 'Klick me'
                         IMPORTING
                           link    = o_link ).

  SET HANDLER lcl_events=>on_link_clicked FOR o_link.

* Dokumentelemente zusammenführen
  o_doc->merge_document( ).

* Dokument anzeigen
  o_doc->display_document( parent = cl_gui_container=>default_screen ).

* erzwingen von cl_gui_container=>default_screen
  WRITE space.

[ABAP] Verwendung von Tabellen in cl_dd_document (Dynamische Dokumente)

TRY.
* DD-Dokumentobjekt anlegen und Hintergrundfarbe festlegen
    DATA(o_doc) = NEW cl_dd_document( background_color = cl_dd_area=>col_textarea ).

* max. 255 Zeichen
    o_doc->add_text( text          = 'Fluginformationen'
                     sap_style     = cl_dd_document=>heading ).

* Trennlinie
    o_doc->underline( ).

* Text
    o_doc->add_text( text          = 'Tabelle:'
                     sap_emphasis  = cl_dd_document=>strong
                     sap_fontstyle = cl_dd_area=>serif ).

* Leerzeile
    o_doc->new_line( ).

    DATA: o_table TYPE REF TO cl_dd_table_element.
    DATA: o_table_area TYPE REF TO cl_dd_table_area.

* Tabelle mit 2 Spalten anlegen
    o_doc->add_table( EXPORTING
                        no_of_columns               = 2
                        cell_background_transparent = abap_false
                      IMPORTING
                        table                       = o_table
                        tablearea                   = o_table_area ).

* Spalte 1, Stil hellblau
    o_table->set_column_style( col_no    = 1
                               sap_style = cl_dd_area=>key ).

* Tabelle hat 2 Spalten, daher 2 Texte hinzufügen
    o_table_area->add_text( text = 'Fluggesellschaft' sap_emphasis = cl_dd_area=>strong ).
    o_table_area->add_text( text = 'LH' ).

* Zeile voll - weiter zur nächsten Zeile
    o_table_area->new_row( ).

    o_table_area->add_text( text = 'Flugnummer' sap_emphasis = cl_dd_area=>strong ).
    o_table_area->add_text( text = '400' ).

* Zweite Zeile voll
    o_table_area->new_row( ).

* Zeile 3
    o_table_area->add_text( text = 'Von' sap_emphasis = cl_dd_area=>strong ).
    o_table_area->add_text( text = 'Frankfurt' ).

* Dritte Zeile voll
    o_table_area->new_row( ).

* Zeile 4
    o_table_area->add_text( text = 'Nach' sap_emphasis = cl_dd_area=>strong ).
    o_table_area->add_text( text = 'New York' ).

* Vierte Zeile voll
    o_table_area->new_row( ).

* Dokumentelemente zusammenführen
    o_doc->merge_document( ).
* Dokument im Standardcontainer anzeigen
    o_doc->display_document( parent = cl_gui_container=>default_screen ).

* erzwingen von cl_gui_container=>default_screen
    WRITE space.

  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

[ABAP] Textausgabe mit cl_dd_document (Dynamische Dokumente) in einem cl_gui_docking_container

DATA: it_spfli TYPE STANDARD TABLE OF spfli.

DATA: o_cnt TYPE REF TO cl_gui_docking_container.
DATA: o_doc TYPE REF TO cl_dd_document.

PARAMETERS: p_carr TYPE spfli-carrid DEFAULT '%'.

INITIALIZATION.
* Containerobjekt für die Einbettung des cl_dd_document
  o_cnt = NEW #( no_autodef_progid_dynnr = abap_true
                 side  = cl_gui_docking_container=>dock_at_bottom
                 ratio = 85 ).

* cl_dd_document für die formatierte Darstellung des Ausgabetextes
  o_doc = NEW #( background_color = cl_dd_area=>col_textarea ).
* Dokument im Container darstellen
  o_doc->display_document( parent = o_cnt ).

AT SELECTION-SCREEN OUTPUT.

  IF o_cnt IS BOUND.
* SELECT mit LIKE, für % als Wildcard
    SELECT * FROM spfli
      INTO TABLE @it_spfli
      WHERE carrid LIKE @p_carr.

* Dokument initialisieren, alten Inhalt löschen, Hintergrundfarbe weiß
    o_doc->initialize_document( background_color = cl_dd_area=>col_textarea ).
* Text vom Stil Überschrift
    o_doc->add_text( text      = 'Flugverbindungen'
                     sap_style = cl_dd_document=>heading ).

* Trennlinie
    o_doc->underline( ).

    LOOP AT it_spfli ASSIGNING FIELD-SYMBOL(<fs_line>).
* Zeilen im Standardformat
      o_doc->add_text( text      = |{ <fs_line>-carrid } { <fs_line>-connid } { <fs_line>-airpfrom } { <fs_line>-cityfrom } { <fs_line>-airpto } { <fs_line>-cityto }|
                       sap_style = cl_dd_document=>standard ).

      o_doc->new_line( ).
    ENDLOOP.

* Dokument zusammenbauen
    o_doc->merge_document( ).
* Dokument anzeigen, bisherige Controls, Ereignisbehandler und Container beibehalten
    o_doc->display_document( reuse_control = abap_true
                             reuse_registration = abap_true
                             parent = o_cnt ).
  ENDIF.