Application Development and Automation 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: 
Read only

Looping on ABAP structure's fields

Former Member
9,159

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.

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
Read only

Former Member
0 Likes
3,268

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

Read only

Former Member
3,268

...

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.

Read only

Former Member
0 Likes
3,268

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

Read only

Former Member
0 Likes
3,268

yup...sorry missed out the component bit!

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

Read only

Former Member
0 Likes
3,268

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!