ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Internal Tables → Processing Statements for Internal Tables → LOOP AT itab → LOOP AT itab - Basic Form
LOOP AT itab - result
Other versions: 7.31 | 7.40 | 7.54
Syntax
... { INTO wa }
| { ASSIGNING <fs> [CASTING] }
| { REFERENCE INTO dref }
| { TRANSPORTING NO FIELDS } ...
Effect
Defines the output behavior of a LOOP
across an internal table. There are four alternatives for the output behavior:
-
The addition
INTO
is used to assign the content of the current row to a work areawa
. -
The addition
ASSIGNING
is used to assign the current row to a field symbol<fs>
. No other memory area can be assigned to the field symbol within the loop and the assignment cannot be undone usingUNASSIGN
. -
The addition
REFERENCE INTO
is used to create a reference to the current row in a reference table. No other reference can be assigned to the reference variable within the loop and the reference variable cannot be initialized usingCLEAR
. -
The addition
TRANSPORTING NO FIELDS
specifies that only the relevant system fields are filled. This addition is only possible if the additionWHERE
is used in the conditionscond
at the same time and if the additionGROUP BY
is not used.
If the internal table itab
is specified as an existing data object, the syntax and meaning of the specified
output behavior is the same as in the statement
READ TABLE
(with the exception
that no further transport_options
can be specified after INTO wa
) and the same restrictions apply to modifications to key fields of the
primary and
secondary table keys.
In particular, inline declarations for the work area, the field symbol, or the reference variable using
the declaration operators DATA
and FIELD-SYMBOL
are possible.
If a field symbol or a dereferenced reference variable is specified for the work area wa
or the reference variable dref
, the target data object of the field symbol
or reference variable is determined in each loop pass. The current data object is used as the target
area for each loop pass. This means that changes in the assignment of the field symbol or reference variable within the loop modifies the target area.
If the internal table is specified as the return value of a
functional method, a
constructor expression, or a
table expression,
the additions ASSIGNING
and REFERENCE INTO
can
also be specified for LOOP
(this is not the case with READ
TABLE). The internal table is only available while the loop is being processed, which means that
all field symbols and reference variables that point to rows in the internal table become invalid when the loop is exited.
Notes
-
For
LOOP
, an obsolete short form exists (outside of classes) whereINTO wa
can be omitted if the internal table has a header lineitab
with the same name.INTO itab
is then added to the statement. -
If the current row is deleted within the loop when the additions
ASSIGNING
orREFERENCE
are used, the field symbol or reference variable are then unassigned or unbound in the current loop pass.