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 fieldname of dynamic structure by index

Former Member
0 Kudos
634

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.

3 REPLIES 3

glen_spalding
Participant
0 Kudos
176

hello wolfgang, did you ever manage to find an answer to this ?

thanks

glen

uwe_schieferstein
Active Contributor
0 Kudos
176

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

0 Kudos
176

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