SELECT-OPTIONS in ABAP: Complete Beginner Guide with Examples
Table of Contents
- • What is SELECT-OPTIONS?
- • Why Is It Needed?
- • Basic Syntax & Declaration
- • Simple Program Example
- • Difference Between PARAMETERS and SELECT-OPTIONS
- • Structure Behind SELECT-OPTIONS: The Selection Table
- ↳ 1. SIGN
- ↳ 2. OPTION
- ↳ 3. LOW
- ↳ 4. HIGH
- • Useful SELECT-OPTIONS Additions & Keywords
- ↳ 1. DEFAULT & TO
- ↳ 2. OBLIGATORY
- ↳ 3. NO-EXTENSION
- ↳ 4. NO INTERVALS
- ↳ 5. MEMORY ID
- • Practical Database Query Example
- • Programmatic Population: Manual Range Internal Tables
- • Database Performance Considerations with SELECT-OPTIONS
- • Self-Assessment Checkpoint
- • Summary
![]()
When starting your SAP development journey, you typically begin with variables, PARAMETERS statements, and basic reporting. Once you feel comfortable with those fundamentals, the logical next step is learning how to process multiple inputs or ranges of values on a selection screen. This is where SELECT-OPTIONS becomes essential.
In a real-world business system, users rarely search for just a single item. A finance analyst might need records for three different company codes, a purchasing coordinator might want inventory details for multiple material ranges, or an HR administrator could require data for a specific group of employee IDs. Entering these values one by one or running the same program repeatedly is highly inefficient.
ABAP provides SELECT-OPTIONS to resolve this challenge, letting developers create highly flexible selection fields directly inside their report programs.
What is SELECT-OPTIONS?
SELECT-OPTIONS generates a selection screen field that allows users to input multiple distinct values, intervals, exclusions, and wildcards.
Unlike the PARAMETERS statement, which restricts user input to a single value, SELECT-OPTIONS creates a complex input control that can store multiple search conditions.
This flexibility makes reports far more adaptable. Instead of requiring users to rerun a program multiple times for different input criteria, a single execution can process all conditions simultaneously.
Why Is It Needed?
Consider a purchasing manager who needs material data for the following specific IDs:
1000200030004000
If the program only used PARAMETERS, the manager would have to run the report four separate times. By implementing a range-based selection field, they can input all four numbers together and run it once. This significantly improves efficiency and delivers a cleaner user experience.
Basic Syntax & Declaration
To declare a selection option, use the following syntax:
TABLES mara.
SELECT-OPTIONS: s_matnr FOR mara-matnr.
Let me break down the components:
SELECT-OPTIONS: The keyword declaring the input control.s_matnr: The name of the selection option variable (standard practice is to prefix withs_).FOR: The binding keyword connecting the input variable to a database table field or data element.mara-matnr: The database table and field used to determine the data type, length, and search help metadata.
ℹ️ Note: To reference database fields like
mara-matnrin your declaration, you must first declare the database table using theTABLESstatement at the top of your program:TABLES mara.
Simple Program Example
Here is a complete executable report showing how to declare and execute a selection option program:
REPORT z_select_options_demo.
TABLES: mara.
" Selection Option with default date range
DATA: gv_date TYPE dats.
SELECT-OPTIONS: s_date FOR gv_date DEFAULT sy-datum TO sy-datum.
START-OF-SELECTION.
WRITE: / 'Selection Range Low :', s_date-low,
/ 'Selection Range High:', s_date-high.
When you execute this program, SAP GUI automatically generates a selection screen containing low and high value inputs, as well as a “Multiple Selection” button on the right to configure advanced filtering.
Difference Between PARAMETERS and SELECT-OPTIONS
Understanding the differences between these two input controls is a common interview topic for junior developers.
| Feature / Property | PARAMETERS | SELECT-OPTIONS |
|---|---|---|
| Input Mode | Accepts only one value | Accepts single values, ranges, exclusions, and lists |
| Internal Type | Standard flat variable | Automatically created internal table (Selection Table) |
| SQL Operator | Queried using = or LIKE | Queried using the IN operator |
| Default Screen Layout | Single input box | Low value, High value, and Multiple Selection popup button |
| Typical Use | Toggle options, radio buttons, single keys | Primary filter criteria (Material, Date range) |
Structure Behind SELECT-OPTIONS: The Selection Table
When you declare a SELECT-OPTIONS field, ABAP automatically creates a special Selection Table with the same name. This selection table contains four key header fields:
+-------------------------------------------------------+
| SIGN | OPTION | LOW | HIGH |
+---------+------------+---------------+----------------+
| I | EQ | 1000000021 | |
| I | BT | 1000000050 | 1000000099 |
| E | EQ | 1000000075 | |
+-------------------------------------------------------+
Each row in the selection table represents a filter condition configured by the user.
1. SIGN
Determines whether the matching values should be included or excluded from the query results:
I(Include): Matches should be selected.E(Exclude): Matches should be ignored.
2. OPTION
Defines the comparison operator for the check:
EQ(Equal): Matches the exact low value.BT(Between): Matches any value in the interval fromLOWtoHIGH.GT(Greater Than): Values greater thanLOW.LT(Less Than): Values less thanLOW.NE(Not Equal): Excludes the exact low value.CP(Contains Pattern): Matches using wildcards (e.g.10*).
3. LOW
Stores the single value or the lower boundary of an interval.
4. HIGH
Stores the upper boundary of an interval (used when OPTION is BT).
Useful SELECT-OPTIONS Additions & Keywords
ABAP provides several useful syntax additions to customize selection screen inputs:
1. DEFAULT & TO
Sets default initial values for LOW and HIGH when the screen loads:
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln DEFAULT '0000001000' TO '0000002000'.
2. OBLIGATORY
Makes the selection option a mandatory field. The user cannot run the report without entering a value:
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr OBLIGATORY.
3. NO-EXTENSION
Hides the “Multiple Selection” button on the right, restricting the user to a single value or single interval input:
SELECT-OPTIONS: s_bukrs FOR t001-bukrs NO-EXTENSION.
4. NO INTERVALS
Hides the “HIGH” input field. The user can only enter single values or multiple single values (if multiple selection button is enabled):
SELECT-OPTIONS: s_matkl FOR mara-matkl NO INTERVALS.
5. MEMORY ID
Links the selection option to a global SAP SPA/GPA Parameter ID for automatic caching:
SELECT-OPTIONS: s_matnr FOR mara-matnr MEMORY ID mat.
Practical Database Query Example
To filter database queries using selection options, use the IN operator in your WHERE clause:
REPORT z_select_database_demo.
TABLES: mara.
SELECT-OPTIONS: s_matnr FOR mara-matnr,
s_mtart FOR mara-mtart DEFAULT 'FERT'.
START-OF-SELECTION.
SELECT matnr, mtart, matkl, ersda
FROM mara
INTO TABLE @DATA(lt_materials)
WHERE matnr IN @s_matnr
AND mtart IN @s_mtart.
IF sy-subrc = 0.
WRITE: / 'Total Records Found:', lines( lt_materials ).
LOOP AT lt_materials ASSIGNING FIELD-SYMBOL(<fs_material>).
WRITE: / 'Material:', <fs_material>-matnr,
'Type:', <fs_material>-mtart,
'Created On:', <fs_material>-ersda.
ENDLOOP.
ELSE.
WRITE / 'No materials found matching criteria.'.
ENDIF.
⚠️ Common Mistake: Beginners often use the
=operator (e.g.,WHERE matnr = s_matnr). This will cause a syntax error or runtime failure. You must always use theINoperator to evaluate a selection option table.
Programmatic Population: Manual Range Internal Tables
Sometimes you need to create a selection range programmatically in an ABAP class, function module, or report where no selection screen exists.
You can declare a Range table explicitly using TYPE RANGE OF:
REPORT z_manual_range_demo.
" Declare a range table matching table field type
DATA: lr_matnr TYPE RANGE OF mara-matnr,
ls_matnr LIKE LINE OF lr_matnr.
" Populate Range Row 1: Include single material
ls_matnr-sign = 'I'.
ls_matnr-option = 'EQ'.
ls_matnr-low = '000000000000001001'.
APPEND ls_matnr TO lr_matnr.
" Populate Range Row 2: Include range of materials
ls_matnr-sign = 'I'.
ls_matnr-option = 'BT'.
ls_matnr-low = '000000000000002000'.
ls_matnr-high = '000000000000003000'.
APPEND ls_matnr TO lr_matnr.
" Query database using programmatic Range
SELECT matnr, mtart FROM mara
INTO TABLE @DATA(lt_materials)
WHERE matnr IN @lr_matnr.
In Modern ABAP 7.40+, you can populate ranges inline using constructor operators:
DATA(lr_matnr) = VALUE range_matnr_type(
( sign = 'I' option = 'EQ' low = '000000000000001001' )
( sign = 'I' option = 'BT' low = '000000000000002000' high = '000000000000003000' )
).
Database Performance Considerations with SELECT-OPTIONS
- Empty Selection Table Behavior: When a user leaves a
SELECT-OPTIONSfield completely empty on screen, ABAP treats the range as Select All. TheWHERE column IN @s_optioncondition evaluates to true for all database rows. - Huge Range Performance Risks: If a user pastes thousands of distinct material numbers into the Multiple Selection popup, Open SQL translates the range internal table into a massive SQL
WHERE matnr IN ('...','...')statement. In Oracle or SAP HANA databases, an excessively long SQL statement can exceed database parser limits or lead to temporary memory spikes. - Index Usage & Leading Wildcards: Using wildcard patterns like
*123(OPTION = 'CP',LOW = '*123') prevents the database optimizer from using database indexes, triggering a full table scan.
Self-Assessment Checkpoint
💡 **What fields are automatically created in the internal structure of a SELECT-OPTIONS table?**
A selection option automatically generates an internal table with four fields:
SIGN(valuesIorEfor Include/Exclude)OPTION(operators likeEQ,BT,NE,CP)LOW(lower bound or single value)HIGH(upper bound of an interval)
💡 **What happens when a user runs a report with an empty SELECT-OPTIONS field?**
If the selection table is empty (0 rows), the Open SQL WHERE field IN @s_field clause matches all database rows, returning unrestricted results.
Summary
SELECT-OPTIONS provides a flexible, powerful framework for capturing search criteria in SAP ABAP applications. By mastering selection table structure (SIGN, OPTION, LOW, HIGH), additions (DEFAULT, OBLIGATORY, NO-EXTENSION), and programmatic RANGE tables, you can build efficient, professional SAP reports.
Written by Daksh Dedha
SAP Technical ConsultantDaksh is an SAP Technical Consultant specializing in ABAP programming, SAP S/4HANA migrations, Fiori development, and BTP cloud architecture. He authors free, hands-on tutorials to make enterprise SAP education accessible to all developers.
Test Your Knowledge
Loading question...
Quiz Completed
Related Tutorials
SAP ABAP Enhancement Framework — User Exits, BADIs, and Enhancement Points
Master SAP ABAP enhancements. Learn User Exits, Customer Exits, BADIs, Enhancement Points, and Implicit/Explicit Enhancement Spots to modify standard SAP without modifying source code.
ABAP ProgrammingABAP CDS Views — Core Data Services Complete Guide for Beginners
Learn ABAP CDS Views from scratch. Understand how to create CDS views in Eclipse ADT, use annotations, associations, parameters, and build OData services with CDS.
ABAP ProgrammingMessage Handling in SAP ABAP — Complete SE91 Message Classes Guide
Master SAP ABAP message handling. Learn how to create message classes in transaction SE91, use the MESSAGE statement, handle error types A E W I S X, and pass placeholders.
Found this tutorial useful? Share it with your SAP development team.