Code: Alles auswählen.
DATA:
obj_data TYPE REF TO data,
obj_table TYPE REF TO cl_abap_tabledescr,
lr_struc TYPE REF TO cl_abap_structdescr,
lt_parameters TYPE abap_parmbind_tab,
l_meth TYPE string VALUE 'GET_MARA'.
FIELD-SYMBOLS <tab> TYPE table.
* itab generieren
lr_struc ?= cl_abap_structdescr=>describe_by_name( 'mara' ).
obj_table ?= cl_abap_tabledescr=>create( lr_struc ).
CREATE DATA obj_data TYPE HANDLE obj_table.
ASSIGN obj_data->* TO <tab>.
* Parameter für dynamischen Methodenaufruf definieren
lt_parameters = VALUE #( name = 'R_TAB'
kind = cl_abap_objectdescr=>receiving
value = REF #( <tab> ) ).
TRY.
* Aufruf einer Beispielmethode get_mara, die eine Tabelle R_TAB vom Typ mara zurückgibt
CALL METHOD zclass=>(l_meth) PARAMETER-TABLE lt_parameters.
CATCH cx_sy_dyn_call_error.
ENDTRY.
Code: Alles auswählen.
CLASS zclass DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
CLASS-METHODS main
IMPORTING
!i_matnr TYPE matnr .
PRIVATE SECTION.
CLASS-METHODS get_mara
IMPORTING
!i_matnr TYPE matnr
RETURNING
VALUE(r_tab) TYPE zmara_t . "Tabellentyp mara (Standardtabelle, default key)
CLASS-METHODS create_itab
IMPORTING
!i_strucname TYPE string
RETURNING
VALUE(r_tabledescr) TYPE REF TO cl_abap_tabledescr .
ENDCLASS.
CLASS zclass IMPLEMENTATION.
METHOD main.
DATA:
obj_table TYPE REF TO cl_abap_tabledescr, "Beschreibung einer Tabelle
obj_data TYPE REF TO data, "Zum kreieren einer internen Tabelle
lt_parameters TYPE abap_parmbind_tab, "Übergabeparameter für Methode
lt_abap_parmbind TYPE TABLE OF abap_parmbind, "Tabelle Übergabeparameter
ls_abap_parmbind TYPE abap_parmbind, "Struktur Übergabeparameter
l_method TYPE string VALUE 'GET_MARA'.
FIELD-SYMBOLS:
<tab> TYPE table.
* itab generieren
obj_table = create_itab( 'MARA' ).
CREATE DATA obj_data TYPE HANDLE obj_table.
ASSIGN obj_data->* TO <tab>.
** Importparameter definieren
ls_abap_parmbind-name = 'I_MATNR'.
GET REFERENCE OF i_matnr INTO ls_abap_parmbind-value.
ls_abap_parmbind-kind = cl_abap_objectdescr=>exporting.
APPEND ls_abap_parmbind TO lt_abap_parmbind.
** Returning Parameter definieren
ls_abap_parmbind-name = 'R_TAB'.
ls_abap_parmbind-kind = cl_abap_objectdescr=>receiving.
GET REFERENCE OF <tab> INTO ls_abap_parmbind-value.
APPEND ls_abap_parmbind TO lt_abap_parmbind.
* Angegebene Methode aufrufen
TRY.
lt_parameters = lt_abap_parmbind.
CALL METHOD zclass=>(l_method) PARAMETER-TABLE lt_parameters.
CATCH cx_sy_dyn_call_error INTO DATA(lo_sy_dyn_call_error).
MESSAGE lo_sy_dyn_call_error->kernel_errid TYPE 'E'.
ENDTRY.
ENDMETHOD.
METHOD create_itab. "Eine interne Tabelle vom Typ des übergebenen Tabellennamens erstellen
DATA:
lr_struc TYPE REF TO cl_abap_structdescr.
lr_struc ?= cl_abap_structdescr=>describe_by_name( i_strucname ).
r_tabledescr ?= cl_abap_tabledescr=>create( lr_struc ).
ENDMETHOD.
METHOD get_mara.
SELECT *
FROM mara
INTO TABLE r_tab
WHERE matnr = i_matnr.
ENDMETHOD.
ENDCLASS.