cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a loop for more no of rows and columns in a table

Former Member
0 Kudos

if we have a table with many no of colums and rows.how to to write loop for a table? help can b appreciated.thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member589029
Active Contributor
0 Kudos

Assumed your table is of type ty_something, then your coding would look something like this:


DATA lt_table type table of ty_something.
FIELD-SYMBOLS: <fs_wa> type ty_something.

* code to fill your table with data

LOOP AT lt_table ASSIGNING <fs_wa>.

ENDLOOP.

In the loop you have the fields of the current row available in the field-symbol

<fs_wa>-field1

<fs_wa>-field2

etc.

In case you do not want to loop at all the data in the table you can add conditions:


LOOP AT lt_table ASSIGNING <fs_wa>
     WHERE fieldx EQ 'some_value'
     AND fieldy IN lr_range.          

ENDLOOP.

Hope that helps,

Michael

Former Member
0 Kudos

Just complementing...

If you need to insert or update some data inside your loop statement, it is better using a work area instead of the field-symbol:


DATA: wa_table type ty_table_type

or


DATA: wa_table type line of gt_itable.

Loop example:


LOOP AT gt_itable INTO wa_table.
   IF gt_itable-field = 'X'.
      APPEND wa_table TO gt_itable_2.
   ENDIF.
ENDLOOP.

Regards.