You are on page 1of 3

Control break statements in sap abap

List of control break statements used in SAP ABAP programming


Control break statements are statements which are used to control the sequence of execution of
statements with in loop.....endloop.
These statements are executed only with in loop...endloop.

Control break statements are


AT FIRST - This statement is executed/triggered for the first iteration of loop (SY-TABIX = 1 ).
AT LAST - This statement is executed/triggered for the last iteration of loop.
AT NEW <field name> - This is executed when ever there is a new value on specified field.
AT END OF <field name> - This statement is executed whenever the new value ends on specific

field.
ON CHANGE OF <field name> - It is same as AT NEW and is obsolete in ECC 6.0.

Report using control break


statements
Using control break statements in ABAP programs to display totals, subtotals
Requirement: Develop a report to display list of sales orders with totals and page sub-totals
for a particular date.
Selection-screen : input date.
SUM : SUM is a key word which is used to add numerical values of a field in control break
statements.
REPORT ZSAPN_CONTROL_BREAK.
TYPES : BEGIN OF TY_VBAP,
VBELN TYPE VBAP-VBELN,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
NETPR TYPE VBAP-NETPR,
END OF TY_VBAP.
DATA : IT_VBAP TYPE TABLE OF TY_VBAP.
DATA : WA_VBAP TYPE TY_VBAP.
PARAMETERS : P_DATE TYPE VBAP-ERDAT .

START-OF-SELECTION.
SELECT VBELN MATNR ZMENG NETPR
FROM VBAP INTO TABLE IT_VBAP
WHERE ERDAT = P_DATE.

LOOP AT IT_VBAP INTO WA_VBAP.

AT FIRST .
WRITE :/2 'SALES DOC', 18 'MATRIAL', 28'QUANTITY', 40 'PRICE'.
ENDAT.

AT NEW VBELN.
WRITE :/2 WA_VBAP-VBELN, 18 WA_VBAP-MATNR, 28 WA_VBAP-ZMENG, 40 WA_VBAPNETPR.
ENDAT.

AT END OF VBELN.
SUM.
WRITE :/23 'SUB TOTAL IS :' COLOR 6, WA_VBAP-NETPR.
ENDAT.

AT LAST.
SUM.
WRITE:/23 'Total is:', WA_VBAP-NETPR .
ENDAT.

ENDLOOP.

You might also like