Control Break Processing in ABAP Internal Tables
Control Break Processing in ABAP Internal Tables
Internal Tables
Control break processing is used to execute a piece of code whenever a specific
condition in the data is detected during the processing of internal table loop.
The following control break statements are available with in LOOP and
ENDLOOP.
AT FIRST / ENDAT
AT LAST / ENDAT
AT NEW / ENDAT
AT END OF / ENDAT
SUM
ON CHANGE OF / ENDON
The code between AT NEW and ENDAT is executed only during the first loop
pass. So it is used to write the headers or some other initialization processing.
The code between AT LAST and ENDAT is executed only during the last loop
pass. So it is used to write the totals or some report footers.
AT FIRST.
ENDAT.
WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid,
29 gwa_spfli-cityfrom,44 gwa_spfli-cityto.
AT LAST.
ULINE.
WRITE:/ 'End of Loop'.
ENDAT.
ENDLOOP.
Output
Between AT FIRST and ENDAT the work area will not contain any data. The
default key fields are filled with asterisks(*) and the numeric fields are filled with
zeros. The ENDAT restores the contents to the values they had prior to entering
the AT FIRST. Changes to the work area within AT FIRST and ENDAT are lost.
The same applies for AT LAST and ENDAT.
ULINE.
ENDAT.
WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid,
29 gwa_spfli-cityfrom,44 gwa_spfli-cityto,
58 gwa_spfli-distance.
AT LAST.
ULINE.
Output
AT NEW and ENDAT is used to detect a change in the value of the field between
the loop passes. The field that is specified in AT NEW is called control level. The
code between AT NEW and ENDAT will be executed during the first loop pass
and every time the value of the control level changes or any other field left to the
control level changes. Between AT NEW and ENDAT all the fields in the work
area that are right to the control level are filled with zeros and asterisks.
Similarly The code between AT END OF and ENDAT will be executed during the
last loop pass and every time the value of the control level changes or any other
field left to the control level changes.
WRITE:/14 gwa_spfli-connid,
29 gwa_spfli-cityfrom,44 gwa_spfli-cityto,
58 gwa_spfli-distance.
AT LAST.
WRITE:/ 'End of Loop'.
ENDAT.
ENDLOOP.
Output