Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Expressions and Functions for Internal Tables 

FOR - Table Iterations

Other versions: 7.31 | 7.40 | 7.54

Syntax Forms


Read rows of internal tables

1. ... FOR wa|<fs> IN itab [INDEX INTO idx] [cond] [let_exp]  ...

Group rows of internal tables

2. ... FOR GROUPS [group|<group>] OF wa|<fs> IN itab
          [INDEX INTO idx] [cond]
          GROUP BY group_key
          [ASCENDING|DESCENDING [AS TEXT]]
          [WITHOUT MEMBERS]
          [let_exp] ...


Read group members of internal tables

3. ... FOR { wa|<fs> IN GROUP group [INDEX INTO idx] [WHERE ( log_exp )] }
        | { GROUPS OF
            wa|<fs> IN GROUP group [INDEX INTO idx] [WHERE ( log_exp )]
            GROUP BY group_key
            [ASCENDING|DESCENDING [AS TEXT]]
            [WITHOUT MEMBERS] } [let_exp] ...

Effect

These syntax forms of an iteration expression using FOR perform table iterations.

  • When used in a constructor expression with the reduction operator REDUCE, these forms are known as table reductions.
  • When used in a constructor expression with the instance operator NEW or with the value operator VALUE for internal tables, these forms are known as table comprehensions.

A FOR expression like this evaluates the content of an internal table and its result can be used to construct the result of the wrapper constructor expression. The three variants of a FOR expression for internal tables work in the same way as the following variants of the statement LOOP AT itab:

The variables or field symbols declared in the FOR expressions are local in these expressions. The local data from all outer FOR expressions can be used when their values are defined. As an option, LET expressions let_exp can be used to define local auxiliary fields at the end of each FOR expression.

The system field sy-tabix is not set by a FOR expression. The addition INDEX INTO can be used instead.


Note

Multiple sequential FOR expressions with different variants (including the conditional iteration) can be specified in a constructor expression. These expressions then work in the same way as nested loops.

Continue

FOR ... IN itab

FOR GROUPS ... OF

FOR ... IN GROUP

FOR - cond

Examples of Table Reductions

Examples of Table Comprehensions

Examples of Grouping with FOR