19 Flares Twitter 0 Facebook 19 Google+ 0 LinkedIn 0 Email -- Pin It Share 0 19 Flares ×

Control break events are used to control the sequence data flow inside the loops in ABAP.

List of control break events in ABAP:

1)      AT  FIRST

2)      AT NEW

3)      AT END OF

4)      AT LAST

5)      SUM

6)      ON CHANGE OF

Note: AT-FIRST, AT-NEW,AT-END-OF,AT-LAST this events works only in between LOOP——ENDLOOP, We are also calling it as LOOP EVENTS

AT FIRST

It is the loop event, it triggers at first run of the loop.

Using this event we can display the page header.

SYNTAX:

AT FIRST ——————-  END AT.

AT NEW

It is the loop event. Whenever the new field value is occurred then AT NEW event will trigger.

The trigger point will be at the first occurrence of the new value for the field.

SYNTAX

AT NEW ——————— END AT.

AT END OF

It is the loop event. It triggers at end of every field value.

Using this event we can calculate the subtotals.

 SYNTAX

AT  END OFS ——————— END AT.

AT LAST

It is the loop event. It triggers in the last loop operation

Using this event we can find calculate the grand totals.

 SYNTAX

AT LAST ——————— END AT.

SUM

Sum is the keyword to find the totals.

ON CHANG OF

On change of it triggers only when there is any change in the particular field, we can use  ON CHANGE OF loop and outside the Loop also.

We can use Logical expressions like AND OR can be used with ON CHANGE OF

SYNTAX

ON CHANGE OF ——————— END OF.

 

EXAMPLE PROGRAM:

*&———————————————————————*
*& Report  ZCEVENTS
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT  ZCEVENTS NO STANDARD PAGE HEADING.
*// Tables declaration.
TABLES marc.

*//Types declaration for ty_marc.
TYPES : BEGIN OF ty_marc,
matnr TYPE matnr,
werks TYPE  werks_d,
pstat  TYPE pstat_d,
lvorm  TYPE lvowk,
plifz   TYPE plifz,
END OF ty_marc.

*//Types declaration for ty_marc1.
TYPES : BEGIN OF ty_marc1,
werks TYPE werks_d,
pstat TYPE pstat_d,
lvorm TYPE lvowk,
plifz TYPE plifz,
matnr TYPE matnr,
END OF ty_marc1.

*//Internal table declaration.
DATA : lt_marc TYPE TABLE OF ty_marc,
lt_marc1 TYPE TABLE OF ty_marc1.

*//Workarea declaration.
DATA : wa_marc TYPE ty_marc,
wa_marc1 TYPE ty_marc1.

*//selection screen design.
SELECT-OPTIONS : s_matnr FOR marc-matnr.

*//Retrive the data from mara.
SELECT matnr werks pstat lvorm plifz
FROM marc
INTO TABLE lt_marc
WHERE matnr IN s_matnr.

IF sy-subrc EQ 0.
*//populating data into final internal table.
LOOP AT lt_marc INTO wa_marc.
*****    wa_marc1-matnr = wa_marc-matnr.
*****    wa_marc1-werks = wa_marc-werks.
*****    wa_marc1-pstat = wa_marc-pstat.
*****    wa_marc1-lvorm = wa_marc-lvorm.
*****    wa_marc1-plifz = wa_marc-plifz.
MOVE-CORRESPONDING wa_marc TO wa_marc1.
APPEND wa_marc1 TO lt_marc1.
CLEAR wa_marc1.

ENDLOOP.
ENDIF.

*// sort by specific field
SORT lt_marc1 BY pstat.

*******//Display output.
******LOOP AT lt_marc1 INTO wa_marc1.
******  WRITE : / wa_marc1-matnr,wa_marc1-werks,wa_marc1-pstat,wa_marc1-lvorm,wa_marc1-plifz.
******ENDLOOP.

*//Apply the control break events.

LOOP AT lt_marc1 INTO wa_marc1.
*//AT FIRST.
AT FIRST.
WRITE : / ‘PLANT DATA’.
ULINE.
SKIP 2.
ENDAT.

******//AT NEW.
*****  AT NEW pstat.
*****    WRITE : /  ‘MAINTENANCE STATUS:  ‘ ,wa_marc1-pstat.
*****
*****  ENDAT.
*****  WRITE : /,/ wa_marc1-matnr,wa_marc1-werks,wa_marc1-pstat,wa_marc1-lvorm,wa_marc1-plifz  .

*//ON CHANGE OF.
ON CHANGE OF wa_marc1-pstat.
write : /,/ ‘MAINTENANCE STATUS :’,wa_marc1-pstat.
endon.
write : / wa_marc1-matnr,wa_marc1-werks,wa_marc1-pstat,wa_marc1-lvorm,wa_marc1-plifz.

*//AT END OF.
AT END OF pstat.
sum .
write : /30 ‘subtotal’, wa_marc1-plifz.
ENDAT.

*//AT LAST.
AT LAST.
SUM.
WRITE : /30 ‘GRAND TOTAL’,wa_marc1-plifz.
ENDAT.
ENDLOOP.

Output:

Control Break Event in ABAP

 

Click on Execute.

 

Control Break Event in ABAP1Enjoy 🙂

Also Read:

Also Read:

Creating Pushbuttons on Selection Screen.

Display a Column As a Pushbutton in the ALV Report Output.

How to Create Transaction Code for Table Maintenance Generator in SAP.

 

19 Flares Twitter 0 Facebook 19 Google+ 0 LinkedIn 0 Email -- Pin It Share 0 19 Flares ×