SAP FOR IN ITAB



Get Example source ABAP code based on a different SAP table
  



FOR ... IN itab

ABAP_SYNTAX
... FOR wa$|<(><)> IN itab $[ • INTO idx$] $[ cond$] $[let_exp$] ...

ABAP Addition
... • INTO idx

What does it do?
This variant of an iteration expression for table iterations using FOR evaluates an internal table itab sequentially, like a line variant of a LOOP. itab is a functional operand position. As in LOOP, the order of the lines read depends on the table category or a key specified in cond.
cond1 can be used to set conditions for the evaluation. For each read line, the result is either assigned to a local work area wa1 or to a field symbol <(><)>. The work area or the field symbol is declared implicitly with the line type of the internal table and bound locally to the FOR expression as a subexpression of the entire constructor expression. The same applies to the namespace and visibility as to the helper fields declared in LET expressions. After the FOR expression, the work area or the field symbol can either be used in further subexpressions or to construct the result of a table comprehension or table reduction.



Latest notes:

Instead of using directly specified internal tables itab, this variant of FOR expressions can also be created using mesh paths, where FOR expressions from both categories can be used together in the same constructor expression.
Changes to the content of the internal table specified after IN within the FOR expression can only be made using method calls. Deleting or replacing the table completely always produces a runtime error.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Construction of an internal table flights in a table iteration with FOR with the value operator VALUE ( table comprehension). The lines of the internal table are merged from the content of two existing internal tables scarr_tab and spfli_tab.
ABEXA 01037
ABAP_EXAMPLE_END

ABAP_EXAMPLES_ABEXA
Examples of Table Comprehensions
Examples of Table Reductions
ABAP_EXAMPLE_END

ABAP Addition

What does it do?
For each read line of the associated FOR expression, this addition sets the helper variable idx to the value to which the system field sy-tabix would be set in a corresponding LOOP. The helper variable idx is declared implicitly with the type i and bound locally to the FOR expression as a subexpression of the entire constructor expression. The same applies to the namespace and visibility as to the helper fields declared in LET expressions.

ABAP_EXAMPLE_VX5
Construction of an internal table carriers from an existing internal table scarr_tab. The first column is provided with the line index of the existing table.
ABEXA 01038
ABAP_EXAMPLE_END