0% found this document useful (0 votes)
611 views3 pages

Control Break Statements SAP ABAP

Control break statements in ABAP allow code to be executed when certain conditions are met within a loop. There are 5 control break statements: AT FIRST, AT LAST, AT END OF, AT NEW, and ON CHANGE OF. AT FIRST executes at the start of the loop, AT LAST at the end. AT END OF and AT NEW execute when the specified field changes, with AT END OF at the last occurrence and AT NEW at the first occurrence. ON CHANGE OF executes whenever the specified field changes. An example program demonstrates the usage of each control break statement on sample table data.

Uploaded by

shravanz252
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
611 views3 pages

Control Break Statements SAP ABAP

Control break statements in ABAP allow code to be executed when certain conditions are met within a loop. There are 5 control break statements: AT FIRST, AT LAST, AT END OF, AT NEW, and ON CHANGE OF. AT FIRST executes at the start of the loop, AT LAST at the end. AT END OF and AT NEW execute when the specified field changes, with AT END OF at the last occurrence and AT NEW at the first occurrence. ON CHANGE OF executes whenever the specified field changes. An example program demonstrates the usage of each control break statement on sample table data.

Uploaded by

shravanz252
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

9/20/13

New To SAP: Control Break Statements in SAP ABAP

newtosap.info

http://www.newtosap.info/2012/07/control-break-statements-in-sap-abap.html

Control Break Statements in SAP ABAP


Control break statements are like events inside the loop. There are 5 control break statements in ABAP. These are used within loop.(Except ON CHANGE OF which can be used outside the loop as well) AT FIRST - ENDAT AT NEW - ENDAT AT END OF - ENDAT AT LAST - ENDAT ON CHANGE OF

Explanation:

AT FIRST : Will trigger at the first run of the loop. AT LAST: Will trigger at the last run of the loop. The below 3 events are normally used when the table is sorted.

AT END OF : When we use At end for a field, it will trigger whenever there is any change in any of the fields from the left to that of the particular field. The trigger point will be the at the last occurrence of the same value for the field. AT NEW: When we use At new for a field, it will trigger whenever there is any change in any of the fields from the left to that of the particular field.The trigger point will be the at the first occurrence of the new value for the field. ON CHANGE OF : On change of it triggers only when there is any change in the particular field. On change of can be used outside the loop too

Example Program:

Here is an example program which gives you the practical understanding of all control break statements.

NOTE: It is important to note that we need a temporary work-area apart from the workarea used in loop for the last 3 control break statements. If we directly use the work-area of the loop, then we will get **** value and not the output we are expecting.
www.newtosap.info/2012/07/control-break-statements-in-sap-abap.html 1/3

9/20/13

New To SAP: Control Break Statements in SAP ABAP

*&---------------------------------------------------------------------* *& Report ZAU_CONTROLBREAK *& *&---------------------------------------------------------------------* *& NEW TO SAP CONTROL BREAK EXAMPLE *& http://www.newtosap.info *& *&---------------------------------------------------------------------* REPORT zau_controlbreak. TYPES: BEGIN OF ty_marc, matnr TYPE marc-matnr, werks TYPE marc-werks, END OF ty_marc. DATA: it_marc TYPE STANDARD TABLE OF ty_marc, wa_marc TYPE ty_marc, wa_temp TYPE ty_marc.

Example Program for Control Break Statements

SELECT matnr werks FROM marc INTO TABLE it_marc UP TO 10 ROWS WHERE matnr ge 40. SORT it_marc BY matnr. FIELD-SYMBOLS : <matnr> type matnr. WRITE:/ 'FULL TABLE'. LOOP AT it_marc INTO wa_marc. wa_temp = wa_marc. WRITE: / sy-tabix , wa_temp-matnr, wa_temp-werks. ENDLOOP. WRITE:/ 'AT FIRST AND LAST'. LOOP AT it_marc INTO wa_marc. wa_temp = wa_marc. AT FIRST. WRITE:/ 'First Entry'. WRITE:/ wa_temp-matnr, wa_temp-werks. ENDAT. AT LAST. WRITE:/ 'Last Entry'.
www.newtosap.info/2012/07/control-break-statements-in-sap-abap.html 2/3

9/20/13

New To SAP: Control Break Statements in SAP ABAP

WRITE:/ wa_temp-matnr, wa_temp-werks. ENDAT. ENDLOOP.

WRITE:/ 'AT END OF'. LOOP AT it_marc INTO wa_marc. wa_temp = wa_marc. AT END OF matnr. WRITE: / sy-tabix , wa_temp-matnr, wa_temp-werks. ENDAT. ENDLOOP. WRITE:/ 'AT NEW'. LOOP AT it_marc INTO wa_marc. wa_temp = wa_marc. AT NEW matnr. WRITE: / sy-tabix , wa_temp-matnr, wa_temp-werks. ENDAT. ENDLOOP. WRITE:/ 'ON CHANGE OF'. LOOP AT it_marc INTO wa_marc. wa_temp = wa_marc. ASSIGN wa_marc-matnr TO <matnr>. ON CHANGE OF wa_marc-matnr. WRITE: / sy-tabix ,wa_temp-matnr, wa_temp-werks. ENDON. ENDLOOP.

www.newtosap.info/2012/07/control-break-statements-in-sap-abap.html

3/3

You might also like