Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting field names of an internal table

Former Member
0 Kudos

Hi all,

Does anyone know if exists a statement, function module or method that gets the field names of an internal table ?

Thanks in advance,

David

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

See this

REPORT typedescr_test.

TYPES:

BEGIN OF my_struct,

comp_a type i,

comp_b type f,

END OF my_struct.

DATA:

my_data TYPE my_struct,

descr_ref TYPE ref to cl_abap_structdescr.

FIELD-SYMBOLS:

<comp_wa> TYPE abap_compdescr.

START-OF-SELECTION.

descr_ref ?= cl_abap_typedescr=>describe_by_data( my_data ).

WRITE: / 'Typename :', descr_ref->absolute_name.

WRITE: / 'Kind :', descr_ref->type_kind.

WRITE: / 'Length :', descr_ref->length.

WRITE: / 'Decimals :', descr_ref->decimals.

WRITE: / 'Struct Kind :', descr_ref->struct_kind.

WRITE: / 'Components'.

WRITE: / 'Name Kind Length Decimals'.

LOOP AT descr_ref->components ASSIGNING <comp_wa>.

WRITE: / <comp_wa>-name, <comp_wa>-type_kind,

<comp_wa>-length, <comp_wa>-decimals.

ENDLOOP.

4 REPLIES 4

Former Member
0 Kudos

Hi,

See this

REPORT typedescr_test.

TYPES:

BEGIN OF my_struct,

comp_a type i,

comp_b type f,

END OF my_struct.

DATA:

my_data TYPE my_struct,

descr_ref TYPE ref to cl_abap_structdescr.

FIELD-SYMBOLS:

<comp_wa> TYPE abap_compdescr.

START-OF-SELECTION.

descr_ref ?= cl_abap_typedescr=>describe_by_data( my_data ).

WRITE: / 'Typename :', descr_ref->absolute_name.

WRITE: / 'Kind :', descr_ref->type_kind.

WRITE: / 'Length :', descr_ref->length.

WRITE: / 'Decimals :', descr_ref->decimals.

WRITE: / 'Struct Kind :', descr_ref->struct_kind.

WRITE: / 'Components'.

WRITE: / 'Name Kind Length Decimals'.

LOOP AT descr_ref->components ASSIGNING <comp_wa>.

WRITE: / <comp_wa>-name, <comp_wa>-type_kind,

<comp_wa>-length, <comp_wa>-decimals.

ENDLOOP.

andreas_mann3
Active Contributor
0 Kudos

Hi,

1) DESCRIBE FIELD itab INTO TD.

2) fm REUSE_ALV_FIELDCATALOG_MERGE

regards Andreas

Former Member
0 Kudos

Hi, some solution has been mentioned.

In addition, you can also call FM 'GET_COMPONENT_LIST'

like following:

DATA: ITAB_SFLIGHT TYPE STANDARD TABLE OF TYP_SFLIGHT,

LC_SFLIGHT LIKE LINE OF ITAB_SFLIGHT.

DATA: ITAB_RSTRUCINFO TYPE STANDARD TABLE OF RSTRUCINFO.

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

PROGRAM = 'ZGZL_SDNTEST' "program name

FIELDNAME = 'LC_SFLIGHT'

TABLES

COMPONENTS = ITAB_RSTRUCINFO.

Hope it will work.

0 Kudos

Thanks for your quick (and very helpful) responses!