[ABAP] Verfügbare DB-Views zu Tabellen suchen

TYPES : BEGIN OF ty_s_views,
          viewname  TYPE dd26s-viewname,
          ddtext    TYPE dd25t-ddtext,
          roottab   TYPE dd25l-roottab,
          viewclass TYPE dd02l-viewclass,
          viewgrant TYPE dd02l-viewgrant,
        END OF ty_s_views.

TYPES: ty_it_views TYPE STANDARD TABLE OF ty_s_views WITH DEFAULT KEY.

DATA: it_views TYPE ty_it_views.

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: on_double_click FOR EVENT double_click OF cl_salv_events_table
      IMPORTING
          row
          column
          sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.
  METHOD on_double_click.
    DATA(lv_row) = it_views[ row ].
    ASSIGN COMPONENT column OF STRUCTURE lv_row TO FIELD-SYMBOL(<cell>).

* views mit texten
    DATA: lv_dd25v TYPE dd25v.
* DD: Technische Einstellungen von Tabellen
    DATA: lv_dd09l TYPE dd09l.

* View auf Basistabellen eines Views aus Tabelle DD26S
    DATA: it_dd26v_tab TYPE STANDARD TABLE OF dd26v.
* View auf Felder eines SAP-Tabellenviews aus Tabelle DD27S
    DATA: it_dd27p_tab TYPE STANDARD TABLE OF dd27p.
* Interne Struktur für Joins von Views
    DATA: it_dd28j_tab TYPE STANDARD TABLE OF dd28j.
* View auf Selektionsbedingung
    DATA: it_dd28v_tab TYPE STANDARD TABLE OF dd28v.

    CALL FUNCTION 'DDIF_VIEW_GET'
      EXPORTING
        name          = <cell>
      IMPORTING
        dd25v_wa      = lv_dd25v
        dd09l_wa      = lv_dd09l
      TABLES
        dd26v_tab     = it_dd26v_tab
        dd27p_tab     = it_dd27p_tab
        dd28j_tab     = it_dd28j_tab
        dd28v_tab     = it_dd28v_tab
      EXCEPTIONS
        illegal_input = 1
        OTHERS        = 2.

    IF sy-subrc = 0.
      cl_demo_output=>write_data( lv_dd25v ).
      cl_demo_output=>write_data( lv_dd09l ).
      cl_demo_output=>write_data( it_dd26v_tab ).
      cl_demo_output=>write_data( it_dd27p_tab ).
      cl_demo_output=>write_data( it_dd28j_tab ).
      cl_demo_output=>write_data( it_dd28v_tab ).
      cl_demo_output=>display( ).
    ENDIF.
  ENDMETHOD.
ENDCLASS.

DATA: lv_tab TYPE dd26s-fortabname.

SELECT-OPTIONS: so_tabs FOR lv_tab.

INITIALIZATION.

  so_tabs[] = VALUE #(
                       ( sign = 'I' option = 'EQ' low = 'MARA' high = '' )
                       ( sign = 'I' option = 'EQ' low = 'MARC' high = '' )
                     ).

START-OF-SELECTION.

  DATA(lv_lang) = cl_abap_syst=>get_logon_language( ).

  SELECT s~viewname,
         t~ddtext,
         r~roottab,
         l~viewclass,
         l~viewgrant
    INTO TABLE @it_views
    FROM dd26s AS s
    INNER JOIN dd02l AS l ON l~tabname = s~viewname
    INNER JOIN dd25l AS r ON r~viewname = l~tabname
    INNER JOIN dd25t AS t ON t~viewname = l~tabname
    WHERE s~fortabname IN @so_tabs
      AND l~as4local   = 'A'
      AND l~tabclass   = 'VIEW'
      AND t~ddlanguage = @lv_lang.

  IF sy-subrc = 0.

    SORT: it_views BY viewname.

    TRY.
        DATA: o_salv TYPE REF TO cl_salv_table.

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

        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.

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

        SET HANDLER lcl_events=>on_double_click FOR o_salv->get_event( ).

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

Kommentare sind geschlossen.