ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Internal Tables → Processing Statements for Internal Tables
AT - itab
Other versions: 7.31 | 7.40 | 7.54
Syntax
LOOP AT itab result ...
[AT FIRST.
...
ENDAT.]
[AT NEW comp1.
...
ENDAT.
[AT NEW comp2.
...
ENDAT.
[...]]]
[ ... ]
[[[...]
AT END OF comp2.
...
ENDAT.]
AT END OF comp1.
...
ENDAT.]
[AT LAST.
...
ENDAT.]
ENDLOOP.
Extras
1. ... FIRST
2. ... {NEW}|{END OF} compi
3. ... LAST
Effect
The statement block of a LOOP
loop can contain control structures for
control level processing.
The corresponding control statement is AT
. The statements AT
and ENDAT
define statement blocks that are executed at
control breaks, that
is, when the control structure is changed. The additions of the AT
statements
determine the control break at which their statement blocks are executed. Within these statement blocks,
the statement SUM
can be specified
to total the numeric components of a control level. For the output behavior result
,
the same applies as for LOOP AT
.
The prerequisite for control level processing is that the processing sequence in which the LOOP
loop reads the rows of the internal table is sorted in the exact order of the components of its row
type, that is, firstly in accordance with the first component, then in accordance with the second component,
and so on. The row structure and the corresponding sorting sequence creates a group structure of the
content of the internal table, whose levels can be evaluated using AT
statements.
The AT
-ENDAT
control structures must be aligned one after the other, in accordance with the group structure.
The statement blocks within the AT
-ENDAT
control
structures are executed if an appropriate control break is made in the current table row. Statements
in the LOOP
-ENDLOOP
control structure that are
not executed within an AT
-ENDAT
control structure are executed in each pass of the loop.
To ensure that control level processing is carried out properly, the following rules must be observed:
-
A table key specified for
LOOP
in cond must be chosen so that it produces the required sort order of the imported rows. -
A restricting condition specified for
LOOP
incond
must select a contiguous block of rows from the internal table. Otherwise the behavior of the control level processing is undefined. -
The internal table cannot be modified within the
LOOP
loop. -
A work area
wa
specified in theLOOP
statement after the additionINTO
must be compatible with the row type of the table. -
A field symbol
<fs>
specified in the statementLOOP
after the additionASSIGNING
must be typed with the row type of the table. -
The content of a work area
wa
specified in the statementLOOP
after the additionINTO
cannot be modified.
If the addition INTO
is used in the statement LOOP
to assign the content of the current row to a work area wa
, its content is
modified as follows when the AT
-ENDAT
control structure is entered:
- The components of the current control key remain unchanged.
- All components with a character-like flat data type to the right of the current control key are set to character "*" in every position.
-
All the other components to the right of the current control key are set to their initial value.
When the AT
-ENDAT
control structure is exited, the content of the current table row is assigned to the entire work area wa
.
Note
When the additions ASSIGNING
and REFERENCE INTO
are used, the referenced table rows are not modified when entering and exiting the AT
-ENDAT
control structure.
Addition 1
... FIRST
Effect
The control level is defined by the first row of the internal table. The control break takes place when this row is read.
Note
In the group level AT FIRST
, the current group key contains no components
and all character-like components of the work area wa
are filled with "*" and all remaining components are set to their initial value.
Addition 2
... {NEW}|{END OF} compi
Effect
Control levels are defined by the beginning or end of a group of rows with the same content in the component
compi
(where i
= 1
,
2
, and so on) and in the components to the left of compi
.
The control breaks take place when the content of the component compi
or another component to the left of compi
changes.
The compi
components can be specified as described in
Specification of Components, with the limitation that access to data objects using references is not possible here. The following is therefore not possible:
- Specifying data objects using data references
-
Specifying attributes of objects using object references
Otherwise, the specified components can have any data type. The relevant comparison rules apply to the evaluation.
Addition 3
... LAST
Effect
The control level is defined by the last row of the internal table. The control break takes place when this row is read.
Note
In the group level AT LAST
, the current group key contains no components
and all character-like components of the work area wa
are filled with "*" and all remaining components are set to their initial value.
Exceptions
Non-Catchable Exceptions
-
Cause: Invalid subfield access with dynamic specification of the control break criterion.
Runtime Error:AT_BAD_PARTIAL_FIELD_ACCESS
-
Cause: The control break criterion is specified dynamically using the field symbol and the field symbol does not point to the
LOOP
output area.
Runtime Error:AT_ITAB_FIELD_INVALID
-
Cause: The control break criterion is specified dynamically using
(name) and the
name
field does not contain a valid subfield label.
Runtime Error:ITAB_ILLEGAL_COMPONENT
-
Cause: Overflow of totals with
SUM
.
Runtime Error:SUM_OVERFLOW