[ABAP] Mehrere interne Tabellen in eigenem Fullscreen-Fenster (cl_gui_dialogbox_container) anzeigen

CLASS lcl_show_window DEFINITION FINAL.

  PUBLIC SECTION.

    CLASS-METHODS show
      IMPORTING
        !i_title TYPE string
      CHANGING
        !c_itab  TYPE STANDARD TABLE .

    CLASS-METHODS show2
      IMPORTING
        !i_title1 TYPE string
        !i_title2 TYPE string
      CHANGING
        !c_itab1  TYPE STANDARD TABLE
        !c_itab2  TYPE STANDARD TABLE .

  PROTECTED SECTION.

  PRIVATE SECTION.

    CLASS-METHODS on_close
      FOR EVENT close OF cl_gui_dialogbox_container
      IMPORTING
        !sender .
ENDCLASS.

CLASS lcl_show_window IMPLEMENTATION.

  METHOD on_close.
    IF sender IS NOT INITIAL.
      sender->free( ).
    ENDIF.
  ENDMETHOD.

  METHOD show.

    TRY.
* Window-Style hier ohne cl_gui_control=>ws_thickframe vordefinieren, da sonst das Fenster nicht richtig maximized werden kann
        DATA(i_style) = cl_gui_control=>ws_minimizebox + cl_gui_control=>ws_maximizebox + cl_gui_control=>ws_sysmenu.

* Bildschirmauflösung ermitteln
        DATA(lv_metric_factors) = cl_gui_props_consumer=>create_consumer( )->get_metric_factors( ).

* https://download.consolut.com/direct/SAP_PrintDoku/de/BCCIDOCK/BCCIDOCK.PDF
* Top, Left, Width, Height in Pixel
        DATA(o_cnt) = NEW cl_gui_dialogbox_container( no_autodef_progid_dynnr = abap_true
                                                      caption                 = |{ i_title }|
                                                      top                     = 1
                                                      left                    = 1
                                                      width                   = lv_metric_factors-screen-x
                                                      height                  = lv_metric_factors-screen-y
                                                      style                   = i_style
                                                      metric                  = cl_gui_dialogbox_container=>metric_pixel ).

* Dialogbox-Container fullscreen (maximized) setzen
*        o_cnt->set_alignment( cl_gui_control=>align_at_left + cl_gui_control=>align_at_right + cl_gui_control=>align_at_top + cl_gui_control=>align_at_bottom ).

* OnClose-Handler für cl_gui_dialogbox_container
        SET HANDLER on_close FOR o_cnt.

* SALV-Grid
        DATA: o_salv TYPE REF TO cl_salv_table.

        cl_salv_table=>factory( EXPORTING r_container  = o_cnt
                                IMPORTING r_salv_table = o_salv
                                CHANGING  t_table      = c_itab ).

        o_salv->get_functions( )->set_all( abap_true ).
        o_salv->get_columns( )->set_optimize( abap_true ).
        o_salv->get_display_settings( )->set_list_header( |{ i_title }| ).
        o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
        o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).

        o_salv->display( ).

      CATCH cx_root.
    ENDTRY.
  ENDMETHOD.

  METHOD show2.

    TRY.
* Window-Style hier ohne cl_gui_control=>ws_thickframe vordefinieren, da sonst das Fenster nicht richtig maximized werden kann
        DATA(i_style) = cl_gui_control=>ws_minimizebox + cl_gui_control=>ws_maximizebox + cl_gui_control=>ws_sysmenu.

* Bildschirmauflösung ermitteln
        DATA(lv_metric_factors) = cl_gui_props_consumer=>create_consumer( )->get_metric_factors( ).

* https://download.consolut.com/direct/SAP_PrintDoku/de/BCCIDOCK/BCCIDOCK.PDF
* Top, Left, Width, Height in Pixel
        DATA(o_cnt) = NEW cl_gui_dialogbox_container( no_autodef_progid_dynnr = abap_true
                                                      caption                 = |{ i_title1 }, { i_title2 }|
                                                      top                     = 1
                                                      left                    = 1
                                                      width                   = lv_metric_factors-screen-x
                                                      height                  = lv_metric_factors-screen-y
                                                      style                   = i_style
                                                      metric                  = cl_gui_dialogbox_container=>metric_pixel ).

* Dialogbox-Container fullscreen (maximized) setzen
*        o_cnt->set_alignment( cl_gui_control=>align_at_left + cl_gui_control=>align_at_right + cl_gui_control=>align_at_top + cl_gui_control=>align_at_bottom ).

* OnClose-Handler für cl_gui_dialogbox_container
        SET HANDLER on_close FOR o_cnt.

* Referenzen auf GUI-Objekte
* Splitter
        DATA: o_splitter TYPE REF TO cl_gui_splitter_container.

* horizontaler Splitter in cl_gui_dialogbox_container einbetten
        o_splitter = NEW #( parent                  = o_cnt
                            no_autodef_progid_dynnr = abap_true
                            rows                    = 2
                            columns                 = 1 ).

* Splittercontainer auf 50%
        o_splitter->set_row_height( id = 1 height = 50 ).

* Splittercontainer oben/unten holen
        DATA(o_cnt_s1) = o_splitter->get_container( row = 1 column = 1 ).
        DATA(o_cnt_s2) = o_splitter->get_container( row = 2 column = 1 ).

* SALV-Grid 1 in Splittercontainer oben
        DATA: o_salv1 TYPE REF TO cl_salv_table.

        cl_salv_table=>factory( EXPORTING r_container  = o_cnt_s1
                                IMPORTING r_salv_table = o_salv1
                                CHANGING  t_table      = c_itab1 ).

        o_salv1->get_functions( )->set_all( abap_true ).
        o_salv1->get_columns( )->set_optimize( abap_true ).
        o_salv1->get_display_settings( )->set_list_header( |{ i_title1 }| ).
        o_salv1->get_display_settings( )->set_striped_pattern( abap_true ).
        o_salv1->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).

        o_salv1->display( ).

* SALV-Grid 2 in Splittercontainer unten
        DATA: o_salv2 TYPE REF TO cl_salv_table.

        cl_salv_table=>factory( EXPORTING r_container  = o_cnt_s2
                                IMPORTING r_salv_table = o_salv2
                                CHANGING  t_table      = c_itab2 ).

        o_salv2->get_functions( )->set_all( abap_true ).
        o_salv2->get_columns( )->set_optimize( abap_true ).
        o_salv2->get_display_settings( )->set_list_header( |{ i_title2 }| ).
        o_salv2->get_display_settings( )->set_striped_pattern( abap_true ).

        o_salv2->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).

        o_salv2->display( ).
      CATCH cx_root.
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.

* Beispieldaten
  SELECT
    FROM mara
    FIELDS *
    INTO TABLE @DATA(it_mara)
    UP TO 100 ROWS.

  IF sy-subrc = 0.
    SELECT
      FROM marc
      FIELDS *
      INTO TABLE @DATA(it_marc)
      UP TO 100 ROWS.

    IF sy-subrc = 0.
* interne Tabelle im Window anzeigen
      lcl_show_window=>show( EXPORTING i_title = |MARA|
                             CHANGING  c_itab  = it_mara ).

* zwei interne Tabellen in einem Window mit Splitter anzeigen
      lcl_show_window=>show2( EXPORTING i_title1 = |MARA|
                                        i_title2 = |MARC|
                              CHANGING  c_itab1  = it_mara
                                        c_itab2  = it_marc ).
    ENDIF.
  ENDIF.

* cl_gui_container=>default_screen erzwingen
  WRITE: space.

[ABAP] GUI-Simple-Tree und SALV-Grid in Split-Container ohne Dynpro anzeigen, Eventhandling

TYPES: ty_it_events TYPE STANDARD TABLE OF cntl_simple_event WITH DEFAULT KEY.
TYPES: ty_it_nodes TYPE STANDARD TABLE OF mtreesnode WITH DEFAULT KEY.

DATA: o_salv TYPE REF TO cl_salv_table.
DATA: it_tree_spfli TYPE STANDARD TABLE OF spfli.
DATA: it_salv_spfli TYPE STANDARD TABLE OF spfli.
DATA: it_nodes TYPE ty_it_nodes.

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
* GUI Simple Tree
    CLASS-METHODS: on_keypress FOR EVENT node_keypress OF cl_gui_simple_tree
      IMPORTING
          node_key
          key
          sender.
    CLASS-METHODS: on_selection_changed FOR EVENT selection_changed OF cl_gui_simple_tree
      IMPORTING
          node_key
          sender.
    CLASS-METHODS: on_expand_no_children FOR EVENT expand_no_children OF cl_gui_simple_tree
      IMPORTING
          node_key
          sender.
* ALV-Events für das SALV-Grid
    CLASS-METHODS: on_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
      IMPORTING
          e_object
          sender.
    CLASS-METHODS: on_user_command FOR EVENT user_command OF cl_gui_alv_grid
      IMPORTING
          e_ucomm
          sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.
* Tastendruck
  METHOD on_keypress.
    MESSAGE |Node: { node_key } Taste: { key }| TYPE 'S'.
  ENDMETHOD.
* Klick auf ein aktives Baumelement
  METHOD on_selection_changed.
* Element in der Nodes-Tabelle lesen
    ASSIGN it_nodes[ node_key = node_key ] TO FIELD-SYMBOL(<fs_node>).

* iTab für SALV-Table neu aufbauen
    CLEAR: it_salv_spfli.

    LOOP AT it_tree_spfli ASSIGNING FIELD-SYMBOL(<fs_line>) WHERE carrid = <fs_node>-text.
      APPEND <fs_line> TO it_salv_spfli.
    ENDLOOP.

* SALV-Table neu anzeigen
    o_salv->refresh( ).
  ENDMETHOD.
* bei Expandierung eines Baumelements ohne Unterelemente
  METHOD on_expand_no_children.
    MESSAGE |Node: { node_key }| TYPE 'S'.
  ENDMETHOD.

* Toolbar-Buttons hinzufügen:
* butn_type   Bezeichung
* 0           Button (normal)
* 1           Menü + Defaultbutton
* 2           Menü
* 3           Separator
* 4           Radiobutton
* 5           Auswahlknopf (Checkbox)
* 6           Menüeintrag
  METHOD on_toolbar.
* Separator hinzufügen
    APPEND VALUE #( butn_type = 3 ) TO e_object->mt_toolbar.
* Edit-Button hinzufügen
    APPEND VALUE #( butn_type = 5 text = 'Daten anzeigen' icon = icon_icon_list function = 'SHOW_DATA' quickinfo = 'Daten anzeigen' disabled = ' ' ) TO e_object->mt_toolbar.
  ENDMETHOD.
* Benutzerkommando (Button-Klick)
  METHOD on_user_command.
    CASE e_ucomm.
      WHEN 'SHOW_DATA'.
        DATA: lv_row TYPE i. " Zeile auf Grid
        DATA: lv_value TYPE char255. " Wert
        DATA: lv_col TYPE i. " Spalte auf Grid
        DATA: lv_row_id TYPE lvc_s_row. " Zeilen-Id
        DATA: lv_col_id TYPE lvc_s_col. " Spalten-Id
        DATA: lv_row_no TYPE lvc_s_roid. " Numerische Zeilen ID

        sender->get_current_cell( IMPORTING
                                    e_row = lv_row
                                    e_value = lv_value
                                    e_col = lv_col
                                    es_row_id = lv_row_id
                                    es_col_id = lv_col_id
                                    es_row_no = lv_row_no ).

        MESSAGE |Zeile: { lv_row }, Spalte: { lv_col }, Wert: { lv_value }, Spaltenname: { lv_col_id-fieldname }| TYPE 'S'.
    ENDCASE.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

  SELECT * INTO TABLE it_tree_spfli FROM spfli.

* Splitter auf screen0 erzeugen
  DATA(o_split) = NEW cl_gui_splitter_container( parent = cl_gui_container=>screen0
                                                 no_autodef_progid_dynnr = abap_true
                                                 rows = 1
                                                 columns = 2 ).

* Breite in % (linke Spalte für den Tree)
  o_split->set_column_width( id = 1 width = 15 ).

* linken und rechten Splitcontainer holen
  DATA(o_spl_left) = o_split->get_container( row = 1 column = 1 ).
  DATA(o_spl_right) = o_split->get_container( row = 1 column = 2 ).

  TRY.
* Tree-Objekt erzeugen
      DATA(o_tree) = NEW cl_gui_simple_tree( parent = o_spl_left
                                             node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single ).


* Eventtypten müssen gesondert registriert werden
      DATA(it_events) = VALUE ty_it_events( ( eventid = cl_gui_simple_tree=>eventid_node_keypress
                                              appl_event = abap_true )
                                            ( eventid = cl_gui_simple_tree=>eventid_selection_changed
                                              appl_event = abap_true )
                                            ( eventid = cl_gui_simple_tree=>eventid_expand_no_children
                                              appl_event = abap_true ) ).

      o_tree->set_registered_events( events = it_events ).

      o_tree->add_key_stroke( cl_gui_simple_tree=>key_enter ).

* Events registrieren
      SET HANDLER lcl_events=>on_keypress FOR o_tree.
      SET HANDLER lcl_events=>on_selection_changed FOR o_tree.
      SET HANDLER lcl_events=>on_expand_no_children FOR o_tree.

* Root-Node einfügen
      it_nodes = VALUE #( ( node_key  = 'ROOT'           " Node-Bezeichner
                            relatship = cl_gui_simple_tree=>relat_last_child
                            disabled  = abap_true
                            isfolder  = abap_true        " Typ Ordner für Root-Element
                            n_image   = icon_folder      " Icon Ordner
                            exp_image = icon_open_folder " Icon geöffneter Ordner
                            style     = cl_gui_simple_tree=>style_default
                            text      = 'Airlines' ) ).

* Childs an Root-Node anhängen
      LOOP AT it_tree_spfli ASSIGNING FIELD-SYMBOL(<fs_line>).
* bei Änderung der carrid neue carrid als Child anhängen
        AT NEW carrid.
          APPEND VALUE #( node_key  = |NODE{ sy-tabix }| " eindeutiger Node-Bezeichner
                          relatship = cl_gui_simple_tree=>relat_last_child
                          relatkey  = 'ROOT'             " an ROOT-Element anhängen
                          style     = cl_gui_simple_tree=>style_intensified
                          text      = |{ <fs_line>-carrid }| ) TO it_nodes.
        ENDAT.
      ENDLOOP.

* Nodes im Baum einfügen
      o_tree->add_nodes( table_structure_name = 'MTREESNODE' " Typ muss gleich mit Zeilentyp von ty_it_nodes sein
                         node_table           = it_nodes ).

* Root-Nodes des Trees expandieren
      o_tree->expand_root_nodes( ).

* leeres SALV-Grid erzeugen
      cl_salv_table=>factory( EXPORTING
                                r_container    = o_spl_right
                              IMPORTING
                                r_salv_table   = o_salv
                              CHANGING
                                t_table        = it_salv_spfli ).

      o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
      o_salv->get_columns( )->set_optimize( abap_true ).
      o_salv->get_functions( )->set_all( ).
      o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).
      o_salv->display( ).

* Trick: Aus dem Split-Container rechts das Grid-Objekt holen und nach cl_gui_alv_grid casten
      READ TABLE o_spl_right->children INDEX 1 ASSIGNING FIELD-SYMBOL(<child>).
      IF <child> IS ASSIGNED.
        DATA(o_alv_grid) = CAST cl_gui_alv_grid( <child> ).

* Eventhandler registrieren
        SET HANDLER lcl_events=>on_toolbar FOR o_alv_grid.
        SET HANDLER lcl_events=>on_user_command FOR o_alv_grid.
      ENDIF.

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

* leere Toolbar ausblenden
  cl_abap_list_layout=>suppress_toolbar( ).

* cl_gui_container=>screen0 erzwingen
  WRITE space.

[ABAP] SALV-Table – Aggregationsfunktionen

SELECT * FROM sflight INTO TABLE @DATA(it_sflight).

TRY.
* SALV-Table
    DATA: o_salv TYPE REF TO cl_salv_table.

    cl_salv_table=>factory( IMPORTING
                              r_salv_table   = o_salv
                            CHANGING
                              t_table        = it_sflight ).

* Grundeinstellungen
    o_salv->get_functions( )->set_all( abap_true ).
    o_salv->get_columns( )->set_optimize( abap_true ).
    o_salv->get_display_settings( )->set_list_header( 'Aggregationen' ).
    o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
    o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).

* Spaltenüberschriften: technischer Name und Beschreibungstexte, Short Text und Medium Text leer lassen für Autosize
    LOOP AT o_salv->get_columns( )->get( ) ASSIGNING FIELD-SYMBOL(<c>).
      DATA(o_col) = <c>-r_column.
      o_col->set_short_text( || ).
      o_col->set_medium_text( || ).
      o_col->set_long_text( |{ o_col->get_columnname( ) } [{ o_col->get_long_text( ) }]| ).
    ENDLOOP.

* vorher sortieren und subtotal setzen
    o_salv->get_sorts( )->add_sort( columnname = 'CARRID' subtotal = abap_true sequence = if_salv_c_sort=>sort_up ).
    o_salv->get_sorts( )->add_sort( columnname = 'CONNID' subtotal = abap_true sequence = if_salv_c_sort=>sort_up ).
* Aggregation
    o_salv->get_aggregations( )->add_aggregation( columnname = 'SEATSMAX' aggregation = if_salv_c_aggregation=>total ).
* Summenzeilen über den Einträgen anzeigen
    o_salv->get_aggregations( )->set_aggregation_before_items( ).

* Anzeige
    o_salv->display( ).
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.