08-06-2009 2:20 PM
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
08-06-2009 2:38 PM
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.
08-06-2009 2:38 PM
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.
08-06-2009 2:44 PM
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?
08-06-2009 2:46 PM
08-06-2009 2:46 PM
08-06-2009 2:51 PM
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.
08-06-2009 2:56 PM