DAY-11: Mastering ABAP Events - A Comprehensive Guide to Execution Flow and Interactive Reporting

On a journey of continuous learning π I share the concepts I learn daily through blogs. Learn concepts with me β one topic at a time.
#LearningInPublic #ContinuousLearning
In SAP ABAP, programs follow an event-driven programming model, unlike traditional languages that execute line by line from top to bottom.
Instead, ABAP programs respond to specific events triggered during execution.
This allows developers to control:
When validation happens
When database logic runs
When output is printed
When interactive actions occur
When user commands are handled
Understanding ABAP events is essential to writing professional reports.
In this guide, we will cover:
Selection Screen Events
Processing Events
Interactive Events
System Fields
Debugging Concepts
Working Code Example
π What Are ABAP Events?
An Event is a predefined execution block that runs automatically at a specific stage of the program lifecycle.
Think of it like real-world triggers:
| Real-Life Action | ABAP Event |
| Pressing Execute | START-OF-SELECTION |
| Double-clicking a line | AT LINE-SELECTION |
| Opening a page | LOAD-OF-PROGRAM |
| Filling a form | AT SELECTION-SCREEN |
| Pressing a function key | AT USER-COMMAND |
π Complete ABAP Program Execution Flow
When you run an ABAP report, this is the real sequence:

Understanding this flow makes debugging and logic placement much easier.
LOAD-OF-PROGRAM
This event runs when the program is loaded into memory.
Example
LOAD-OF-PROGRAM.
WRITE: / 'Program Loaded Successfully'.
Use Cases
Display startup message
Initialize static variables
Load configuration
INITIALIZATION
Runs before the selection screen appears.
Used to set default values.
INITIALIZATION.
p_carr = 'LH'.
If the user runs the report, the carrier field automatically shows LH.
AT SELECTION-SCREEN (Validation Event)
Triggered when user interacts with selection screen.
Example: Field Validation
AT SELECTION-SCREEN ON p_carr.
IF p_carr IS INITIAL.
MESSAGE 'Carrier cannot be empty' TYPE 'E'.
ENDIF.
If the field is empty, an error message is shown.
AT SELECTION-SCREEN OUTPUT (Dynamic Screen)
Used to modify screen elements dynamically.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'P_CARR'.
screen-intensified = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
This highlights the input field.
START-OF-SELECTION (Main Logic Begins)
This is the most important event.
It runs when the user presses F8 (Execute).
START-OF-SELECTION.
All:
SELECT statements
Calculations
Core logic
should go here.
Database Selection Example
SELECT carrid connid price
FROM sflight
INTO TABLE gt_flight
WHERE carrid = p_carr.
Important Keywords
| Keyword | Meaning |
| INTO TABLE | Store result in internal table |
| WHERE | Apply filter |
| sy-subrc | Check success or failure |
Checking System Field (sy-subrc)
IF sy-subrc <> 0.
WRITE: / 'No Data Found'.
EXIT.
ENDIF.
sy-subrc = 0 β Successsy-subrc β 0 β Failure
END-OF-SELECTION
Triggered after data retrieval.
Best place to:
Loop internal table
Display results
Calculate totals
LOOP & Data Processing
LOOP AT gt_flight INTO gs_flight.
IF gs_flight-price > 500.
WRITE: / 'High Price Flight'.
ELSE.
WRITE: / 'Normal Flight'.
ENDIF.
ENDLOOP.
Interactive Reporting
Using HIDE
HIDE gs_flight.
This stores data for the selected line.
Double Click Event
AT LINE-SELECTION.
WRITE: / 'You selected:', gs_flight-carrid.
When user double-clicks a row, this event triggers.
TOP-OF-PAGE & END-OF-PAGE
Used for header and footer formatting.
TOP-OF-PAGE.
WRITE: / 'Flight Report',
/ 'User:', sy-uname,
'Date:', sy-datum,
'Time:', sy-uzeit.
AT USER-COMMAND
Triggered when user presses function key.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'FC01'.
WRITE: / 'Function Key 1 Pressed'.
ENDCASE.
π§ System Fields Every Developer Must Know
| Field | Purpose |
| sy-subrc | Return code |
| sy-uname | Current user |
| sy-datum | Current date |
| sy-uzeit | Current time |
| sy-ucomm | Function code |
π Debugging Concepts
Static Breakpoint
BREAK-POINT.
Stops program execution.
Activate Debugger Manually
Type:
/h
in command field before execution.
Debugger Controls
| Key | Function |
| F5 | Step into |
| F6 | Execute |
| F7 | Return |
| F8 | Continue |
π§ͺ Complete Beginner-Friendly Example
REPORT z_event_demo.
TYPES: BEGIN OF ty_flight,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
price TYPE sflight-price,
END OF ty_flight.
DATA: gt_flight TYPE TABLE OF ty_flight,
gs_flight TYPE ty_flight,
gv_total TYPE p DECIMALS 2.
PARAMETERS: p_carr TYPE sflight-carrid OBLIGATORY.
INITIALIZATION.
p_carr = 'LH'.
START-OF-SELECTION.
SELECT carrid connid price
FROM sflight
INTO TABLE gt_flight
WHERE carrid = p_carr.
IF sy-subrc <> 0.
MESSAGE 'No Data Found' TYPE 'I'.
EXIT.
ENDIF.
END-OF-SELECTION.
LOOP AT gt_flight INTO gs_flight.
WRITE: / gs_flight-carrid,
gs_flight-connid,
gs_flight-price.
gv_total = gv_total + gs_flight-price.
ENDLOOP.
WRITE: / 'Total Price:', gv_total.
π― Final Understanding
By mastering ABAP events, you now understand:
β Event-driven execution
β Selection screen lifecycle
β Validation handling
β Database processing
β Interactive reporting
β System fields
β Debugging flow
π₯ Key Takeaway
ABAP development is not just about writing code.
It is about:
Knowing where to place logic
Understanding execution timing
Controlling user interaction
Designing structured reports
Once you understand events, you control the entire ABAP program lifecycle.



