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: 

Looping on ABAP structure's fields

Former Member

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.

5 REPLIES 5

Former Member
0 Kudos

Is the structure you want to loop on defined in the dictionary...or just in the program?

Former Member

...

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.

Former Member
0 Kudos

the statement you are looking for is "Assign component of structure"

Former Member
0 Kudos

yup...sorry missed out the component bit!

assign component (lst_dd07l-fieldname) of structure <your structure> to <lfs_field>.

Former Member
0 Kudos

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!