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.
1. ... FIRST
2. ... {NEW}|{END OF} compi
3. ... LAST
The statement block of a LOOP loop can contain control structures for control level processing. The respective 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 to 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 add together 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 internal table is sorted in exactly the same sequence as the component of its line type - that is, first in accordance with the first component, then in accordance with the second component, and so on. The line structure and the corresponding sorting sequence gives 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 listed if an appropriate control break is made in the current table line. 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.
In order that control level processing is carried out properly, the following rules must be observed:
If the INTO addition is used in the LOOP statement to assign the content of the current line to a work area wa, its content is changed upon entry into the AT-ENDAT control structure as follows:
When the AT-ENDAT
control structure is exited, the content of the current table line is assigned to the entire work area wa.
... FIRST
The control level is defined by the first line of the internal table. The control break takes place when this line is read.
In the group level AT FIRST, the current group key contains
no components and all character-type components of the work area wa are filled with "*" and all remaining components are set to their initial value.
... {NEW}|{END OF} compi/>
: Control levels are defined by the beginning or end of a group of lines 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 object attributes is not possible here.
If the INTO or ASSIGNING
additions are used in the LOOP statement, a field symbol
can be entered after AT {NEW}|{END OF} outside classes,
to which the corresponding component of the work area wa
or the field symbol <fs> is assigned. This form
of dynamic component specification is obsolete and has been replaced by specification in the format (name).
... LAST
: The control level is defined by the last line of the internal table. The control break takes place when this line is read.
In the group level AT LAST, the current group key contains
no components and all character-type components of the work area wa are filled with "*" and all remaining components are set to their initial value.
See SUM.
Non-Catchable Exceptions