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.

This was first published in June 2004

Dig deeper on SAP Java and J2EE

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

1 comment

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close