‎2008 Jun 05 10:33 AM
hi,
I have a structure say lt_struc which has some 10 fields.
i have a variable lv_field which holds the field name.
how do i fetch the field value for the field name stored in the variable lv_field from the structure lt_struc.
with regards
kiran
‎2008 Jun 05 10:37 AM
Use the Field Symbols.
Field-symbols: <f_fs> type any,
<f_f1> type any,
<f_f2> type any,
<f_f3> tye any.
Loop at lt_struc assigning <f_fs>.
ASSIGN COMPONENT 1 OF STRUCTURE <f_fs> TO <f_f1>.
ASSIGN lv_field TO <f_fs2>.
<f_fs1> = <f_fs2>.
endloop.Regards
Kannaiah
‎2008 Jun 05 10:36 AM
I didnt understand what exactly you want for dynamically fetching values you can use FIELD-SYMBOLS for fetching the values
‎2008 Jun 05 10:37 AM
Use the Field Symbols.
Field-symbols: <f_fs> type any,
<f_f1> type any,
<f_f2> type any,
<f_f3> tye any.
Loop at lt_struc assigning <f_fs>.
ASSIGN COMPONENT 1 OF STRUCTURE <f_fs> TO <f_f1>.
ASSIGN lv_field TO <f_fs2>.
<f_fs1> = <f_fs2>.
endloop.Regards
Kannaiah
‎2008 Jun 05 12:42 PM
Actually i will not be knowing which field to access before hand from the structure. only at run time i will get to know which field to access.
So it is something like i have the field name stored in a variable.
Request to provide code in detail.
thanks
kiran
‎2008 Jun 05 12:44 PM
Hi,
ASSIGN COMPONENT comp OF STRUCTURE struc TO <comp>.
[Assigning Components of Structures to a Field Symbol|http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3923358411d1829f0000e829fbfe/frameset.htm]
DATA gs_mara TYPE mara.
DATA gv_fieldname TYPE fieldname VALUE 'MATNR'.
FIELD-SYMBOLS <gv_fieldvalue> TYPE ANY.
ASSIGN COMPONENT gv_fieldname OF STRUCTURE gs_mara TO <gv_fieldvalue>.
Regards Rudi
‎2008 Jun 05 2:23 PM
Hi,
Let me be simple in explaining the what I want:
Data: itab type (DDIC structure Name).
Now this DDIC structure Name has 5 fields: f1,f2,f3,f4&f5.
Now I want:
Data: lv_temp type string.
Field-symbols: <lv_dynamic_field> type ANY.
lv_temp = itab-<lv_dynamic_field>. - is this the correct one ?
here lv_dynamic_field can have any field name like f1 or f2 or f3......
Hope you got the issue now ?
Thanks & Regards,
Kiran
‎2008 Jun 05 10:54 PM
data: l_fldname type string.
field-symbols: <fs1> type any.
l_fldname = assign the fieldname of the internal table to this string.
assign (l_fldname) to <fs1>.
now you can use this field symbol <fs1> for your further processing.
Hope this would help you.
‎2008 Jun 06 6:03 AM
Thanks Rudi, I followed your solution and it worked.
Thank you all for your help.
With regards,
kiran