Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables 

LOOP AT itab

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax Forms


Loop across table rows

1. LOOP AT itab result [cond].
    ...
  ENDLOOP.

Loop across row groups

2. LOOP AT itab result [ cond] GROUP BY group_key
                             [ASCENDING|DESCENDING [AS TEXT]]
                             [WITHOUT MEMBERS]
                             [group_result].
    ...
  ENDLOOP.

Effect

Executes a table iteration as a loop across an internal table itab. itab is a functional operand position.

The statements LOOP and ENDLOOP define the statement block of the loop. The statement LOOP reads rows from the internal table itab sequentially that meet an optional condition cond.

  • If the addition GROUP BY is not specified, the statement block is executed for each read row and the row can be processed here. The way in which the read row is addressed in the statement block is specified in the output behavior result.
  • The addition GROUP BY is used to group the read rows by a group key group_key and the statement block is then executed for every group. The way in which the current group is addressed in the statement block is specified in the output behavior group_result.

To exit processing of the statement block, the statements described in the leave loops section can be used.


Note

Internal tables can also be specified as a data source of a query in ABAP SQL.


Example

Simple LOOP over an internal table.

DATA itab TYPE TABLE OF i WITH EMPTY KEY. 
itab = VALUE #( FOR i = 1 UNTIL i > 10 ( i ) ). 

DATA(str) = ``. 
LOOP AT itab ASSIGNING FIELD-SYMBOL(<fs>). 
  str = str && CONV string( <fs> ) && ` `. 
ENDLOOP. 
cl_demo_output=>display( str ).

Continue

LOOP AT itab - Basic Form

LOOP AT itab - GROUP BY

ENDLOOP