ABAP: LOOP AT for a dynamic table

Whenever you work with a dynamic and want to read more than 1 record, you should use a LOOP AT Statement. But since the table is dynamic, you can't use the static field names. Luckily there is way to adress the fields dynamicly.

FIELD-SYMBOLS: <ft_proxy>   TYPE ANY TABLE,
                <fs_proxy>  TYPE any.

DATA(lv_loop_where) = |MATNR = '{ <fs_predata>-matnr }' AND PBDNR = '{ <fs_predata>-pbdnr }'|.
LOOP AT <ft_proxy> ASSIGNING <fs_proxy> WHERE (lv_loop_where).
    "Work with <fs_proxy>
ENDLOOP.
1
2
3
4
5
6
7

In this example we have the data with which we want to read in the field symbol <fs_predata>. What makes this work is the fact, that a strign surrounded by brackets is dynamicly transformed. Thanks to the string templates, we can build the where clause easily and readable in one line. Since <fs_proxy> is dynamic as well, you'll most likely want to work with ASSIGN COMPONENT to access the fields.