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: 

Get Fields of internal table

michael_fallenbchel
Active Participant

Hi experts,

small problem: I want to get all the field names of my internal table:

Coding:

DATA: lt_tabdescr     TYPE abap_keydescr_tab,
        ref_table_descr TYPE REF TO cl_abap_tabledescr.

  ref_table_descr ?=  cl_abap_typedescr=>describe_by_data( itab ).
  lt_tabdescr[] = ref_table_descr->key[].

  l_out[] = lt_tabdescr[].

With this, I only got the key fields.

I know there's a way with structures (like this):

DATA : lt_tabdescr TYPE abap_compdescr_tab,
DATA : ref_table_descr TYPE REF TO cl_abap_structdescr.

   ref_table_descr ?=  cl_abap_typedescr=>describe_by_name( struct_name ).
   lt_tabdescr[] = ref_table_descr->components[].

But this I can't use because I don't want to work with the table structure - I want to work with the internal table itself.

How to realize this?

Thanks in advance

Michael

1 ACCEPTED SOLUTION

rainer_hbenthal
Active Contributor

I did it this way:



  data:
    wa_ref               type ref to data,
    it_fields            type stringtab,

    desc_struc           type ref to cl_abap_structdescr,
    desc_fields          type ddfields.

  field-symbols:
    <wa_data>            type any,
    <p_str>              type string,
    <p_component>        type dfies.

  create data wa_ref like line of it_data.
  assign wa_ref->* to <wa_data>.

  desc_struc ?= cl_abap_structdescr=>describe_by_data( <wa_data> ).
  desc_fields = desc_struc->get_ddic_field_list( ).

  loop at desc_fields assigning <p_component>.
    ...
  endloop.

it_data is a parameter in the signature of a method with type any table.

6 REPLIES 6

rainer_hbenthal
Active Contributor

I did it this way:



  data:
    wa_ref               type ref to data,
    it_fields            type stringtab,

    desc_struc           type ref to cl_abap_structdescr,
    desc_fields          type ddfields.

  field-symbols:
    <wa_data>            type any,
    <p_str>              type string,
    <p_component>        type dfies.

  create data wa_ref like line of it_data.
  assign wa_ref->* to <wa_data>.

  desc_struc ?= cl_abap_structdescr=>describe_by_data( <wa_data> ).
  desc_fields = desc_struc->get_ddic_field_list( ).

  loop at desc_fields assigning <p_component>.
    ...
  endloop.

it_data is a parameter in the signature of a method with type any table.

0 Kudos

Sorry, this wont work for me.

If I do so I get an error:

Source-Type "\CLASS=CL_ABAP_TABLEDESCR"

Target-Type: "\CLASS=CL_ABAP_STRUCTDESCR"

I will use this In a function, the internal table is a changing-paramter:

itab type any table

Any other ideas?

0 Kudos

which system you are on? 4.7? ECC 6.0?

0 Kudos

Sorry, it's a ECC 6.0 (Unicode)

0 Kudos

Try this one:


  data:
    desc_table    type ref to cl_abap_tabledescr,
    desc_struc    type ref to cl_abap_structdescr.

  field-symbols:
    <p_component> type abap_compdescr.

  desc_table ?= cl_abap_tabledescr=>describe_by_data( it_data ).
  desc_struc ?= desc_table->get_table_line_type( ).

  loop at desc_struc->components assigning <p_component>.

  endloop.

this works in both methods and function modules. (on ECC 6.0)

Check <p_component>-name for the fieldname.

0 Kudos

Exactly what I needed!!

Perfect, thank you so much