04-25-2007 8:25 AM
Hey fellows,
I need to loop on all structure's fields and get the name of the field and the value.
how can I do that?
thanks & regards
Natti Nachmias.
04-25-2007 8:27 AM
Is the structure you want to loop on defined in the dictionary...or just in the program?
04-25-2007 8:35 AM
...
If the structure is defined in the dictionary you can access the field names for the structure by reading table dd03l with the structure name in the table field...
you can then using a field symbol to access the data...
e.g.
data:
lst_dd07l LIKE dd07l,
lt_dd07l LIKE STANDARD TABLE OF lst_dd07l OCCURS 0.
field-symbols:
<lfs_field>.
select *
from dd07l
into table lt_dd07l
where tabname = '<YOUR STRUCTURE NAME>'.
loop at lt_dd07l
into lst_dd07l.
ASSIGN (lst_dd07l-fieldname) OF STRUCTURE <your structure name>
TO <lfs_field>.
endloop.
at the point you loop through the table you have both the field name and subsequently the <lfs_field> will hold the value assigned to that field in the structure.
04-25-2007 8:35 AM
the statement you are looking for is "Assign component of structure"
04-25-2007 8:38 AM
yup...sorry missed out the component bit!
assign component (lst_dd07l-fieldname) of structure <your structure> to <lfs_field>.
04-25-2007 8:40 AM
oh..and replace all reference to dd07l with dd03l like i said in the first statement!...don't know where my brain is this morning!