Problem solve Get help with specific problems with your technologies, process and projects.

How to find column names in a statically defined internal table

Here is the sample code with which you can find out the fields and other properties of your statically defined internal table dynamically.

Here is the sample code with which you can find out the fields and other properties of your statically defined internal table dynamically. Code tested in 4.7EE.
REPORT ZTEST.

TYPE-POOLS : abap.

DATA: BEGIN OF tabl occurs 0,
mandt TYPE mara-mandt,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
laeda TYPE mara-laeda,
aenam TYPE mara-aenam,
vpsta TYPE mara-vpsta,
pstat TYPE mara-pstat,
lvorm TYPE mara-lvorm,
mtart TYPE mara-mtart,
mbrsh TYPE mara-mbrsh,
END OF tabl.

DATA : it_details TYPE abap_compdescr_tab,
wa_comp TYPE abap_compdescr.

DATA : ref_descr TYPE REF TO cl_abap_structdescr.

ref_descr ?= cl_abap_typedescr=>describe_by_data( tabl ).
it_details[] = ref_descr->components[].

loop at it_details into wa_comp.
write:/ wa_comp.
endloop.

Dig Deeper on SAP development and programming languages

Join the conversation

1 comment

Send me notifications when other members comment.

Please create a username to comment.

This error occurs:
"WA_COMP" cannot be converted to a character-type field.
Cancel

-ADS BY GOOGLE

SearchERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchContentManagement

SearchHRSoftware

Close