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.
PARAMETERSdefines a single field for user input.SELECT-OPTIONScreates an interval or list of values.- Entered values are accessible in the program to filter data.
- Facilitates user interaction and entry of multiple criteria.
SELECT-OPTIONSautomatically create internal tables to store the values entered by the user.
Best Practices #
- Always properly initialize parameters to avoid unexpected empty values.
- Prefer
SELECT-OPTIONSoverPARAMETERSfor 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.
PARAMETERSis used for a single field;SELECT-OPTIONSfor 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 #
PARAMETERScreate simple input fields for the user, similar to fields in a paper form or Excel sheet. EachPARAMETERcan 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.
PARAMETERScorrespond to each field of that form.
PARAMETERScan 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 withp_), 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
OBLIGATORYoption makes the parameter mandatory.
PARAMETERS: p_vbeln TYPE vbak-vbeln OBLIGATORY,
p_posnr TYPE vbap-posnr.
Field with default value #
The
DEFAULTkeyword 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 #
PARAMETERScreates a single input field for the user.- The field is typed via
TYPEand 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-OPTIONScreate dual input fields to retrieve value ranges. UnlikePARAMETERS, aSELECT-OPTIONSfield 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-OPTIONSprovides this flexibility, whilePARAMETERSallows only a single cell.
Each
SELECT-OPTIONSis 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-OPTIONSbehaves like aPARAMETERS.
No entry #
- If no value is entered, the program considers all possible values.
Always check the affected table if using
SELECT-OPTIONSto filter data.
Parameter Options #
Mandatory field #
The
OBLIGATORYparameter of thePARAMETERSstatement makes the field mandatory.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln OBLIGATORY,
s_posnr FOR vbap-posnr.
Field with default value #
The parameter
DEFAULTfollowed 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-OPTIONScreates 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-CODESare search aids that allow users to display a list of choices to facilitate data selection.
They are often used inSELECTION-SCREENSto improve the user experience and reduce input errors.
Imagine a search engine with automatic suggestions when you start typing a keyword.
MATCH-CODESdo the same thing for SAP fields: they suggest possible values.
Standard behavior #
- In a
SELECTION-SCREEN, aMATCH-CODEautomatically appears to the right of fields if the type (TYPEforPARAMETERS,FORforSELECT-OPTIONS) refers to a DDIC table field.
Example #
PARAMETERS: p_vbeln TYPE vbak-vbeln,
p_posnr TYPE vbap-posnr.
- Here,
p_vbelnandp_posnrare typed on table fields.- SAP automatically suggests the
MATCH-CODESassociated with the fields.- If the type is a simple type (e.g.,
TYPE vbeln), noMATCH-CODEwill be suggested.
Automatic
MATCH-CODESeliminate the need to manually create a list of values.
Specific match codes #
- It is possible to create a specific
MATCH-CODEfor aPARAMETERSorSELECT-OPTIONS:
- Create the
MATCH-CODEusing transaction SE11 or the search help. - Add the parameter
MATCHCODE OBJECT match_code_nameto the declaration.
Example #
PARAMETERS: p_matnr TYPE mara-matnr MATCHCODE OBJECT zar_mara.
p_matnris typed onmara-matnr.- The specific
MATCH-CODEzar_marais used to display the custom columns and values defined in the search help.
Specific
MATCH-CODESallow only relevant values to be displayed and improve readability for the user.
Best practices #
- Always use automatic
MATCH-CODESwhen typing is done on table fields. - Create specific
MATCH-CODESto filter and customize the list of values if necessary. - Test the behavior of the search help for different user profiles.
Summary #
MATCH-CODESfacilitate data selection onSELECTION-SCREENS.- Typing on DDIC table = automatic
MATCH-CODE.- Typing on simple type = no
MATCH-CODE.- Specific
MATCH-CODESallow 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_TABLEclass 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_tableof typeCL_SALV_TABLE. - An internal table
lt_maracontains the data to be displayed.
2. Loading data #
- The internal table is filled with a
SELECT.
3. Creating the ALV object #
- The
FACTORYmethod 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_msgcaptures 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_TABLEis a simplified, modern version of the ALV GRID module.
Use
CL_SALV_TABLEfor 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 callingdisplay( ).
Resume #
- The ALV (ABAP List Viewer) allows you to display data in a clear, fast, and interactive way.
- The
CL_SALV_TABLEclass 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.