sapdev logo background
sapdev logo sapdev logo
Comments

ABAP AT ITAB Statement syntax, information and example SAP source code



Return to Statement index



AT - itab

Short Reference

ABAP 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.

ABAP_ADDITIONS:
1 ... FIRST
2 ... {NEW}|{END OF} compi
3 ... LAST

What does it do? 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 in cond 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 the LOOP statement after the addition INTO must be compatible with the row type of the table.

A field symbol fs specified in the statement LOOP
after the addition ASSIGNING must be typed with the row type of the table.

The content of a work area wa specified in the statement
LOOP after the addition INTO 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 .
Latest notes: 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.
If INTO is used, note that "
character-like " has a different definition in Unicode programs and non-Unicode programs, which means that identical structures can produce different results.

Example ABAP Coding See Control Level Processing
.

ABAP_ADDITION_1 ... FIRST

What does it do? The control level is defined by the first row of the internal table. The control break takes place when this row is read.

Latest notes: 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.

ABAP_ADDITION_2 ... {NEW}|{END OF} compi

What does it do? 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.

Latest notes: An obsolete variant allows field symbols to also be specified, outside of classes compi .

ABAP_ADDITION_3 ... LAST

What does it do? The control level is defined by the last row of the internal table. The control break takes place when this row is read.

Latest notes: 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.



Runtime Exceptions
Non-catchable Exceptions

Reason for error: Invalid subfield access with when the control break criterion is specified dynamically.
Runtime error: AT_BAD_PARTIAL_FIELD_ACCESS
Reason for error: 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
Reason for error: 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
Reason for error: Overflow of totals with SUM .
Runtime error: SUM_OVERFLOW
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




AT_GROUP_LEVEL
AT_ITAB_OBSOLETE




comments powered by Disqus