CONTROL BREAK EVENTS

Control break statement / events in internal table: -

Control break statements are work with in the loop at internal table. Before using the control break statements. We must sort the internal table based on At new field.

Control break statements are
1> At First
2> At New <field name>
3> At End of <field name>
4> At last

Each control break statement ends with Endat.

AT FIRST: -
This is an event which is triggered at the first record of internal table.
Advantage: - This is used to display the header information for internal table.

AT NEW <field name>: -
It’s an event which is triggered at the first record of each block.
Advantage: - It’s used to display the individual fields.

AT END OF <field name>: -
This event triggered at the last record of each block.

Advantage: -This is used to display the sub total.

AT LAST: -
This is an event which is triggered at the last record of internal table.
Advantage: - It’s used to display the grand total.


PROGRAM:

*&---------------------------------------------------------------------*
*& Report  ZR_CONTROL_BREAK_EVENTS
*&
*&---------------------------------------------------------------------*

REPORT ZR_CONTROL_BREAK_EVENTS.
DATA LV_VBELN TYPE VBAK-VBELN.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
  
SELECT-OPTIONS SO_VBELN FOR LV_VBELN.
  
SELECTION-SCREEN END OF BLOCK B1.

TYPES : BEGIN OF TY_VBAP,
        VBELN 
TYPE VBAP-VBELN,
        POSNR 
TYPE VBAP-POSNR,
        KWMENG 
TYPE VBAP-KWMENG,
        MEINS 
TYPE VBAP-MEINS,
        NETWR 
TYPE VBAP-NETWR,
        
END OF TY_VBAP.
DATA : V1 TYPE VBAP-NETWR,
       V2 
TYPE VBAP-NETWR.
DATA : WA_VBAP TYPE TY_VBAP,
       IT_VBAP 
TYPE TABLE OF TY_VBAP.

SELECT VBELN
       POSNR
       KWMENG
       MEINS
       NETWR
       
FROM VBAP
       
INTO TABLE IT_VBAP
       
WHERE VBELN IN SO_VBELN.
SORT IT_VBAP BY VBELN.

LOOP AT IT_VBAP INTO WA_VBAP.
  
AT FIRST.
    
WRITE : 'These are sales order deatails'.
    
ENDAT.
  
AT NEW VBELN.
    
WRITE :/ WA_VBAP-VBELN COLOR 6.

    
ENDAT.

    
WRITE :/
             WA_VBAP
-POSNR COLOR 5,
             WA_VBAP
-KWMENG COLOR 4,
             WA_VBAP
-MEINS COLOR 3,
             WA_VBAP
-NETWR COLOR 7.


    V1 
V1 + WA_VBAP-NETWR.
    V2 
V2 + WA_VBAP-NETWR.
  
AT END OF VBELN.
    
WRITE :/ 'SUB TOTAL'33 V1 COLOR 1.
    
CLEAR V1.
  
ENDAT.

  
AT LAST.
    
WRITE'GRAND TOTAL'33 V2 COLOR 2.
    
ENDAT.
ENDLOOP.


OUTPUT :