ABAP Reports and Selection Screens – Study Notes
Learning Date: 2026-03-19 Learning Objective: Understand the flow of executable programs, selection screen processing, and event-driven execution model in ABAP Content Source: https://help.sap.com/
1. Overview
Executable programs in ABAP follow a specific execution flow driven by events. Understanding this event-driven model is fundamental to developing effective report programs and batch applications in SAP. The execution begins when a program is called via the SUBMIT statement and proceeds through a defined sequence of events and processes that handle initialization, user input, data retrieval, and output generation.
The selection screen serves as the primary interface for user input in executable programs. It provides a standardized mechanism for users to specify parameters and selection criteria before data processing begins. The ABAP runtime environment manages this entire process, ensuring proper sequencing of events and handling user interactions appropriately. This separation of concerns between input, processing, and output is a hallmark of well-structured ABAP applications.
Modern ABAP development continues to enhance selection screen capabilities while maintaining backward compatibility with classic event-driven programming. The evolution from procedural reports to object-oriented approaches has introduced new paradigms, but the core event model remains essential knowledge for any SAP developer working with report development or batch processing scenarios.
2. Core Knowledge Modules
2.1 Executable Program Flow Overview
The execution of an executable ABAP program follows a strict event-driven sequence managed by the ABAP runtime environment. When a program is launched using the SUBMIT statement, the runtime environment orchestrates a series of processes that raise events and execute associated processing blocks in a predetermined order.
Key Event Sequence:
The program flow begins with the LOAD-OF-PROGRAM event, which occurs when the program and its associated global data are loaded into memory. This event serves as the program constructor and is triggered exactly once per program call. Immediately following, the runtime environment assigns default values to parameters and selection criteria defined in the program. The INITIALIZATION event then provides an opportunity for programmatic initialization before any screens are displayed.
The selection screen processing represents a complex subprocess within the overall flow. The system displays the selection screen and processes all associated events, including AT SELECTION-SCREEN OUTPUT for screen modifications and AT SELECTION-SCREEN for user command processing. The flow either continues to data processing or terminates based on user actions such as clicking Back, Exit, or Cancel.
The data retrieval phase encompasses START-OF-SELECTION and potentially multiple GET events if the program is associated with a logical database. These events execute the core business logic and data fetching operations. The END-OF-SELECTION event provides a final processing opportunity before output generation. Finally, the basic list is displayed or sent to the SAP spool system for batch processing.
2.2 Program Constructor Event – LOAD-OF-PROGRAM
The LOAD-OF-PROGRAM event marks the beginning of program execution and occurs when the ABAP runtime environment loads the program into an internal session. This event serves as the program constructor, similar to the constructor method of a class, and is executed exactly once per program call.
Execution Context:
This event executes before any default values are assigned to selection screen parameters. It provides a reliable point for performing one-time initialization of program-wide resources, such as establishing database connections, setting up shared data structures, or preparing global variables. The event executes within the context of the internal session established by the calling program or transaction.
The LOAD-OF-PROGRAM event is particularly important in the context of shared memory objects and shared data areas. Any shared objects or data referenced in this event block are instantiated or loaded into the shared memory area, making them available to subsequent processing blocks and potentially to other programs in the same internal session.
Practical Considerations:
Developers should be cautious about performing time-consuming operations in LOAD-OF-PROGRAM, as this directly impacts program startup time. Heavy operations such as complex database queries or large data retrievals should be deferred to subsequent events where they can be better controlled and monitored. This event is best reserved for lightweight initialization tasks that must execute before any user interaction or data processing begins.
LOAD-OF-PROGRAM.
” Initialize global variables
gv_session_id = cl_system_uuid=>create_uuid_x16( ).
gv_start_time = utclong_get_current( ).
” Set up shared objects
TRY.
go_cache = cl_abap_memory=>get_cache( ).
CATCH cx_root.
” Handle cache initialization failure
ENDTRY.
” Log program start
WRITE: / ‘Program started:’, gv_start_time.
2.3 INITIALIZATION Event
The INITIALIZATION event executes after default values have been assigned to PARAMETERS and SELECT-OPTIONS but before the selection screen is displayed. This event provides a final opportunity to modify default values, perform dynamic initializations, and prepare the selection screen based on context-specific requirements.
Use Cases:
Common applications of INITIALIZATION include setting context-dependent defaults based on user preferences, organizational settings, or current business date. For example, a sales report might default the date range to the current fiscal period based on the user’s organizational unit. The event can also be used to hide or disable selection criteria based on user authorization or previous selections.
INITIALIZATION.
” Set default date range to current month
DATA: lv_first_day TYPE d,
lv_today TYPE d.
lv_today = sy-datum.
CALL FUNCTION ‘GET_FIRST_DAY_OF_MONTH’
EXPORTING
day_in = lv_today
IMPORTING
first_day_of_month = lv_first_day.
s_date-low = lv_first_day.
s_date-high = lv_today.
s_date-sign = ‘I’.
s_date-option = ‘BT’.
APPEND s_date.
” Set default company code from user parameter
SELECT SINGLE usrid FROM usr21 INTO @DATA(lv_pernr).
SELECT SINGLE persg FROM pa0001
WHERE pernr = @lv_pernr
AND begda <= @sy-datum
AND endda >= @sy-datum.
2.4 Selection Screen Processing
Selection screens are specialized screens generated automatically from PARAMETERS and SELECT-OPTIONS statements. They provide a user-friendly interface for entering report execution criteria and are processed through a defined event sequence managed by the ABAP runtime environment.
Selection Screen Events:
The AT SELECTION-SCREEN OUTPUT event (PBO – Process Before Output) executes immediately before the selection screen is displayed. This event allows programmatic modification of screen elements, such as setting field attributes, hiding fields based on conditions, or dynamically adjusting default values. The AT SELECTION-SCREEN event (PAI – Process After Input) executes after user input has been processed, allowing validation and response to user actions.
AT SELECTION-SCREEN OUTPUT.
” Modify screen dynamically
LOOP AT SCREEN.
IF screen-group1 = ‘GR1’.
screen-input = ‘0’.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
AT SELECTION-SCREEN ON p_vkorg.
” Validate organization
SELECT SINGLE vkorg FROM tvko
INTO @DATA(lv_exists)
WHERE vkorg = @p_vkorg.
IF sy-subrc <> 0.
MESSAGE e001(zmsg) WITH p_vkorg ‘does not exist’.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_search.
” F4 help
CALL FUNCTION ‘F4_TEXTS’
EXPORTING
value = p_search
IMPORTING
result = p_search.
2.5 START-OF-SELECTION and END-OF-SELECTION
The START-OF-SELECTION event marks the beginning of the main data processing phase. It executes after the selection screen has been processed and the user has chosen to continue (not Back, Exit, or Cancel). This event typically contains the core business logic, including database queries and data processing operations.
The END-OF-SELECTION event provides a final processing opportunity after all data retrieval is complete. It is particularly useful for final output formatting, summary calculations, or cleanup operations that should execute regardless of whether the START-OF-SELECTION processing produced any results.
START-OF-SELECTION.
” Set progress indicator
SET PF-STATUS ‘MAIN’.
SET TITLEBAR ‘TIT_MAIN’.
” Fetch data
SELECT vbak~vbeln, vbak~erdat, vbak~netwr, vbap~posnr,
vbap~matnr, mara~maktx, vbap~kwmeng
FROM vbak
INNER JOIN vbap ON vbak~vbeln = vbap~vbeln
LEFT JOIN mara ON vbap~matnr = mara~matnr
LEFT JOIN makt ON mara~matnr = makt~matnr AND makt~spras = ‘E’
INTO CORRESPONDING FIELDS OF TABLE gt_order_items
WHERE vbak~erdat IN s_date
AND vbak~vkorg = p_vkorg.
” Process records
LOOP AT gt_order_items ASSIGNING FIELD-SYMBOL(
ENDLOOP.
END-OF-SELECTION.
” Display summary
DATA: lv_total TYPE p DECIMALS 2.
LOOP AT gt_order_items INTO DATA(ls_item).
lv_total = lv_total + ls_item-line_total.
ENDLOOP.
WRITE: / ‘Total Value:’, lv_total CURRENCY ‘CNY’.
2.6 GET Events and Logical Databases
When an executable program is associated with a logical database, additional GET events are raised during the data retrieval phase. These events correspond to nodes in the logical database hierarchy and are triggered when the database program has read a record for the corresponding node.
Logical Database Structure:
Logical databases organize data retrieval hierarchically, ensuring referential integrity and optimizing database access. Each node in the logical database structure corresponds to a database table, and the GET event for that node is raised whenever the logical database reads a record from that table. The program can then process the retrieved data within the corresponding GET event block.
” Logical database PNP (HR) example
GET PERNR.
” Employee level processing
WRITE: / ‘Processing Employee:’, pnp-pernr.
GET BEGDA.
” Infotype 0001 (Org Assignment) retrieval
rp_provide_from_frst pnp-pernr ‘0001’ pnp-begda pnp-endda.
IF pnp-pernr-rc = 0.
WRITE: / ‘Organizational Unit:’, p0001-orgeh.
ENDIF.
GET BUKRS.
” Company code level (hierarchical)
WRITE: / ‘Company:’, pnp-bukrs.
2.7 List Processing
After all data processing events have completed, the ABAP runtime environment generates the basic list output. The basic list is either displayed on screen, sent to the SAP spool system for printing, or saved to ABAP memory depending on the submission parameters.
List Event Handling:
User interactions with the displayed list raise list events, including AT LINE-SELECTION (triggered by double-click or function key), AT USER-COMMAND (triggered by custom function codes), TOP-OF-PAGE (triggered at page breaks), and END-OF-PAGE (triggered before page breaks). These events enable interactive list processing similar to classical Dynpro programming.
START-OF-SELECTION.
” Generate list output
SELECT vbeln, erdat, netwr
FROM vbak
INTO TABLE @DATA(lt_orders)
WHERE erdat = @sy-datum.
LOOP AT lt_orders INTO DATA(ls_order).
WRITE: / ls_order-vbeln, ls_order-erdat, ls_order-netwr.
HIDE: ls_order-vbeln. ” Store for AT LINE-SELECTION
ENDLOOP.
AT LINE-SELECTION.
” Display details for selected order
SET PARAMETER ID ‘VL’ FIELD ls_order-vbeln.
CALL TRANSACTION ‘VA03’ AND SKIP FIRST SCREEN.
TOP-OF-PAGE.
WRITE: / ‘Sales Orders Report’.
WRITE: / ‘Date:’, sy-datum.
ULINE.
3. Code Examples
3.1 Complete Report Program with Selection Screen
This comprehensive example demonstrates the complete structure of an executable ABAP report with selection screen, event handling, and list output:
REPORT z_sales_report.
TABLES: vbak, vbap, mara, makt.
” Selection Screen Definition
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-hdr.
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY DEFAULT ‘1000’,
p_lifsp TYPE lifsp DEFAULT space.
SELECT-OPTIONS: s_erdat FOR vbak-erdat NO-EXTENSION,
s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN SKIP.
PARAMETERS: p_detail RADIOBUTTON GROUP rpt DEFAULT ‘X’,
p_summary RADIOBUTTON GROUP rpt.
SELECTION-SCREEN END OF BLOCK b1.
” Data Declaration
DATA: gt_orders TYPE TABLE OF vbak,
gs_order TYPE vbak,
gt_items TYPE TABLE OF vbap,
gs_item TYPE vbap.
” Initialization
INITIALIZATION.
text-hdr = ‘Sales Order Selection’.
s_erdat-low = sy-datum – 30.
s_erdat-high = sy-datum.
s_erdat-sign = ‘I’.
s_erdat-option = ‘BT’.
APPEND s_erdat.
” Selection Screen Events
AT SELECTION-SCREEN OUTPUT.
IF p_summary = abap_true.
LOOP AT SCREEN.
IF screen-name CS ‘S_VBELN’.
screen-invisible = ‘1’.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_vbeln-low.
” Custom F4 help for sales orders
CALL FUNCTION ‘Z_F4_SALES_ORDERS’
IMPORTING
et_orders = DATA(lt_f4_orders).
CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’
EXPORTING
retfield = ‘VBELN’
value_org = ‘S’
TABLES
value_tab = lt_f4_orders
return_tab = DATA(lt_return)
EXCEPTIONS
OTHERS = 4.
” Main Processing
START-OF-SELECTION.
PERFORM fetch_orders.
PERFORM process_orders.
END-OF-SELECTION.
PERFORM display_summary.
” Subroutines
FORM fetch_orders.
SELECT * FROM vbak
INTO TABLE gt_orders
WHERE vkorg = p_vkorg
AND erdat IN s_erdat
AND vbeln IN s_vbeln
AND lifsp = p_lifsp
AND vbtyp = ‘C’.
IF sy-subrc <> 0.
MESSAGE s003 DISPLAY LIKE ‘W’.
ENDIF.
ENDFORM.
FORM process_orders.
IF p_detail = abap_true.
SELECT * FROM vbap
INTO TABLE gt_items
FOR ALL ENTRIES IN gt_orders
WHERE vbeln = gt_orders-vbeln.
ENDIF.
ENDFORM.
FORM display_summary.
IF p_summary = abap_true.
WRITE: / ‘Summary Report’.
ULINE.
DATA: lv_count TYPE i,
lv_total TYPE netwr.
DESCRIBE TABLE gt_orders LINES lv_count.
LOOP AT gt_orders INTO gs_order.
lv_total = lv_total + gs_order-netwr.
ENDLOOP.
WRITE: / ‘Total Orders:’, lv_count.
WRITE: / ‘Total Value:’, lv_total CURRENCY ‘CNY’.
ELSE.
LOOP AT gt_orders INTO gs_order.
WRITE: / gs_order-vbeln, gs_order-erdat, gs_order-netwr.
ENDLOOP.
ENDIF.
ENDFORM.
3.2 Interactive Report with List Events
This example demonstrates interactive list processing with drill-down capability:
REPORT z_customer_analysis.
SELECTION-SCREEN BEGIN OF BLOCK cust.
PARAMETERS: p_kunnr TYPE kunnr MATCHCODE OBJECT debi.
SELECT-OPTIONS: s_erdat FOR vbak-erdat.
SELECTION-SCREEN END OF BLOCK cust.
DATA: gt_vbak TYPE TABLE OF vbak,
gs_vbak TYPE vbak.
START-OF-SELECTION.
SELECT * FROM vbak
INTO TABLE gt_vbak
WHERE kunnr = p_kunnr
AND erdat IN s_erdat
AND vbtyp = ‘C’
ORDER BY erdat DESCENDING.
IF gt_vbak IS INITIAL.
MESSAGE s001(zmsg) WITH ‘No orders found’.
ENDIF.
LOOP AT gt_vbak INTO gs_vbak.
WRITE: / gs_vbak-vbeln COLOR COL_KEY,
gs_vbak-erdat COLOR COL_NORMAL,
gs_vbak-netwr COLOR COL_POSITIVE.
HIDE gs_vbak-vbeln.
ENDLOOP.
AT LINE-SELECTION.
CHECK gs_vbak-vbeln IS NOT INITIAL.
DATA: ls_vbap TYPE vbap,
lt_items TYPE TABLE OF vbap.
SELECT * FROM vbap
INTO TABLE lt_items
WHERE vbeln = gs_vbak-vbeln.
IF sy-subrc = 0.
WRITE: / ‘Order Items:'(t01).
LOOP AT lt_items INTO ls_vbap.
WRITE: / ls_vbap-posnr, ls_vbap-matnr, ls_vbap-kwmeng.
ENDLOOP.
ENDIF.
4. Practical Applications
4.1 Applicable Scenarios
Financial Reporting:
Executable programs with selection screens are extensively used in financial reporting applications. The selection screen enables users to specify fiscal periods, company codes, and account ranges, while the event-driven architecture supports complex calculations and aggregations in START-OF-SELECTION and END-OF-SELECTION blocks. The hierarchical nature of financial data often benefits from logical database integration, particularly in programs accessing multiple related tables.
Sales and Distribution Analysis:
Sales reports leverage selection screens for specifying sales organizations, date ranges, and customer hierarchies. Interactive features like drill-down from order headers to line items use AT LINE-SELECTION events to provide detailed analysis capabilities. Batch execution with background processing enables scheduled report generation and distribution through SAPmail or external email systems.
Data Extraction and Interfaces:
Reports designed for data extraction often use SELECT-OPTIONS extensively to specify complex selection criteria. The WITH HOLD DATA addition in SUBMIT preserves user selections for subsequent executions, improving usability in repetitive extraction scenarios. Export to file using CL_BCS or direct dataset operations enables integration with external systems.
4.2 Best Practices
Performance Optimization:
Database access in START-OF-SELECTION should use WHERE clauses that leverage database indexes, avoiding full table scans where possible. Aggregate operations in SELECT statements reduce data transfer volume. Using field lists rather than SELECT * minimizes memory consumption, particularly when processing large result sets.
User Experience:
Selection screens should provide sensible defaults based on user context and business rules. Proper use of MATCHCODE objects and F4 help improves data entry accuracy. Message handling should provide clear feedback while allowing continuation for non-critical issues.
Maintainability:
Modularization using subroutines (PERFORM) or methods improves code organization and testability. Comments documenting the purpose of each event block and major processing section aid future maintenance. Parameterization of hard-coded values enables configuration without code changes.
5. Common Questions
Q: What is the difference between START-OF-SELECTION and END-OF-SELECTION events?
A: START-OF-SELECTION executes at the beginning of the data processing phase, after the selection screen has been processed and before any GET events (if using logical databases). It typically contains the main data retrieval and processing logic. END-OF-SELECTION executes after all data processing is complete, including all GET events. It is commonly used for summary calculations, final formatting, or cleanup operations that should execute regardless of whether the data retrieval produced results.
Q: How do I prevent the selection screen from displaying when running a report in background mode?
A: The selection screen is automatically suppressed when a report is submitted with the addition AND RETURN TO CURRENT MODE or when submitted from a batch input session. The SPA/GPA parameters (SET PARAMETER ID/GET PARAMETER ID) can be used to pass values programmatically, ensuring the report has necessary input values even without user interaction.
Q: What is the purpose of HIDE in list processing?
A: The HIDE statement stores values associated with a displayed line, making them available in subsequent AT LINE-SELECTION or AT USER-COMMAND events. When a user clicks a line, the hidden values are automatically populated into the corresponding variables, enabling the program to determine which record was selected without requiring complex cursor position calculations.
Q: How can I make a selection screen field read-only dynamically?
A: Use the AT SELECTION-SCREEN OUTPUT event to modify screen element attributes. Loop through the SCREEN internal table and set screen-input = ‘0’ for fields that should be read-only. For radio button groups, you can also modify screen-active to hide fields that are irrelevant based on the current selection.
Q: What happens if I use multiple executable programs with the same selection screen number?
A: Each executable program should use a unique selection screen number. By default, the standard selection screen 1000 is used. To use a custom selection screen, specify the screen number in the REPORT statement using the LINE-SIZE and LINE-COUNT additions, or use SELECTION-SCREEN BEGIN OF SCREEN screen_number. When multiple programs share the same screen number, conflicts can occur during selection screen processing.
6. Learning Resources
SAP Help Portal – ABAP Keyword Documentation
Selection Screen Documentation: PARAMETERS, SELECT-OPTIONS statements
Event Documentation: INITIALIZATION, START-OF-SELECTION, END-OF-SELECTION
List Processing: AT LINE-SELECTION, TOP-OF-PAGE events
Logical Database Documentation: GET events, database program structure
Summary
Core Takeaways
Event-Driven Execution Model: ABAP executable programs follow a strict event-driven execution sequence managed by the ABAP runtime environment. Understanding this sequence—from LOAD-OF-PROGRAM through INITIALIZATION, selection screen processing, data retrieval (START-OF-SELECTION and GET events), to END-OF-SELECTION and list display—is fundamental to effective report development.
Selection Screen Processing: Selection screens are automatically generated from PARAMETERS and SELECT-OPTIONS statements and processed through PBO (AT SELECTION-SCREEN OUTPUT) and PAI (AT SELECTION-SCREEN) events. These events enable dynamic modification and validation of user input before processing begins.
Interactive List Processing: The basic list generated by WRITE statements supports interactive processing through AT LINE-SELECTION and AT USER-COMMAND events. The HIDE statement enables storing values for retrieval when users interact with list entries.
Logical Database Integration: Programs associated with logical databases receive GET events for each node in the database hierarchy, providing a structured approach to hierarchical data retrieval with built-in referential integrity.
Background Processing: Reports can be executed in background mode using SUBMIT with appropriate additions, with selection screen processing automatically bypassed when appropriate parameters are provided.
Key Insights
The ABAP executable program model represents a mature, proven architecture for developing business reports and batch applications. While modern ABAP development emphasizes object-oriented approaches and class-based components, the event-driven report model remains essential knowledge. Many standard SAP transactions and custom developments continue to leverage this architecture for its simplicity and effectiveness in data processing scenarios.
The tight integration between selection screens, event processing, and list output provides a cohesive framework that balances user interaction flexibility with programmatic control. Understanding the subtleties of this integration—such as when defaults are applied, when AT SELECTION-SCREEN events execute, and how HIDE works with interactive lists—enables developers to build robust, user-friendly applications.
Action Items
Review existing reports for proper event block usage and optimization opportunities
Implement comprehensive selection screen validation using AT SELECTION-SCREEN events
Add interactive drill-down capabilities to flat list reports where appropriate
Evaluate background processing opportunities for scheduled report distribution
Document selection screen conventions and best practices for the development team
