[ABAP] Feldinfos zu Tabellenfeldern auslesen

* Infos zur Tabelle 'MARA' lesen
SELECT fieldname, rollname
  INTO TABLE @DATA(it_elements)
  FROM dd03l
  WHERE tabname  = 'MARA'
    AND comptype = 'E'
    AND as4local = 'A'.

IF sy-subrc = 0.

  DATA: lv_dtel TYPE rsddtel.

  LOOP AT it_elements ASSIGNING FIELD-SYMBOL(<e>).
* Infos zu Datenelement lesen, ruft implizit FuBa DDIF_FIELDINFO_GET
    CALL FUNCTION 'RSD_DTEL_GET'
      EXPORTING
        i_dtelnm       = <e>-rollname
      IMPORTING
        e_s_dtel       = lv_dtel
      EXCEPTIONS
        dtel_not_found = 1
        doma_not_found = 2
        illegal_input  = 3
        OTHERS         = 4.

    IF sy-subrc = 0.
* Daten  hinzufügen
      cl_demo_output=>write_data( lv_dtel ).
    ENDIF.
  ENDLOOP.

* Daten anzeigen
  cl_demo_output=>display( ).

ENDIF.

[ABAP] Zugriff auf die Metainformationen einer internen Tabelle

* Daten holen
SELECT carrid, connid, fldate, price, currency, planetype
  INTO TABLE @DATA(it_sflight)
  FROM sflight .

* Table: Beschreibung
DATA(o_tdesc) = CAST cl_abap_tabledescr( cl_abap_tabledescr=>describe_by_data( it_sflight ) ).
* Row: Beschreibung
DATA(o_sdesc) = CAST cl_abap_structdescr( o_tdesc->get_table_line_type( ) ).
* Col: Komponenten (Felder) -> DFIES: DD-Schnittstelle: Tabellenfelder für DDIF_FIELDINFO_GET
DATA(it_com) = o_sdesc->get_components( ).

* Header
LOOP AT it_com ASSIGNING FIELD-SYMBOL(<c>).
* Prüfen, ob DDIC-Typ, damit die Metadaten ausgelesen werden können
  DATA(o_edesc) = CAST cl_abap_elemdescr( <c>-type ).
  IF o_edesc->is_ddic_type( ) EQ abap_true.
    DATA(lv_dfies) = o_edesc->get_ddic_field( ).
* technischer Name
*    WRITE: |{ <c>-name WIDTH = lv_dfies-scrlen3 }|.
* Langtext des Feldes
    WRITE: |{ lv_dfies-scrtext_l WIDTH = lv_dfies-scrlen3 }|.
  ENDIF.
ENDLOOP.

ULINE.

* Daten zellenweise auslesen
LOOP AT it_sflight ASSIGNING FIELD-SYMBOL(<row>).

  LOOP AT it_com ASSIGNING FIELD-SYMBOL(<col>).
* Prüfen, ob DDIC-Typ, damit die Metadaten ausgelesen werden können
    DATA(o_edesc2) = CAST cl_abap_elemdescr( <col>-type ).
    IF o_edesc2->is_ddic_type( ) EQ abap_true.
* wenn DDIC-Typ, dann Metainformationen auslesen
      DATA(lv_dfies2) = o_edesc2->get_ddic_field( ).
* anhand des Komponentennamens den akt. Zellinhalt einer Zeile lesen
      ASSIGN COMPONENT <col>-name OF STRUCTURE <row> TO FIELD-SYMBOL(<cell>).
      WRITE: |{ <cell> WIDTH = lv_dfies2-scrlen3 }|.
    ENDIF.
  ENDLOOP.

  WRITE: /.

ENDLOOP.