Skip to main content
  1. Documentation/

Selection screen and report in ABAP

··9 mins· loading · loading · · ·
SAP ERP Back-End
Adrien D'acunto
Author
Adrien D’acunto
Table of Contents

Selection screen and report in ABAP
#

Selection Screen
#

Objectives
#

  • Create a simple user interface for entering criteria
  • Allow data selection or file import through the screen
  • Use PARAMETERS and SELECT-OPTIONS to filter data

Definition
#

A selection screen is a user interface that allows the end user to:

  • Enter data
  • Define selection criteria
  • Import files or data lists
  • Interact with the program in a user-friendly way

Imagine an Excel form where the user can enter an ID, a name, or choose a city from a dropdown list to filter rows.

SAP provides example programs (often starting with DEMO) to illustrate the use of selection screens.

Example
#

Definition of a simple selection screen
#

SELECTION-SCREEN BEGIN OF BLOCK b000 WITH FRAME TITLE TEXT-000.

    " Declaration of selection parameters
    PARAMETERS: p_id   TYPE zpassenger-id_passenger,
                p_name TYPE zpassenger-name.

    " Declaration of a selection option for ranges or lists
    SELECT-OPTIONS: s_city FOR zpassenger-city.

SELECTION-SCREEN END OF BLOCK b000.
  1. PARAMETERS defines a single field for user input.
  2. SELECT-OPTIONS creates an interval or list of values.
  3. Entered values are accessible in the program to filter data.
  4. Facilitates user interaction and entry of multiple criteria.

SELECT-OPTIONS automatically create internal tables to store the values entered by the user.

Best Practices
#

  • Always properly initialize parameters to avoid unexpected empty values.
  • Prefer SELECT-OPTIONS over PARAMETERS for lists or ranges.
  • Provide default values to make usage easier.
  • Validate user input when necessary to avoid data processing errors.

Summary
#

  • The selection screen is the main interface between the ABAP program and the user.
  • PARAMETERS is used for a single field; SELECT-OPTIONS for lists or intervals.
  • The entered values are used to filter or select records from a table.
  • SAP DEMO* programs are useful for illustrating best practices.

PARAMETERS
#

Objectives
#

  • Create a simple input field for the end user
  • Retrieve and use the value entered in the ABAP program
  • Improve navigation and understanding through input texts

Definition
#

PARAMETERS create simple input fields for the user, similar to fields in a paper form or Excel sheet. Each PARAMETER can contain only one value. Use: retrieve user-entered data to filter, calculate, or process records.

Imagine a form where the user only enters a document number or a date. PARAMETERS correspond to each field of that form.

PARAMETERS can automatically generate a MATCHCODE if the type is linked to a DDIC table, making search easier.

PARAMETERS Instruction
#

Simple declaration example
#

PARAMETERS: p_vbeln TYPE vbak-vbeln,
            p_posnr TYPE vbap-posnr.
  • PARAMETERS: is mandatory to declare one or several input fields.
  • p_vbeln: name of the parameter (conventionally starting with p_), here for entering the sales document number.
  • TYPE: defines the expected type and allows automatic matchcode generation.
  • vbak-vbeln: reference to the table field in the DDIC.
  • p_posnr: second parameter for entering the item number.

Parameter Options
#

Mandatory field
#

The OBLIGATORY option makes the parameter mandatory.

PARAMETERS: p_vbeln TYPE vbak-vbeln OBLIGATORY,
            p_posnr TYPE vbap-posnr.

Field with default value
#

The DEFAULT keyword applies a default value to the field.

PARAMETERS: p_vbeln TYPE vbak-vbeln OBLIGATORY,
            p_posnr TYPE vbap-posnr DEFAULT '00015'.

Input Texts
#

  • By default, the text displayed during execution is the parameter name.
  • Customization options:
    • Manual entry for each parameter (may require translations).
    • Automatic via DDIC if the type is linked to a table/field (recommended).

Best Practices
#

  • Use clear, understandable parameter names; follow the p_ convention.
  • Always type the parameter with a DDIC field for automatic validations and matchcodes.
  • Provide default values if needed.
  • Validate the entered value in the program to avoid errors.

Summary
#

  • PARAMETERS creates a single input field for the user.
  • The field is typed via TYPE and may generate an automatic matchcode.
  • Input texts can be customized.
  • Convention: names start with p_ for easy identification.

SELECT-OPTIONS
#

Objectives
#

  • Create an input field allowing retrieval of a range of values
  • Retrieve and use values entered in the ABAP program
  • Allow users to filter based on ranges

Definition
#

SELECT-OPTIONS create dual input fields to retrieve value ranges. Unlike PARAMETERS, a SELECT-OPTIONS field can contain several rows corresponding to multiple entries or intervals.

Imagine an Excel sheet where you can enter multiple value intervals or a list of numbers: SELECT-OPTIONS provides this flexibility, while PARAMETERS allows only a single cell.

Each SELECT-OPTIONS is typed automatically based on a DDIC table field, which allows matchcode generation and validation.

Affected Tables Declaration
#

Example
#

TABLES: vbak, vbap.
  • Mandatory to specify which tables will be used with SELECT-OPTIONS.
  • Usually placed at the beginning of the program.
  • Links the field type and activates automatic matchcodes.

SELECT-OPTIONS Declaration
#

Example
#

SELECT-OPTIONS: s_vbeln FOR vbak-vbeln,
                s_posnr FOR vbap-posnr.
  • SELECT-OPTIONS: is mandatory for declaration.
  • s_vbeln: field name (convention: s_), here for sales document number.
  • FOR: indicates the table field used for typing and matchcode.
  • Both fields can contain several rows (multiple intervals or single values).

Specific Behaviors
#

Single entry
#

  • If only one value is entered, the SELECT-OPTIONS behaves like a PARAMETERS.

No entry
#

  • If no value is entered, the program considers all possible values.

Always check the affected table if using SELECT-OPTIONS to filter data.

Parameter Options
#

Mandatory field
#

The OBLIGATORY parameter of the PARAMETERS statement makes the field mandatory.

SELECT-OPTIONS: s_vbeln FOR vbak-vbeln OBLIGATORY,
                s_posnr FOR vbap-posnr.

Field with default value
#

The parameter DEFAULT followed by the value applies a default value to the field at the Low value level.

SELECT-OPTIONS: s_vbeln FOR vbak-vbeln OBLIGATORY,
                s_posnr FOR vbap-posnr DEFAULT '00015'.

Input texts
#

  • Interface texts can be customized as for PARAMETERS.
  • Makes the interface more readable and accessible.

Best Practices
#

  • Use the s_ naming convention.
  • Declare affected tables before selection options.
  • Provide clear input texts.
  • Test different input types: range, single value, no value.

Summary
#

  • SELECT-OPTIONS creates fields for ranges or multiple values.
  • Each entry can contain several rows.
  • Affected tables must be declared with TABLES.
  • Names start with s_ by convention.

MATCH-CODE
#

Objectives
#

  • Understand how match codes work in a selection screen
  • Use automatic and specific match codes
  • Facilitate data selection by the end user

Definition
#

MATCH-CODES are search aids that allow users to display a list of choices to facilitate data selection.
They are often used in SELECTION-SCREENS to improve the user experience and reduce input errors.

Imagine a search engine with automatic suggestions when you start typing a keyword. MATCH-CODES do the same thing for SAP fields: they suggest possible values.

Standard behavior
#

  • In a SELECTION-SCREEN, a MATCH-CODE automatically appears to the right of fields if the type (TYPE for PARAMETERS, FOR for SELECT-OPTIONS) refers to a DDIC table field.

Example
#

PARAMETERS: p_vbeln TYPE vbak-vbeln,
            p_posnr TYPE vbap-posnr.
  • Here, p_vbeln and p_posnr are typed on table fields.
  • SAP automatically suggests the MATCH-CODES associated with the fields.
  • If the type is a simple type (e.g., TYPE vbeln), no MATCH-CODE will be suggested.

Automatic MATCH-CODES eliminate the need to manually create a list of values.

Specific match codes
#

  • It is possible to create a specific MATCH-CODE for a PARAMETERS or SELECT-OPTIONS:
  1. Create the MATCH-CODE using transaction SE11 or the search help.
  2. Add the parameter MATCHCODE OBJECT match_code_name to the declaration.

Example
#

PARAMETERS: p_matnr TYPE mara-matnr MATCHCODE OBJECT zar_mara.
  • p_matnr is typed on mara-matnr.
  • The specific MATCH-CODE zar_mara is used to display the custom columns and values defined in the search help.

Specific MATCH-CODES allow only relevant values to be displayed and improve readability for the user.

Best practices
#

  • Always use automatic MATCH-CODES when typing is done on table fields.
  • Create specific MATCH-CODES to filter and customize the list of values if necessary.
  • Test the behavior of the search help for different user profiles.

Summary
#

  • MATCH-CODES facilitate data selection on SELECTION-SCREENS.
  • Typing on DDIC table = automatic MATCH-CODE.
  • Typing on simple type = no MATCH-CODE.
  • Specific MATCH-CODES allow you to display customized columns and values to improve the user experience.

ALV (ABAP List Viewer)
#

Objectives
#

  • Display data in a structured and interactive way
  • Use the CL_SALV_TABLE class to create a dynamic table
  • Provide users with sorting, filtering, and exporting functions

Definition
#

An ALV (ABAP List Viewer) is an SAP tool that allows you to display lists and tables of data in a clear, structured, and interactive way.
It offers integrated functions such as:

  • automatic column sorting,
  • filtering,
  • totals and subtotals,
  • exporting to Excel,
  • and customization options (column width, multiple sorting, etc.).

Imagine an Excel table directly integrated into SAP, but automatically generated from your code.
That’s exactly what ALV does: it transforms an internal table into a dynamic interactive table.

Simple implementation example
#

DATA: r_salv_table TYPE REF TO cl_salv_table,
      lt_mara      TYPE TABLE OF mara.

" Fill the internal table with data
SELECT * FROM mara INTO TABLE @lt_mara UP TO 20 ROWS.

" Create the ALV from the internal table
TRY.
    CALL METHOD cl_salv_table=>factory
        IMPORTING
            r_salv_table = r_salv_table
        CHANGING
            t_table      = lt_mara.
    CATCH cx_salv_msg INTO DATA(lx_msg).
        WRITE: / ALV error:, lx_msg->get_text( ).
ENDTRY.

" Displaying the ALV table
r_salv_table->display( ).

Explanation
#

1. Declaration
#

  • We declare an object reference r_salv_table of type CL_SALV_TABLE.
  • An internal table lt_mara contains the data to be displayed.

2. Loading data
#

  • The internal table is filled with a SELECT.

3. Creating the ALV object
#

  • The FACTORY method automatically creates the ALV structure from the internal table.

4. Displaying
#

  • r_salv_table->display( ) opens the ALV window with all interactive functions.

5. Error handling
#

  • CATCH cx_salv_msg captures any errors related to creating or displaying the ALV.

Help
#

  • The ALV is compatible with most standard data types.
  • If the column names are not self-explanatory, you can rename them using cl_salv_columns_table.
  • CL_SALV_TABLE is a simplified, modern version of the ALV GRID module.

Use CL_SALV_TABLE for internal reports or quality control tools: it is fast, readable, and does not require a complex interface to code.

Best Practices
#

  • Always populate the internal table before calling FACTORY.
  • Use a row limit (UP TO n ROWS) to avoid long execution times.
  • Test the ALV rendering before delivering it (width, titles, formats).
  • Consider adding totals or default sorts according to user needs.

If your internal table is empty, the ALV will be displayed without any visible columns.
Always check the content before calling display( ).

Resume
#

  • The ALV (ABAP List Viewer) allows you to display data in a clear, fast, and interactive way.
  • The CL_SALV_TABLE class makes it easy to create a dynamic table.
  • It is an essential tool for viewing, checking, and validating data.
  • Built-in features (sorting, filtering, exporting) make the ALV very powerful and user-friendly.

Related

ITAB Instructions in ABAP
··38 mins· loading · loading
SAP ERP Back-End
Instructions in ABAP
··20 mins· loading · loading
SAP ERP Back-End
Coniunctiones in ABAP
··18 mins· loading · loading
SAP ERP Back-End
Introduction to ABAP
·14 mins· loading · loading
SAP ERP Back-End
ITAB Types in ABAP
··14 mins· loading · loading
SAP ERP Back-End
ABAP Program Structure
··12 mins· loading · loading
SAP ERP Back-End