2008 Oct 08 2:04 PM
Hello all,
how can i get the fieldname of a dynamic structure for example in a loop?
It is not really a problem but i am interested in an other solution.
Short example:
I create a dynamic structure and table of t001 named <t_table> and <w_struc>.
loop at <t_table> assigning <w_struc>.
do.
assign component sy-index of structure <w_table> to <field>.
now i want to know when i have access to 'PERIV', is index 10 in T001
i know 3 possibilities to get the name:
1: read table DD03L with tablename and index (=>low performance)
2: assign component 'PERIV' of structure <w_table> to <field>.
3: read itab lt_components with index (method lt_components = lref_struct_descr->get_components( ). )
why i can't get the name direct from the reference lref_struct_descr like
lref_struct_descr->get_fieldname( sy-index )? This information has to be known at runtime too, i think?
enddo.
endloop.
2008 Nov 19 2:22 AM
hello wolfgang, did you ever manage to find an answer to this ?
thanks
glen
2008 Nov 19 4:57 AM
Hello Wolfgang
I have two answers that are probably not satisfying to you:
(1) If you specifically want to access a field called 'PERIV' you do not need to go via the field index:
ASSIGN COMPONENT 'PERIV' OF STRUCTURE <gd_struc> TO <gd_fld>.
(2) Whereas a data object can be de-referenced to a field-symbol (e.g.)
CREATE DATA gdo_data TYPE TABLE OF ('T001').
ASSIGN gdo_data->* TO <gt_table>.
you cannot do this with classes or class attributes except they represent data objects.
Regards
Uwe
2008 Nov 19 9:24 AM
Hello Uwe,
thanks for answering, but you are right, this solution is not satisfying me
I know that i can access the field directly by name, but in some cases i need to know the name of the actual index of the structure. So i am searching a solutions without big overhead to get this information.
Thanks,
Wolfgang