Classical Reports in ABAP use a sequence of predefined events during program execution. These events let you structure your code based on data fetching, formatting, and output rendering.
Event | Description |
---|---|
LOAD-OF-PROGRAM |
Triggered once when the program is loaded into memory (before anything else) |
INITIALIZATION |
Called before the selection screen is displayed |
AT SELECTION-SCREEN |
Called after user input is entered on the selection screen |
START-OF-SELECTION |
Main logic block, starts after selection screen input |
TOP-OF-PAGE |
Used to print page headers |
END-OF-PAGE |
Used to print page footers |
END-OF-SELECTION |
Called after START-OF-SELECTION, typically for final output |
AT LINE-SELECTION |
Triggered by user double-click (F2) on output |
AT USER-COMMAND |
Triggered when a custom function key is pressed |
REPORT zrep_lclclass.
TABLES: mara.
data: lt_mara type table of mara.
" Selection Screen
SELECT-OPTIONS: s_matnr FOR mara-matnr.
" LOAD-OF-PROGRAM
LOAD-OF-PROGRAM.
WRITE: / '>> Program loaded into memory.'.
" INITIALIZATION
INITIALIZATION.
s_matnr-sign = 'I'.
s_matnr-option = 'EQ'.
s_matnr-low = '1'.
s_matnr-high = '9999'.
APPEND s_matnr.
" AT SELECTION-SCREEN
AT SELECTION-SCREEN.
IF s_matnr[] IS INITIAL.
MESSAGE 'Please enter a carrier ID' TYPE 'E'.
ENDIF.
" START-OF-SELECTION
START-OF-SELECTION.
WRITE: / '>> Start of selection'.
SELECT * FROM mara INTO TABLE lt_mara
WHERE matnr IN s_matnr.
IF sy-subrc = 0.
LOOP AT lt_mara INTO DATA(ls_matnr).
WRITE: / ls_matnr-matnr,
ls_matnr-ernam,
ls_matnr-ersda.
ENDLOOP.
ELSE.
WRITE: / 'No data found'.
ENDIF.
" END-OF-SELECTION
END-OF-SELECTION.
WRITE: / '>> End of selection processing.'.
" TOP-OF-PAGE
TOP-OF-PAGE.
WRITE: / 'Material Master Report'.
WRITE: / '------------------------'.
" AT LINE-SELECTION
AT LINE-SELECTION.
MESSAGE 'You clicked a line!' TYPE 'I'.
Output:
Execute