[ABAP] Informationen zu Business Objekten anzeigen

* Transaktion SWO1

DATA: lv_objtyp TYPE swo_objtyp.
DATA: lv_stext TYPE swc_shtext.

SELECT-OPTIONS: so_objtp FOR lv_objtyp.
SELECT-OPTIONS: so_stext FOR lv_stext.
*PARAMETERS: p_spras type sy-langu DEFAULT 'E'.

INITIALIZATION.

  so_objtp[] = VALUE #( ( sign = 'I' option = 'EQ' low = 'BUS2012' high = '' ) ).
  so_stext[] = VALUE #( ( sign = 'I' option = 'CP' low = 'Bestellung*' high = '' )
                        ( sign = 'I' option = 'CP' low = 'Eink*' high = '' ) ).

START-OF-SELECTION.

  SELECT FROM tojtb AS tb
    INNER JOIN tojtt AS tt ON tb~name = tt~name
    FIELDS tb~name,
           tb~editelem,
           tt~ntext,
           tt~stext
    WHERE tb~name IN @so_objtp
*      AND tb~activelang = @p_spras
*      AND tt~language = @p_spras
    INTO TABLE @DATA(it_tojtb).

  IF sy-subrc = 0.

    SELECT dv~objtype,   " BO Typ
           dv~verb,      " Funktion
           dv~verbtype,  " Funktionstyp ( ' ' =   Kein Verb, K = Schlüsselfeld, A = Attribut, M = Methode, E = Ereignis )
           dv~editelem,  " Element
           dv~refstruct, " Tabelle
           dv~reffield,  " Bezugsfeld
           dv~abapname,  " Funktionsbaustein
           tv~descript,  " Beschreibung
           tv~shorttext  " Kurztext
      INTO TABLE @DATA(it_bor_info)
      FROM swotdv AS dv
      INNER JOIN swottv AS tv ON dv~objtype = tv~objtype AND dv~verb = tv~verb
      WHERE dv~objtype IN @so_objtp
*        AND tv~language = @p_spras
      AND tv~shorttext IN @so_stext.

    IF sy-subrc = 0.

      SORT: it_bor_info BY verbtype verb.

      TRY.
          DATA(lv_tojtb_name) = SWITCH #( lines( it_tojtb ) WHEN 0 THEN || ELSE it_tojtb[ 1 ]-name ).
          DATA(lv_tojtb_stext) = SWITCH #( lines( it_tojtb ) WHEN 0 THEN || ELSE it_tojtb[ 1 ]-stext ).

          lv_tojtb_name = SWITCH #( lines( so_objtp ) WHEN 0 THEN || ELSE |Objekttyp: { lv_tojtb_name }| ).
          lv_tojtb_stext = SWITCH #( lines( so_objtp ) WHEN 0 THEN |keine Selektion| ELSE lv_tojtb_stext ).

* 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_bor_info ).

* 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( |{ lv_tojtb_name } ({ lv_tojtb_stext })| ).
          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
          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->display( ).
        CATCH cx_root INTO DATA(e_txt).
          WRITE: / e_txt->get_text( ).
      ENDTRY.
    ENDIF.
  ENDIF.