Code: Alles auswählen.
DATA:
lt_mara TYPE TABLE OF MARA,
lt_marc TYPE TABLE OF MARC.
PERFORM TEST USING lt_mara 'MANDT'.
PERFORM TEST USING lt_mara 'ABCDE'.
PERFORM TEST USING lt_marc 'MANDT'.
PERFORM TEST USING lt_marc 'ABCDE'.
FORM TEST USING lt_data TYPE ANY TABLE
l_fieldname TYPE c.
*
* Hier geschieht ein Wunder :)
*
IF SY-SUBRC = 0.
WRITE 'vorhanden'.
ELSE.
WRITE 'nicht vorhanden'.
ENDIF.
ENDFORM.
Hast du dir einmal die RTTS - Run Time Type Services angeschaut? Diese liefern dir zur Laufzeit Informationen zu Datenelementen. Für Tabellen und Strukturen gibt es die Klassen:Timo7 hat geschrieben:Hat jemand eine Idee, wie man dieses Problem angehen kann?
Code: Alles auswählen.
DATA:
lt_mara TYPE TABLE OF MARA,
lt_marc TYPE TABLE OF MARC.
PERFORM TEST USING lt_mara 'MANDT'.
PERFORM TEST USING lt_mara 'ABCDE'.
PERFORM TEST USING lt_marc 'MANDT'.
PERFORM TEST USING lt_marc 'ABCDE'.
FORM TEST USING lt_data TYPE ANY TABLE
l_fieldname TYPE c.
DATA:
lo_tabdef TYPE ref to cl_abap_tabledescr.
lo_tabdef ?= cl_abap_typedescr=>DESCRIBE_BY_DATA( LT_data ).
READ TABLE lo_tabdef->key WITH KEY NAME = l_fieldname
TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0.
WRITE / 'vorhanden'.
ELSE.
WRITE / 'nicht vorhanden'.
ENDIF.
ENDFORM.
Code: Alles auswählen.
TYPES:
BEGIN OF tw_test,
C TYPE c,
N TYPE n,
D TYPE d,
T TYPE t,
X TYPE x,
I TYPE i,
P TYPE p,
F TYPE f,
S TYPE string,
Z TYPE xstring,
END OF tw_test.
DATA:
lt_test TYPE TABLE OF tw_test.
PERFORM TEST USING lt_test 'C'.
PERFORM TEST USING lt_test 'N'.
PERFORM TEST USING lt_test 'D'.
PERFORM TEST USING lt_test 'T'.
PERFORM TEST USING lt_test 'X'.
PERFORM TEST USING lt_test 'I'.
PERFORM TEST USING lt_test 'P'.
PERFORM TEST USING lt_test 'F'.
PERFORM TEST USING lt_test 'S'.
PERFORM TEST USING lt_test 'Z'.
FORM TEST USING lt_data TYPE ANY TABLE
l_fieldname TYPE c.
DATA:
lo_tabdef TYPE ref to cl_abap_tabledescr.
lo_tabdef ?= cl_abap_typedescr=>DESCRIBE_BY_DATA( LT_data ).
READ TABLE lo_tabdef->key WITH KEY NAME = l_fieldname
TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0.
WRITE: / l_fieldname, ': vorhanden'.
ELSE.
WRITE: / l_fieldname, ': nicht vorhanden'.
ENDIF.
ENDFORM.
Vorsichtig die obere Anweisung greift nur auf die Schlüsselfelder der Tabelle zu. Du willst aber alle Felder der Zeile verproben, dafür mußt du die Zeilenstruktur auswerten:Timo7 hat geschrieben: Kann man auch irgendwie erreichen, dass Integer-,
Packed- und Float-Felder in der Struktur gefunden werden?Code: Alles auswählen.
READ TABLE lo_tabdef->key WITH KEY NAME = l_fieldname TRANSPORTING NO FIELDS.
Code: Alles auswählen.
FORM test USING lt_data TYPE ANY TABLE
l_fieldname TYPE c.
DATA:
* Referenz auf Tabellenbeschreibung
lo_tabdef TYPE REF TO cl_abap_tabledescr,
* Referenz auf Tabellenstrukturbeschreibung
lo_datadef TYPE REF TO cl_abap_datadescr,
lo_strucdef TYPE REF TO cl_abap_structdescr.
* Tabellenbeschreibung hohlen
lo_tabdef ?= cl_abap_typedescr=>describe_by_data( lt_data ).
* Tabellenstrukturbeschreibung hohlen
CALL METHOD lo_tabdef->get_table_line_type
RECEIVING
p_descr_ref = lo_datadef.
* Typecasting
lo_strucdef ?= lo_datadef.
* Felder der Tabellenstruktur verproben
READ TABLE lo_strucdef->components WITH KEY name = l_fieldname
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
WRITE: / l_fieldname, ': vorhanden'.
ELSE.
WRITE: / l_fieldname, ': nicht vorhanden'.
ENDIF.
ENDFORM. "TEST
Code: Alles auswählen.
TYPES:
BEGIN OF tw_test,
C TYPE c,
N TYPE n,
D TYPE d,
T TYPE t,
X TYPE x,
I TYPE i,
P TYPE p,
F TYPE f,
S TYPE string,
Z TYPE xstring,
END OF tw_test.
DATA:
lt_test TYPE TABLE OF tw_test.
PERFORM TEST USING lt_test 'C'.
PERFORM TEST USING lt_test 'N'.
PERFORM TEST USING lt_test 'D'.
PERFORM TEST USING lt_test 'T'.
PERFORM TEST USING lt_test 'X'.
PERFORM TEST USING lt_test 'I'.
PERFORM TEST USING lt_test 'P'.
PERFORM TEST USING lt_test 'F'.
PERFORM TEST USING lt_test 'S'.
PERFORM TEST USING lt_test 'Z'.
FORM TEST USING lt_data TYPE ANY TABLE
l_fieldname TYPE c.
DATA:
lo_tabdef TYPE ref to cl_abap_tabledescr,
lo_strdef TYPE ref to cl_abap_structdescr.
lo_tabdef ?= cl_abap_typedescr=>DESCRIBE_BY_DATA( LT_data ).
lo_strdef ?= lo_tabdef->get_table_line_type( ).
READ TABLE lo_strdef->components WITH KEY name = l_fieldname
TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0.
WRITE: / l_fieldname, ': vorhanden'.
ELSE.
WRITE: / l_fieldname, ': nicht vorhanden'.
ENDIF.
ENDFORM.