Get Example source ABAP code based on a different SAP table
• IN FOR • • INTO FOR
FOR>, Table Iterations
ABAP_SYNTAX_FORMS
Read Lines of Internal Tables> 1 ... FOR wa$|<(><)> IN itab $[ • INTO idx$] $[ cond>$] $[let_exp>$] ...>
Group Lines of Internal Tables> 2 ... FOR GROUPS $[group$| < group>$] OF wa$|<(><)> IN itab $[ • INTO idx$] $[cond>$] GROUP BY group_key> $[ASCENDING$|DESCENDING $[AS TEXT$]$] $[WITHOUT MEMBERS$] $[let_exp>$] ...>
Read Group Members of Internal Tables> 3 ... FOR ${ wa$|<(><)> IN GROUP group $[ • INTO idx$] $[ WHERE ( log_exp )>$] $} $| ${ GROUPS OF wa$|<(><)> IN GROUP group $[ • INTO idx$] $[ WHERE ( log_exp )>$] GROUP BY group_key> $[ASCENDING$|DESCENDING $[AS TEXT$]$] $[WITHOUT MEMBERS$] $} $[let_exp>$] ...>
What does it do? These syntax forms of an iteration expression> using FOR>> perform table iterations>.
When used in a constructor expression with the reduction operator REDUCE>>, these 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 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 first variant FOR ... IN itab>> works in the same way as the regular line variant LOOP AT itab>> without the addition GROUP BY>.
The second variant FOR GROUPS ... OF>> works in the same way as the variant for grouping lines with the addition GROUP BY>>.
The third variant FOR ... IN GROUP>> works in the same way as the variant LOOP AT GROUP >> for member loops>. The variables or field symbols declared in the FOR> expressions are local here. 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 specified to define local helper fields at the end of each FOR> expression. The system field sy-tabix> is not set by a FOR> expression. The addition • INTO> can be used instead.
Latest notes:
Multiple consecutive 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.
The clearing or replacement of the complete table body of the internal table that is currently processed in a FOR> expression is not allowed. Any attempt leads to the runtime error TABLE_FREE_IN_LOOP >. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Generation of an internal table jtab> from an internal table itab> using a table comprehension>. Generation of a text string str> from the internal table jtab> using a table reduction>. The result in str> is the character string 1, 9, 25>. ABEXA 01039 ABAP_EXAMPLE_END