📘 SAP ABAP Control Break Statements – Complete Guide with Example
Learn about Control Break Statements in SAP ABAP including AT FIRST, AT NEW, AT END OF, AT LAST, and ON CHANGE OF. Includes a real-time example program with explanation and output. Perfect for SAP ABAP beginners and developers.
- SAP ABAP Control Break Statements
- AT NEW ABAP example
- AT END OF ABAP tutorial
- ABAP loop control
- SAP ABAP report programming
- AT FIRST, AT LAST in ABAP
- SAP ABAP internal table sorted
📘 Introduction
In SAP ABAP, control break statements are used to trigger events inside a loop. They are essential for creating grouped or hierarchical reports, especially when working with sorted internal tables.
There are 5 main control break statements in ABAP:
- AT FIRST – ENDAT
- AT NEW – ENDAT
- AT END OF – ENDAT
- AT LAST – ENDAT
- ON CHANGE OF FIELD.
SAP ABAP Loop Control Tutorial:
🧠 Key Control Break Statements Explained
Statement | Triggered When |
|---|---|
| AT FIRST | Triggered at the first record of the loop |
| AT LAST | Triggered at the last record of the loop |
| AT NEW | Triggered at the first occurrence of a new value in a field |
| AT END OF | Triggered at the last occurrence of a value in a field |
| ON CHANGE OF | Triggered whenever the specified field value changes; can also be used outside loops |
📌 Detailed Explanation
1. AT FIRST – ENDAT
- Executes only once at the first record of a loop.
- Useful for printing headers or initializing counters.
2. AT LAST – ENDAT
- Executes only once at the last record of a loop.
- Often used to print footers or totals.
3. AT NEW <field> – ENDAT
- Executes when a new value of a field is encountered.
- Example: Display Material Type heading when the value changes in sorted table.
4. AT END OF <field> – ENDAT
- Executes at the last occurrence of a field value.
- Useful for calculating totals or counts for grouped data.
5. ON CHANGE OF <field>
- Executes whenever a field value changes.
- Can be used inside or outside loops.
- Often used in reporting to detect changes in key fields.
📌 Notes
- Works only with sorted internal tables.
- Very useful for grouped reports by key fields.
- Supports nested levels, e.g., an AT NEW inside another AT NEW.
🟦 Example Program – SAP ABAP Control Break Statements
Requirement
Display Material Master Data grouped by Material Type (MTART) and count total materials for each type.
🎯 Summary
-
Control Break Statements help in grouping, totaling, and formatting reports.
-
Use AT FIRST and AT LAST for headers/footers.
-
Use AT NEW and AT END OF to group by key fields.
-
ON CHANGE OF is flexible and can be used inside or outside loops.
-
Essential for real-time SAP ABAP reporting scenarios..
Comments
Post a Comment