Control break and loop control statements in SAP ABAP help manage data processing efficiently. They simplify internal table handling and improve program readability.
This article covers:
- Control break statements (
AT FIRST
,AT LAST
,AT NEW
,AT END OF
) - Loop control statements (
EXIT
,CONTINUE
,RETURN
) - Examples and best practices

SAP Control Break Statements
Control break statements trigger actions at specific points during LOOP AT
processing. They help in handling grouped data efficiently.
Types of Control Break Statements
- AT FIRST – Executes once before the first record.
- AT LAST – Executes once after processing the last record.
- AT NEW <Field> – Triggers when a field value changes.
- AT END OF <Field> – Executes at the last occurrence of a field value.
Example: Using Control Breaks
abapCopyEditLOOP AT it_data INTO wa_data.
AT FIRST.
WRITE: / 'Employee Report'.
WRITE: / '-----------------'.
ENDAT.
AT NEW department.
WRITE: / 'Department:', wa_data-department.
ENDAT.
WRITE: / wa_data-emp_id, wa_data-name, wa_data-salary.
AT END OF department.
WRITE: / 'Total for', wa_data-department, ':', dept_total.
dept_total = 0.
ENDAT.
AT LAST.
WRITE: / '-----------------'.
WRITE: / 'End of Report'.
ENDAT.
ENDLOOP.
SAP Loop Control Statements
Loop control statements manage the flow within loops. They help in controlling iterations efficiently.
Types of Loop Control Statements
- EXIT – Exits the loop immediately.
- CONTINUE – Skips the current iteration and moves to the next.
- RETURN – Exits the current processing block (method, function, or form).
1. EXIT Statement
EXIT
stops the loop execution completely. It is often used in search operations.
Example: Exit Loop on Condition
abapCopyEditLOOP AT it_data INTO wa_data.
IF wa_data-emp_id = 'E1001'.
WRITE: / 'Employee found:', wa_data-name.
EXIT. "Exit loop after finding the employee
ENDIF.
ENDLOOP.
Use case: Finding the first matching record and stopping further processing.
2. CONTINUE Statement
CONTINUE
skips the current iteration and moves to the next record.
Example: Skip Processing for Specific Records
abapCopyEditLOOP AT it_data INTO wa_data.
IF wa_data-salary < 3000.
CONTINUE. "Skip employees with salary below 3000
ENDIF.
WRITE: / wa_data-emp_id, wa_data-name, wa_data-salary.
ENDLOOP.
Use case: Ignoring certain records based on conditions.
3. RETURN Statement
RETURN
exits the current processing block, such as a method or function.
Example: Exit a Method Early
abapCopyEditMETHOD check_employee.
IF emp_id IS INITIAL.
RETURN. "Exit method if employee ID is missing
ENDIF.
WRITE: / 'Processing Employee:', emp_id.
ENDMETHOD.
Use case: Stopping method execution when a condition is met.
Best Practices for Control Break & Loop Control Statements
- Use sorted tables for control break statements to work efficiently.
- Minimize logic inside AT blocks to improve performance.
- Use EXIT only when necessary to prevent unintended terminations.
- Use CONTINUE to skip unnecessary processing and improve efficiency.
- Avoid RETURN inside loops unless it’s needed for method exits.
Know more on SAP
Pingback: Mastering Core ABAP: 12 Key Concepts for SAP Development