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 last published in June 2004

Dig Deeper on SAP Java and J2EE

PRO+

Content

Find more PRO+ content and other member only offers, here.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

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

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close