CONTROL BREAK STATEMENTS IN SAP ABAP | 4 Types of Control Break Statements & Examples

Control break statements in sap abap | control break statements in sap abap 7.4 | at new control break statement in sap abap | control break statements example in sap abap |

Control Break Statements in SAP ABAP
Control Break Statements in SAP ABAP

Control Break Statements in SAP ABAP are used within AT and ENDAT, Control Break statements is used to control Loop in ABAP Programming. Control Break Statements event execute within loop, control break statement can also be treated as control break event. There is a ground rule to use control break statement they will be working within Loop.

Control Break Statement is different from Control statement, the BREAK, EXIT, CONTINUE are used to break and come out of the current loop where it occurs, where as AT NEW, AT END,AT LAST, AT FIRST is used to check for a table field value (internal table). When u asked for control statements alone, you need to answer as BREAK, EXIT, CONTINUE, CHECK because it controls the program flow.

Types of Control Break Statements :

There are 4 different control break statements in SAP ABAP which we will discuss below one by one.

AT FIRST: – At First event or control break statement trigger only for first record of internal table in loop, For Example we want to perform the action only when first record trigger and the rest of the record we don’t want to perform that action so we will use At First event or control break statements in SAP ABAP.

Syntax :

Loop at it_final into wa_final.
AT FIRST.
Statement1.
Statement2.
Statement3.
ENDAT.
Endloop.

AT LAST:- At Last event or control break statement trigger only for last record of internal table in Loop, For example we want to perform the action only when last record trigger and the rest of the record we don’t want to perform that action so we will use At last event or control break statements in SAP ABAP.

Syntax :

Loop at it_final into wa_final.
AT LAST.
Statement1.
Statement2.
Statement3.
ENDAT.
Endloop.

AT NEW:- At new event or control break statement trigger only when new record or field trigger which we mention with event in loop, For example we want to display record only when new repeated matnr trigger in loop so we will use At new event or control break statements in SAP ABAP.

Syntax :

Loop at it_final into wa_final.
AT NEW field.
Statement1.
Statement2.
Statement3.
ENDAT.
Endloop.

AT END OF:- At end of event or control break statement trigger only when end record or field trigger which we mention with event in loop, For example we want to display record only when last repeated matnr trigger in loop so we will use At end of event or control break statements in SAP ABAP.

Syntax :

Loop at it_final into wa_final.
AT END OF field.
Statement1.
Statement2.
Statement3.
ENDAT.
Endloop.

ON CHANGE OF:- There is other control break statement available in SAP which is absolute, this control break statement is also used within loop like others statement.

Syntax :

Loop at it_final into wa_final.
On Change Of field.
Statement1.
Statement2.
Statement3.
ENDON.
Endloop.

Examples : Control Break Statements in SAP ABAP

Here is the example of control statement program with output screen, please check.

REPORT ZPS_CONTROL_STATEMENT.


SELECT MATNR, ERSDA FROM MARA UP TO 10 ROWS INTO TABLE @DATA(IT_MARA).
****** Without Control Statement*******************
WRITE:/ ‘Material Number’, 20 ‘Created On’.
ULINE.
LOOP AT IT_MARA INTO DATA(WA_MARA).

  WRITE:/ WA_MARA-MATNR, WA_MARA-ERSDA.
  CLEAR WA_MARA.
ENDLOOP.

******** With AT First Control Statement*************

WRITE:/ ‘Material Number’, 20 ‘Created On’.
ULINE.
LOOP AT IT_MARA INTO WA_MARA.
  WRITE:/ WA_MARA-MATNR, WA_MARA-ERSDA.
  AT FIRST.
    WRITE :/’AT First record’.
  ENDAT.
  CLEAR WA_MARA.

ENDLOOP.

*********** With AT Last Control Statement***********

WRITE:/ ‘Material Number’, 20 ‘Created By’.
ULINE.
LOOP AT IT_MARA INTO WA_MARA.
  WRITE:/ WA_MARA-MATNR, WA_MARA-ERSDA.
  AT LAST.
    WRITE :/’AT Last record’.
  ENDAT.
  CLEAR WA_MARA.

ENDLOOP.

*********** With At New Control Satement**********

WRITE:/ ‘Material Number’, 20 ‘Created on’.
ULINE.
LOOP AT IT_MARA INTO WA_MARA.

  CONCATENATE WA_MARA-ERSDA+6(2) WA_MARA-ERSDA+4(2) WA_MARA-ERSDA+0(4) INTO DATA(LV_DATE) SEPARATED BY ‘.’.
  AT NEW MATNR.
    WRITE :/’AT new record’.
    WRITE:/ WA_MARA-MATNR, LV_DATE.
  ENDAT.
  CLEAR: WA_MARA, LV_DATE.

ENDLOOP.

********* With At End of Control Statement***************

WRITE:/ ‘Material Number’, 20 ‘Created on’.
ULINE.
LOOP AT IT_MARA INTO WA_MARA.

  CONCATENATE WA_MARA-ERSDA+6(2) WA_MARA-ERSDA+4(2) WA_MARA-ERSDA+0(4) INTO LV_DATE SEPARATED BY ‘.’.
  AT END OF MATNR.
    WRITE :/’AT End of record’.
    WRITE:/ WA_MARA-MATNR, LV_DATE.
  ENDAT.
  CLEAR: WA_MARA, LV_DATE.

ENDLOOP.

Control Break Statements in SAP ABAP
Before control Statement
Control Break Statements in SAP ABAP
Before Control Statement output

AT FIRST IN SAP ABAP

AT first
AT First
AT first
At first Output

AT LAST IN SAP ABAP

AT Last
At Last
AT Last
AT Last Output

AT NEW IN SAP ABAP

At New
At New
At New
At New Output

AT End of in SAP ABAP

AT End of
AT End of
AT End of
AT End of Output

Problem with Control Break Statements

Sometime At first statement is not trigger due to some technical issue like we trying to call at first MATNR from IT_MSEG internal table where MBLNR listed first and MATNR is listing in third column so here At first MATNR will not trigger, to solve this issue we must adjust our internal table and get MATNR on first column.

FAQ

What is Control Break Statement?

Control Break Statement is used to control the Loop in SAP ABAP or we can say is used to control data flow in loop.

How many type of Control Break Statement available?

There is 4 kind of control break statements available in system these are
AT First, AT Last, AT New and AT end of.

What is the Difference between Control break statement and Control Statement?

Control Break Statement is different from Control statement, the BREAK, EXIT, CONTINUE are used to break and come out of the current loop where it occurs, where as AT NEW, AT END,AT LAST, AT FIRST is used to check for a table field value (internal table). When u asked for control statements alone, you need to answer as BREAK, EXIT, CONTINUE, CHECK because it controls the program flow.

Dear Reader hope this article is helpful to understand Control statement in SAP ABAP, Please connect with us for next article.

1 thought on “CONTROL BREAK STATEMENTS IN SAP ABAP | 4 Types of Control Break Statements & Examples”

Leave a Comment

%d bloggers like this: