VinceCoder
10/22/2019 - 12:45 PM

RTTS: ESEMPIO

"AS A DEMO Fetch data that normally comes from the RFC ...
DATA your_rfc_tab TYPE STANDARD TABLE OF mara.

REFRESH your_rfc_tab.
SELECT * UP TO 100 ROWS
  FROM mara
  INTO TABLE your_rfc_tab.
IF sy-subrc <> 0.
  EXIT.
ENDIF.

DATA:
  lo_data           TYPE REF TO data,
  lo_rfc_tabdescr   TYPE REF TO cl_abap_tabledescr,
  lo_rfc_strucdescr TYPE REF TO cl_abap_structdescr,
  lo_rfc_elemdescr  TYPE REF TO cl_abap_elemdescr,
  lt_rfc_components TYPE cl_abap_structdescr=>component_table,
  lt_components     TYPE cl_abap_structdescr=>component_table.

FIELD-SYMBOLS:
  <your_rfc_tab> TYPE STANDARD TABLE, "ANY TABLE,
  <value>        TYPE any.

"Object-Reference
GET REFERENCE OF your_rfc_tab INTO lo_data.
ASSIGN lo_data->* TO <your_rfc_tab>.

"Get Table-Struct-Components
lo_rfc_tabdescr   ?= cl_abap_tabledescr=>describe_by_data( <your_rfc_tab> ).
lo_rfc_strucdescr ?= lo_rfc_tabdescr->get_table_line_type( ).
lt_rfc_components = lo_rfc_strucdescr->get_components( ).

LOOP AT <your_rfc_tab> ASSIGNING FIELD-SYMBOL(<rfc_structure>).
  LOOP AT lt_rfc_components ASSIGNING FIELD-SYMBOL(<rfc_component>).
  "IF YOU NEED FIELDCATALOG-data ...
  "lo_rfc_elemdescr ?= cl_abap_elemdescr=>describe_by_name( <rfc_component>-type->get_relative_name( ) ).

    "Check NAME / ABSOLUTE / RELATIVE Name as Mapping-Source
    ASSIGN COMPONENT <rfc_component>-name OF STRUCTURE <rfc_structure> TO <value>.
    ASSIGN COMPONENT <rfc_component>-type->absolute_name+6 OF STRUCTURE <rfc_structure> TO <value>.
    ASSIGN COMPONENT <rfc_component>-type->get_relative_name( ) OF STRUCTURE <rfc_structure> TO <value>.

    IF <value> IS ASSIGNED.
      "DO YOUR THING ... 
      "Map with Table in Current System, Create New (Table)Type based on FieldCatalog-data, ...
    ENDIF.

  ENDLOOP.
  UNASSIGN <rfc_component>.
ENDLOOP.
UNASSIGN <rfc_structure>.