[ABAP] SALV-Tree: Beispiel für Verwendung von cl_salv_tree

* Demoprogramme
*
* SALV_DEMO_TREE_DATA_UPDATE
* SALV_DEMO_TREE_EVENTS
* SALV_DEMO_TREE_FUNCTIONS
* SALV_DEMO_TREE_METADATA
* SALV_DEMO_TREE_SELECTIONS
* SALV_DEMO_TREE_SETTINGS
* SALV_DEMO_TREE_SIMPLE

TYPES: ty_it_spfli TYPE STANDARD TABLE OF spfli WITH DEFAULT KEY.

DATA: o_tree TYPE REF TO cl_salv_tree.
DATA: it_spfli TYPE ty_it_spfli.
DATA: it_spfli_empty TYPE ty_it_spfli.

* Eventhandlerklasse
CLASS lcl_events DEFINITION.
  PUBLIC SECTION.

    CLASS-METHODS:
      on_button_click FOR EVENT link_click OF cl_salv_events_tree
        IMPORTING
            columnname
            node_key
            sender.
    CLASS-METHODS:
      on_user_command FOR EVENT added_function OF cl_salv_events
        IMPORTING
            e_salv_function
            sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.

  METHOD on_button_click.

    TRY.
        IF o_tree IS BOUND.
* Unternode (Child) zur akt. geklickten Node holen
          DATA(o_child_node) = o_tree->get_nodes( )->get_node( node_key )->get_first_child( ).

* alle Unternodes durchlaufen und Checkbox der Spalte Carrier setzen
          WHILE o_child_node IS BOUND.

            DATA(o_item) = o_child_node->get_item( 'CARRID' ).

            IF o_item->is_checked( ) = abap_true.
              o_item->set_checked( abap_false ).
            ELSE.
              o_item->set_checked( abap_true ).
            ENDIF.

            o_child_node = o_child_node->get_next_sibling( ).
          ENDWHILE.

        ENDIF.
      CATCH cx_salv_msg.
    ENDTRY.

  ENDMETHOD.

  METHOD on_user_command.
    MESSAGE e_salv_function TYPE 'I'.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
* Daten holen
  SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE it_spfli.

  SORT: it_spfli BY carrid.

  TRY.
* Tree-Objekt mit leerer Tabelle (Dummy) erzeugen
      cl_salv_tree=>factory( IMPORTING
                               r_salv_tree = o_tree
                             CHANGING
                               t_table     = it_spfli_empty ).

* Header setzen
      o_tree->get_tree_settings( )->set_header( CONV #( sy-title ) ).
      o_tree->get_tree_settings( )->set_hierarchy_header( 'Carrier' ).
      o_tree->get_tree_settings( )->set_hierarchy_tooltip( 'Carrier' ).
      o_tree->get_tree_settings( )->set_hierarchy_size( 40 ).
      o_tree->get_tree_settings( )->set_hierarchy_icon( CONV #( icon_tree ) ).

* Treenodes einfügen
      LOOP AT it_spfli ASSIGNING FIELD-SYMBOL(<c>) GROUP BY <c>-carrid.

        DATA(it_cp) = VALUE ty_it_spfli( FOR <cp> IN GROUP <c> ( <cp> ) ).

        DATA(o_parent) = o_tree->get_nodes( )->add_node( related_node   = ''
                                                         relationship   = cl_gui_column_tree=>relat_last_child
                                                         collapsed_icon = CONV #( icon_closed_folder )
                                                         expanded_icon  = CONV #( icon_open_folder )
                                                         row_style      = if_salv_c_tree_style=>intensified
                                                         text           = CONV #( <c>-carrid ) ).

        IF lines( it_cp ) > 1.
          o_parent->get_item( 'CARRID' )->set_type( if_salv_c_item_type=>button ).
          o_parent->get_item( 'CARRID' )->set_value( 'all' ).
        ENDIF.

        LOOP AT GROUP <c> ASSIGNING FIELD-SYMBOL(<f>).
          DATA(o_carrid) = o_tree->get_nodes( )->add_node( related_node = o_parent->get_key( )
                                                           relationship = cl_gui_column_tree=>relat_last_child
                                                           data_row     = <f>
                                                           row_style    = if_salv_c_tree_style=>intensified
                                                           text         = CONV #( <f>-connid ) ).

          o_carrid->get_item( 'CARRID' )->set_type( if_salv_c_item_type=>checkbox ).
          o_carrid->get_item( 'CARRID' )->set_editable( abap_true ).
        ENDLOOP.

      ENDLOOP.

* Mandant ausblenden
      o_tree->get_columns( )->get_column( 'MANDT' )->set_technical( abap_true ).
* Carrid zentriert
      o_tree->get_columns( )->get_column( 'CARRID' )->set_alignment( if_salv_c_alignment=>right ).

* Spaltenbreiten optimieren
      o_tree->get_columns( )->set_optimize( abap_true ).

* Flugzeiten Aggregieren
      o_tree->get_aggregations( )->add_aggregation( columnname  = 'FLTIME'
                                                    aggregation = if_salv_c_aggregation=>total ).

* Alle Funktionsbuttons einschalten
      o_tree->get_functions( )->set_all( abap_true ).

* eigenen Button hinzufügen
* das Hinzufügen des Buttons funktioniert nur, wenn die SALV-Table innerhalb eines Containers (z.B. cl_gui_container=>default_screen) eingebettet ist
*      o_tree->get_functions( )->add_function( name     = 'BTN_USR'
*                                              icon     = CONV #( icon_abap )
*                                              text     = 'Testbutton'
*                                              tooltip  = 'Testbutton'
*                                              position = if_salv_c_function_position=>right_of_salv_functions ).

* Handler für Button-Click setzen
      SET HANDLER lcl_events=>on_button_click FOR o_tree->get_event( ).
*      SET HANDLER lcl_events=>on_user_command FOR o_tree->get_event( ).

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

[ABAP] Verwendung des Engineering Client Viewer für 2D-/3D-Objekte (ECL viewer)

Beispiel 1: JPEG anzeigen

DATA: o_dock TYPE REF TO cl_gui_docking_container.

PARAMETERS: p_name TYPE string. " Dummy-Parameter

AT SELECTION-SCREEN OUTPUT.

  IF NOT o_dock IS BOUND.
* Dockingcontainer erzeugen
    o_dock = NEW #( repid = sy-repid
                    dynnr = sy-dynnr
                    side  = cl_gui_docking_container=>dock_at_right
                    ratio = 50 ).

* ECL viewer erzeugen
    DATA(o_viewer) = NEW cl_gui_ecl_2dviewer( parent = o_dock ).

* Toolbar einstellen
    o_viewer->create_toolbar( close_button = abap_false
                              navigation = abap_true
                              options = abap_true
                              remove_document = abap_true
                              tools = abap_false
                              tool_stamp = abap_false
                              tool_compare = abap_false
                              tool_measurement = abap_false
                              viewer = abap_true
                              viewer_openfile = abap_true
                              viewer_savefile = abap_true
                              viewer_closefile = abap_true ).

* JPEG anzeigen
    o_viewer->open_document( file = 'c:\temp\temp.jpg'
                             file_type = 'image/jpeg' ). " https://wiki.selfhtml.org/wiki/Referenz:MIME-Typen

  ENDIF.

Beispiel 2: PDF anzeigen

  
* ECL viewer in extra Fenster
DATA(o_viewer) = NEW cl_gui_ecl_viewerbox( ).

* Fullscreen
o_viewer->set_alignment( 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 ).

* PDF öffnen
o_viewer->open_document( file = 'c:\temp\temp.pdf'
                         file_type = 'application/pdf' ). " https://wiki.selfhtml.org/wiki/Referenz:MIME-Typen

Weiterführende Infos:

[ABAP] Eigenständiges Dialogfenster (cl_gui_dialogbox_container) fullscreen (maximized) mit SALV-Table ohne zus. Dynpro anzeigen

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      on_close FOR EVENT close OF cl_gui_dialogbox_container
        IMPORTING sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.
  METHOD on_close.
    IF sender IS NOT INITIAL.
      sender->free( ).
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.

  TRY.
      DATA: it_sflight TYPE STANDARD TABLE OF sflight WITH DEFAULT KEY.

      SELECT * INTO TABLE it_sflight FROM sflight WHERE carrid = 'LH'.

* Window-Style hier ohne cl_gui_control=>ws_thickframe vordefinieren, wenn das Fenster nicht richtig maximized werden soll
      DATA(lv_style) = cl_gui_control=>ws_thickframe + cl_gui_control=>ws_minimizebox + cl_gui_control=>ws_maximizebox + cl_gui_control=>ws_sysmenu.

* siehe auch 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                 = 'Flüge'
                                                    top                     = 1
                                                    left                    = 1
                                                    width                   = 640
                                                    height                  = 480
                                                    style                   = lv_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 setzen
      SET HANDLER lcl_events=>on_close FOR o_cnt.

      DATA: o_salv TYPE REF TO cl_salv_table.

* SALV-Grid erzeugen und in das Containerfenster einbetten
      cl_salv_table=>factory( EXPORTING r_container  = o_cnt
                              IMPORTING r_salv_table = o_salv
                              CHANGING  t_table      = it_sflight ).

* automatische Spaltenbreite
      o_salv->get_columns( )->set_optimize( abap_true ).
* Darstellung mit Striped-Pattern
      o_salv->get_display_settings( )->set_striped_pattern( abap_true ).

      o_salv->display( ).

* cl_gui_container=>default_screen erzwingen
      WRITE:  space.
    CATCH cx_root.
  ENDTRY.