on 05-14-2008 4:54 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.