[ABAP] Customizing-Objekte zu einem Datenfeld lesen

TYPES : BEGIN OF ty_s_customizing_tables,
          tabname TYPE dd02l-tabname,
          ddtext  TYPE dd02t-ddtext,
        END OF ty_s_customizing_tables.

TYPES: ty_it_customizing_tables TYPE STANDARD TABLE OF ty_s_customizing_tables WITH DEFAULT KEY.

DATA: it_customizing_tables TYPE ty_it_customizing_tables.

* Klasse für Eventhandling definieren
CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
* Doppelklick
    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.
* Tabelle / Pflegeview
    DATA(lv_tab) = CONV dd02l-tabname( it_customizing_tables[ row ]-tabname ).

* Customizingobjekte zu Tabelle anzeigen, ins SAP-IMG abspringen
    CALL FUNCTION 'OBJECT_MAINTENANCE_CALL'
      EXPORTING
        tabname                        = lv_tab
      EXCEPTIONS
        interface_not_correct          = 1
        transaction_not_maintained     = 2
        transaction_not_found          = 3
        table_not_activ                = 4
        table_not_found                = 5
        subobject_not_found_in_project = 6
        subobject_not_found_in_guide   = 7
        object_not_found_in_project    = 8
        object_not_found_in_guide      = 9
        table_has_no_object_in_project = 10
        table_has_no_object_in_guide   = 11
        outline_not_found              = 12
        call_transaction_recurring     = 13
        system_failure                 = 14
        OTHERS                         = 15.

    DATA(lv_err) = ||.

    CASE sy-subrc.
      WHEN 1.
        lv_err = |INTERFACE_NOT_CORRECT|.
      WHEN 2.
        lv_err = |TRANSACTION_NOT_MAINTAINED|.
      WHEN 3.
        lv_err = |TRANSACTION_NOT_FOUND|.
      WHEN 4.
        lv_err = |TABLE_NOT_ACTIV|.
      WHEN 5.
        lv_err = |TABLE_NOT_FOUND|.
      WHEN 6.
        lv_err = |SUBOBJECT_NOT_FOUND_IN_PROJECT|.
      WHEN 7.
        lv_err = |SUBOBJECT_NOT_FOUND_IN_GUIDE|.
      WHEN 8.
        lv_err = |OBJECT_NOT_FOUND_IN_PROJECT|.
      WHEN 9.
        lv_err = |OBJECT_NOT_FOUND_IN_GUIDE|.
      WHEN 10.
        lv_err = |TABLE_HAS_NO_OBJECT_IN_PROJECT|.
      WHEN 11.
        lv_err = |TABLE_HAS_NO_OBJECT_IN_GUIDE|.
      WHEN 12.
        lv_err = |OUTLINE_NOT_FOUND|.
      WHEN 13.
        lv_err = |CALL_TRANSACTION_RECURRING|.
      WHEN 14.
        lv_err = |SYSTEM_FAILURE|.
      WHEN 15.
        lv_err = |OTHERS|.
    ENDCASE.

    MESSAGE |{ lv_err }| TYPE 'S' DISPLAY LIKE 'E'.

  ENDMETHOD.
ENDCLASS.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (10) l_field FOR FIELD p_field.
PARAMETER: p_field TYPE dd03vv-fieldname DEFAULT 'VSBED'.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.

  l_field = 'Feldname:'.

START-OF-SELECTION.

* Customizingtabellen zu einem Datenfeld lesen
  SELECT t~tabname,
         tx~ddtext
    FROM dd03vv AS t
    INNER JOIN dd02l AS c ON t~tabname = c~tabname
    INNER JOIN dd02t AS tx ON t~tabname = tx~tabname
    INTO TABLE @it_customizing_tables
    WHERE t~fieldname = @p_field     " Feldname
      AND t~tabclass = 'TRANSP'      " transparente Tabellen
      AND t~as4local = 'A'           " aktive Objekte
      AND c~contflag IN ('C', 'G')   " Typ: Customizing-Tabellen
      AND tx~ddlanguage = @sy-langu. " Anmeldesprache

  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_customizing_tables ).

* 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( |Customizing-Tabellen zu Datenfeld { p_field } (Doppelklick -> IMG)| ).
      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.

* Handler registrieren
      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.

Links

[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.

[ABAP] Element des Selektionsbildes lesen und Wert für dynamische F4-Suchhilfe benutzen

PARAMETERS: p_table LIKE dd02l-tabname DEFAULT 'T100'.
PARAMETERS: p_field TYPE slis_fieldname.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_field.

  DATA: it_fieldvalues TYPE STANDARD TABLE OF rsselread WITH DEFAULT KEY.
  APPEND VALUE #( name = 'P_TABLE' " Dynprofeld P_TABLE
                  kind = 'P'       " P - PARAMETER, S - SELECT-OPTION
                ) TO it_fieldvalues.

* Element des Selektionsbildes lesen
  CALL FUNCTION 'RS_SELECTIONSCREEN_READ'
    EXPORTING
      program     = sy-repid
      dynnr       = sy-dynnr
    TABLES
      fieldvalues = it_fieldvalues.

  DATA(lv_tabname) = it_fieldvalues[ 1 ]-fieldvalue.

  IF NOT lv_tabname IS INITIAL.
    TRANSLATE lv_tabname TO UPPER CASE.

    SELECT fieldname
      FROM dd03l
      INTO TABLE @DATA(it_cols)
      WHERE tabname = @lv_tabname.

    IF sy-subrc = 0.
      DATA: it_return TYPE STANDARD TABLE OF ddshretval WITH DEFAULT KEY.

* F4-Hilfe mit Übergabe der anzuzeigenden Werte in interner Tabelle
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          retfield        = 'FIELDNAME' " Rückgabewert aus dem Feld FIELDNAME
          dynpprog        = sy-repid
          dynpnr          = sy-dynnr
          dynprofield     = 'P_FIELD'   " Name des Dynpro-Feldes für die automatische Werterückgabe
          value_org       = 'S'         " Werteübergabe: C: zellenweise, S: strukturiert
          window_title    = 'Auswahl'
        TABLES
          value_tab       = it_cols     " Übergabe-Tabelle mit Werten für die Anzeige und Auswahl
          return_tab      = it_return   " Rückgabe-Tabelle mit den ausgewählten (geklickten) Elementen
        EXCEPTIONS
          parameter_error = 1
          no_values_found = 2
          OTHERS          = 3.

      IF sy-subrc = 0.
        IF lines( it_return ) > 0.
          MESSAGE it_return[ 1 ]-fieldval TYPE 'S'.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

[ABAP] Nützliche ABAP-Datentypen, Domänen, Tabellentypen

* Datentypen
* DD04L
* DD04T
* DD04V

Name          Typ         Länge   Beschreibung
---------------------------------------------------------------------------
MANDT         CLNT        3       Mandant

DEC_16_01_S   DEC         16,1    Dezimalwert mit 1 Nachkommastelle
DEC_16_02_S   DEC         16,2    Dezimalwert mit 2 Nachkommastellen
DEC_16_03_S   DEC         16,3    Dezimalwert mit 3 Nachkommastellen
DEC_16_04_S   DEC         16,4    Dezimalwert mit 4 Nachkommastellen
DEC_16_05_S   DEC         16,5    Dezimalwert mit 5 Nachkommastellen
DEC_16_06_S   DEC         16,6    Dezimalwert mit 6 Nachkommastellen
DEC20_2       DEC         20,2    Dezimalwert mit 2 Nachkommastellen
DEC20_3       DEC         20,3    Dezimalwert mit 3 Nachkommastellen
DECIMAL21_7   DEC         21,7    Dezimalwert mit 7 Nachkommastellen
DEC23_2       DEC         23,2    Dezimalwert mit 2 Nachkommastellen
DEC31_14      DEC         31,14   Dezimalwert mit 14 Nachkommastellen

SURL          CHAR        255     URL Länge 255
SWK_URL       CHAR        2048    URL Länge 2048
SKWF_URL      CHAR        4096    URL Länge 4096
USS_Y_URL     CHAR        255     URL Länge 255
VBC_URL2      CHAR        1024    URL Länge 1024

BAPI_MSG      CHAR        220     Meldungstext
ERR_TEXT      CHAR        60      Fehlertext
TEXT255       CHAR        255     Text Lowercase
TWB_S_TXT     CHAR        200     Groß / Kleinschreibung berücksichtigt
TXT50         CHAR        50      Text
VBC_TEXT      CHAR        255     Beschreibung Lowercase
VBI_TEXT      CHAR        255     Beschreibung Lowercase
VEPTEXT       CHAR        255     Kurzbeschreibung Lowercase

SYSUUID_C     CHAR        32      UUID in Character-Darstellung

EDPLINE       CHAR        72      EDIC Programm-Editor Zeile

TABNAME       CHAR        30      Tabellenname

ERNAM         CHAR        12      Name des Benutzers
XUANAME       CHAR        12      Anleger des Benutzerstamms
XUBNAME	      CHAR        12      Benutzername im Benutzerstamm
XUMODIFIER    CHAR        12      Letzter Änderer

AWKGR         CURR        15,2    Betrag
BELWER        CURR        15,2    Betrag
KWERT         CURR        13,2    Konditionswert

ABBDT         DATS        8       Beginndatum des Zeitabschnitts
ABDATUM       DATS        8       Beginn eines Zeitraumes
ADATU         DATS        8       Datum Gültigkeitsbeginn
BEGDATUM      DATS        8       Beginndatum
BEGINDATE     DATS        8       Beginndatum
ERSDA         DATS        8       Erstellungsdatum (JJJJMMDD)
LAEDA         DATS        8       Datum der letzten Änderung (JJJJMMDD)
XULDATE       DATS        8       Letzes Login-Datum (JJJJMMDD)
XUERDAT       DATS        8       Anlegedatum des Benutzerstamms (JJJJMMDD)
XUMODDATE     DATS        8       Modifikationsdatum (JJJJMMDD)

BEGINUZ       TIMS        6       Beginnuhrzeit
BEGUZ         TIMS        6       Beginnuhrzeit
XULTIME       TIMS        6       Letzte Anmeldeuhrzeit (HHMMSS)
XUMODTIME     TIMS        6       Modifikationszeit (HHMMSS)

TIMESTAMP     DEC         15      UTC-Zeitstempel in Kurzform (JJJJMMTThhmmss)
TIMESTAMPL    DEC         21,7    UTC-Zeitstempel in Langform (JJJJMMTThhmmssmmmuuun)

* Domänen
* DD01L
* DD01T
* DD01V

Name          Typ         Länge   Beschreibung
---------------------------------------------------------------------------
RSDSSELOPT    CHAR        45      Zeilentyp für RANGE-Tabelle
FUNCNAME      CHAR        30      Unterprogrammname
TDSFNAME      CHAR        30      Smart Forms: Formularname

* Strukturen
* DD02L
* DD03L
* DD03T


* Tabellentypen
* DD40L
* DD40T

Typ            Zeilentyp   Länge   Beschreibung
----------------------------------------------------------------------------
BAPIRETTAB     BAPIRET2            Tabelle mit BAPI Return Informationen
BAPIRET2_T     BAPIRET2            Returntabelle
BDCDATA_TAB    BDCDATA     309     Tabelle für Batchdaten
SOTR_TXTS      CHAR        255     Texttabelle
TTTEXT255      CHAR        255     Texttabelle
HTML_TABLE     W3HTML      255     Texttabelle für HTML
W3_HTMLTAB     W3_HTML     255     Texttabelle für HTML
INT4_TABLE     INT4        10      Standard Table of INT4
W3MIMETABTYPE  RAW         255     Tabelle für RAW-Daten
XML_RAWDATA    RAW         255     Tabelle für RAW-Daten
WD_OBJECTS     REF                 Tabelle zur Speicherung von REF TO OBJECT
RSEC_T_SPOPLI  SPOPLI      67      Auswahl von Werten
RSELOPTION     RSDSSELOPT  93      SELECT-OPTIONS Tabelle
STRINGTAB      STRING              Tabelle mit Strings
STRING_TABLE   STRING              Tabelle mit Strings
TLINE_T        TLINE               Tabelle mit TLINE
ICL_THEAD_TAB  THEAD               tabelle mit THEAD

[ABAP] Tabellen zu einer Transaktion auflisten

TYPES: BEGIN OF ty_data_item,
         tcode    TYPE tstc-tcode,
         ttext    TYPE tstct-ttext,
         pgmna    TYPE tstc-pgmna,
         tabname  TYPE d010tab-tabname,
         tabclass TYPE dd02l-tabclass,
         ddtext   TYPE dd02t-ddtext,
       END OF ty_data_item.

DATA: it_data TYPE STANDARD TABLE OF ty_data_item WITH DEFAULT KEY.

PARAMETERS: ptcode TYPE tstc-tcode DEFAULT 'MIGO'.
PARAMETERS: plang TYPE dd02t-ddlanguage DEFAULT 'DE'.

START-OF-SELECTION.

* Holt Transaktion, Programm zur Transaktion, verwendete Tabellen im Programm
  SELECT tstc~tcode, tstct~ttext, tstc~pgmna, d010tab~tabname, dd02l~tabclass, dd02t~ddtext
    FROM tstc
      INNER JOIN d010tab ON d010tab~master = tstc~pgmna
      INNER JOIN dd02l ON dd02l~tabname = d010tab~tabname
      INNER JOIN dd02t ON dd02t~tabname = dd02l~tabname
      INNER JOIN tstct ON tstct~tcode = tstc~tcode
      INTO CORRESPONDING FIELDS OF TABLE @it_data
      WHERE tstc~tcode = @ptcode
      AND dd02t~ddlanguage = @plang
      AND tstct~sprsl = @plang.

  SORT: it_data BY tabclass DESCENDING tabname.

  DATA: o_salv TYPE REF TO cl_salv_table.

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

  o_salv->get_functions( )->set_all( abap_true ).
  o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
  o_salv->get_columns( )->set_optimize( abap_true ).

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

  o_salv->display( ).

[ABAP] dynamische Tabelle zur Laufzeit aus einem Feldkatalog erstellen und in SALV-Table anzeigen

DATA : it_fcat TYPE lvc_t_fcat.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
    i_structure_name = 'SPFLI'  " Dictionary-Struktur
  CHANGING
    ct_fieldcat      = it_fcat. " Feldkatalog

DATA: o_tab TYPE REF TO data.
* dynamische Tabelle aus dem Feldkatalog erstellen
cl_alv_table_create=>create_dynamic_table( EXPORTING
                                             it_fieldcatalog = it_fcat
                                           IMPORTING
                                             ep_table        = o_tab ).

* dynamische Tabelle auf Feldsymbol abbilden
FIELD-SYMBOLS: <tab> TYPE ANY TABLE.
ASSIGN o_tab->* TO <tab>.

* Daten holen
SELECT * FROM spfli INTO TABLE <tab> UP TO 10 ROWS.

* Daten anzeigen
DATA: o_alv TYPE REF TO cl_salv_table.
TRY.
    cl_salv_table=>factory( IMPORTING
                              r_salv_table = o_alv
                            CHANGING
                              t_table      = <tab> ).

    o_alv->display( ).

  CATCH cx_root.
ENDTRY.

Links