Selection Screens and Variants
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Many classic ABAP programs start by asking the user a few questions: which claims do you want to see, from which date,
how many lines. The screen that asks these questions is called a selection screen. You do not draw it. You declare
the input fields with a few statements, and ABAP builds the screen, reads what the user typed into program variables and
then runs the program. A variant is a saved set of answers, so that the same report can be started again with the same
values, also in the night as a background job. A newcomer meets selection screens in almost every old report, and a
developer who maintains such a report has to read and change them. After reading this page you can declare single
fields and value ranges, group and hide them, check the input, start a report with prepared values and explain what a
variant is. The page is written against Standard ABAP release 8.16. Selection screens exist only in classic Standard
ABAP, in programs of the type executable program (a report), and they cannot be created in ABAP Cloud (release 9.20,
2608); the Public Edition of SAP S/4HANA Cloud and the ABAP environment of SAP BTP offer other user interfaces instead,
for example Fiori apps built on the RESTful Application Programming Model. Ranges tables (TYPE RANGE OF), which you meet
below, work in both worlds.
Before you read
-
Program Types and Structure: what a report is and where its statements go.
-
Data Types and Data Objects:
TYPE,LIKEand elementary types such ascandi. -
Internal Tables: tables, lines and
APPEND. -
ABAP SQL Basics:
SELECTwith aWHEREcondition. -
Text Elements and Translation: selection texts and text symbols for titles.
Key terms
-
Selection screen: a screen generated from ABAP statements that collects input for an executable program.
-
Selection parameter: one input field declared with
PARAMETERS, backed by one program variable. -
Selection criterion: a field declared with
SELECT-OPTIONSthat accepts single values, intervals and exclusions. -
Ranges table: an internal table with the columns
sign,option,lowandhighthat stores such conditions. -
Selection variant: a saved set of values for the fields of one selection screen.
-
Modification group: a three-character label that lets a program change several screen elements together.
What a selection screen is
Every executable program has one selection screen of its own, called the standard selection screen, with the screen
number 1000. Every PARAMETERS, SELECT-OPTIONS and SELECTION-SCREEN statement that stands in the global declaration
part, outside a block that defines another screen, becomes part of it. You can also define further standalone selection
screens between SELECTION-SCREEN BEGIN OF SCREEN and SELECTION-SCREEN END OF SCREEN, with their own numbers, and
show them with CALL SELECTION-SCREEN. These screens are generated when the program runs and cannot be edited by hand,
and you do not need the Screen Painter (the graphical tool for ordinary dynpros). The ABAP editor, which is part of
ADT or transaction SE38, is the only tool you use.
The runtime sends the screen and then raises selection screen events, which are event blocks of your program that run
before the screen is shown and after the user acts. The order below is the one to keep in mind. Only after the last
selection screen event does START-OF-SELECTION run, which is where the real work of a report belongs.
The loop in the diagram is the reason why AT SELECTION-SCREEN OUTPUT runs many times, while INITIALIZATION runs only
once.
Single fields with PARAMETERS
PARAMETERS para TYPE type declares a selection parameter. It does two things at once: it creates a global variable
para in the program, as DATA would, and it puts an input field with the same name on the standard selection screen.
When the user chooses Execute, the content of the field is moved into the variable. The name has at most eight
characters, which is why classic code uses short names such as p_status, with p_ for a parameter by convention. A
character-like parameter is converted to uppercase by default, so a user who types open gets OPEN. When the type
comes from the ABAP Dictionary, the field takes over the properties of that type, such as its length, its F1 help and
its input help (the list of values behind F4); a type of the program itself brings none of them.
The most used additions are in the table. Most can be combined, some cannot, and the keyword documentation lists the exceptions.
| Addition | Effect |
|---|---|
|
Start value. It can be a literal or a data object. |
|
Required field. Execute does nothing and shows a message while it is empty. |
|
Keeps lowercase letters as typed. |
|
Shows a checkbox. The type is |
|
Makes the parameter one radio button of a group. The group name has at most four characters, and at most one parameter
of the group has a |
|
Shows a dropdown list. The list entries are supplied by the program, for example with the function module
|
|
Checks the entry against the fixed values of the domain or the foreign key. Without it there is no automatic check. |
|
Links the field to a search help of the ABAP Dictionary. |
|
Fills the field from the SET/GET parameter |
|
Hides the field. A caller can still fill it with |
|
Puts the element in the modification group |
|
Gives a checkbox, radio button group or listbox a function code, so that choosing it raises |
Value ranges with SELECT-OPTIONS
A single value is often not enough. A user wants the claims numbered C-1000 to C-1999, or everything except
status REJECTED, or three particular numbers. SELECT-OPTIONS selcrit FOR dobj declares a selection criterion for the
data object dobj. Its type decides the type of the values. On the screen it shows two input fields, one for the lower
and one for the upper limit, and a button for multiple selection, where the user enters lists of single values and
intervals, and can exclude values as well.
In the program, selcrit is a selection table: an internal standard table with four columns, which is exactly what the
user entered, one condition per line.
| Column | Meaning |
|---|---|
|
|
|
The comparison: |
|
The value for a single comparison, or the lower limit of an interval. |
|
The upper limit of an interval. |
The selection table is used directly in a condition. IN selcrit is true for a value that fits the table, in a loop
over a table with WHERE as well as in an ABAP SQL WHERE clause (WHERE claim_id IN @s_id). When the table is empty, because the user
filled nothing in, the condition is true for every line. That is useful, but it also means that a report over a large
table selects the whole table if the user leaves the field empty. For historical reasons a selection table has a
header line, a work area with the same name as the table. To address the lines of the table as a table, for example in
IF s_id[] IS INITIAL, write the name with square brackets.
Useful additions are DEFAULT a TO b OPTION c SIGN d for a first line of the table, NO-EXTENSION to remove the
multiple-selection button, NO INTERVALS to remove the second input field, OBLIGATORY, LOWER CASE,
MATCHCODE OBJECT, MEMORY ID, NO-DISPLAY and MODIF ID, with the same meaning as for PARAMETERS.
TYPE RANGE OF versus RANGES
The four-column layout is not special to selection screens. A table of that layout is called a ranges table, and you can
declare one yourself, for example to build conditions in code. The current way is DATA r TYPE RANGE OF type, and
TYPES accepts the same addition. The table has no header line. The older statement RANGES r FOR dobj is obsolete,
is forbidden in classes and declares a table with a header line; replace it with TYPE RANGE OF when you meet it. A
selection table declared by SELECT-OPTIONS and a ranges table declared by TYPE RANGE OF have the same structure, so
you can pass one to the other.
The next listing needs no selection screen, so it ran in the local playground (open-abap, a community transpiler that
runs a subset of ABAP in Node.js). It builds two ranges tables by hand and shows how IN reads them, including the
empty table. The playground pads each WRITE line with trailing blanks, which are removed below.
REPORT zranges.
TYPES: BEGIN OF ty_claim,
claim_id TYPE c LENGTH 8,
status TYPE c LENGTH 8,
amount TYPE i,
END OF ty_claim.
START-OF-SELECTION.
DATA claims TYPE STANDARD TABLE OF ty_claim WITH EMPTY KEY.
claims = VALUE #( ( claim_id = 'C-1001' status = 'OPEN' amount = 120 )
( claim_id = 'C-1002' status = 'APPROVED' amount = 80 )
( claim_id = 'C-1003' status = 'OPEN' amount = 1500 )
( claim_id = 'C-1004' status = 'REJECTED' amount = 300 ) ).
" The same four-column layout that SELECT-OPTIONS creates.
DATA r_amount TYPE RANGE OF i.
APPEND VALUE #( sign = 'I' option = 'BT' low = 100 high = 400 ) TO r_amount.
APPEND VALUE #( sign = 'E' option = 'EQ' low = 300 ) TO r_amount.
DATA r_status TYPE RANGE OF ty_claim-status.
APPEND VALUE #( sign = 'I' option = 'CP' low = 'OP*' ) TO r_status.
APPEND VALUE #( sign = 'I' option = 'EQ' low = 'REJECTED' ) TO r_status.
WRITE / 'amount in 100..400 but not 300:'.
LOOP AT claims INTO DATA(c) WHERE amount IN r_amount.
WRITE / c-claim_id.
ENDLOOP.
WRITE / 'status OPEN* or REJECTED:'.
LOOP AT claims INTO c WHERE status IN r_status.
WRITE / c-claim_id.
ENDLOOP.
DATA r_empty TYPE RANGE OF i.
DATA(n) = 0.
LOOP AT claims INTO c WHERE amount IN r_empty.
n = n + 1.
ENDLOOP.
WRITE / |empty range keeps { n } of { lines( claims ) } lines|.
Output:
amount in 100..400 but not 300: C-1001 status OPEN* or REJECTED: C-1001 C-1003 C-1004 empty range keeps 4 of 4 lines
Read the output line by line. Claim C-1002 (80) is below the interval and C-1004 (300) is excluded by the second
line, so only C-1001 is left. The pattern OP* fits OPEN, and the second line adds REJECTED. The empty table
keeps everything, which is the rule that surprises beginners most.
Blocks and layout
Without further statements, every field gets its own line. The SELECTION-SCREEN statement arranges the screen:
-
SELECTION-SCREEN BEGIN OF BLOCK name WITH FRAME TITLE titleandSELECTION-SCREEN END OF BLOCK namegroup the elements in between, optionally in a frame with a title. Blocks can be nested up to five levels deep. The name has at most 20 characters. The title is either a text symbol, writtenTEXT-t01, or a name of at most eight characters that the program fills at run time. Every block raises its own event,AT SELECTION-SCREEN ON BLOCK, in which the program can check the entries of the block together. -
SELECTION-SCREEN COMMENTwrites a line of text,SELECTION-SCREEN ULINEa horizontal line andSELECTION-SCREEN SKIPempty lines. -
SELECTION-SCREEN BEGIN OF LINEandEND OF LINEput several elements in one line, andSELECTION-SCREEN PUSHBUTTONadds a button that raises an event with a function code. -
SELECTION-SCREEN BEGIN OF TABBED BLOCKbuilds tab pages from subscreens, andSELECTION-SCREEN FUNCTION KEYenables up to five buttons in the application toolbar (function codesFC01toFC05).
When two elements are placed on the same position, the selection screen cannot be generated, so check the position numbers when you use POSITION or COMMENT with an explicit column. The captions of
fields are selection texts of the text pool; see Text
Elements and Translation.
Selection screen events and input checks
A selection screen has its own events. They are event blocks that start with AT SELECTION-SCREEN, and the table
shows the ones you use most. Declarations inside these blocks create local data, so declare shared data globally.
| Event block | Runs |
|---|---|
|
Once, before the first screen is shown. Use it for start values that |
|
Before every display of the screen, also after each reaction. This is the place to change screen elements. |
|
When the value of a parameter or selection criterion arrives in the program. Use it to check one field. |
|
When all fields of a block have arrived. |
|
When a radio button group has arrived. |
|
When the user presses F4 on a field. The program can show its own list of values. |
|
When the user chooses Back, Exit or Cancel. Use it for cleaning up. |
|
Last, after all input has arrived, and also for a function code from a button or a field with |
|
After selection screen processing is complete. The main work of the report goes here. |
Check input here and not in START-OF-SELECTION. A message of type E raised in an AT SELECTION-SCREEN block shows
the error and makes the fields ready for input again, so the user can correct the entry without starting over; a message
raised later in START-OF-SELECTION ends the report instead. See
Messages for message types and message classes.
Changing the screen with MODIFY SCREEN
Fixed fields are sometimes too rigid: an option should appear only when a checkbox is ticked. Each element of the
screen has properties that a program can change before the screen is displayed. This happens in
AT SELECTION-SCREEN OUTPUT, with a loop over the elements of the screen:
LOOP AT SCREEN INTO DATA(screen) runs once for every element that has a field behind it, and MODIFY SCREEN FROM screen
writes the changed properties of the current element back. The work area has, among others, these components.
| Component | Meaning |
|---|---|
|
The name of the element, for example |
|
The modification groups. The first one holds the three characters of |
|
|
|
|
|
|
The changes last only for the current display. At the start of every display the elements are back at their static
properties, which is why the code belongs to AT SELECTION-SCREEN OUTPUT and runs again each time. The statement works
only during that screen output, not while input is processed.
Example: a claim report
The report below belongs to the expense claims example and reads the table ZEXP_CLAIM. It has a frame with a selection
criterion for the claim number, a parameter for the status and a selection criterion for the amount, and a second
frame with a checkbox and a limit that is hidden while the checkbox is off. It sets a start range in INITIALIZATION,
checks the limit in an AT SELECTION-SCREEN ON block and uses the selection table in the SELECT. The text symbols
t01 and t02 are the frame titles (maintained as text elements). The listing requires an SAP system; not run here,
because the local playground has no selection screen, no ABAP Dictionary table and no database table ZEXP_CLAIM.
The message text is a literal only to keep the example short; a real program uses a message class.
REPORT zexp_claim_sel.
TABLES sscrfields.
DATA gs_claim TYPE zexp_claim.
SELECTION-SCREEN BEGIN OF BLOCK b_filter WITH FRAME TITLE TEXT-t01.
SELECT-OPTIONS s_id FOR gs_claim-claim_id.
PARAMETERS p_stat TYPE zexp_claim-status DEFAULT 'OPEN'.
SELECT-OPTIONS s_amt FOR gs_claim-amount.
SELECTION-SCREEN END OF BLOCK b_filter.
SELECTION-SCREEN BEGIN OF BLOCK b_view WITH FRAME TITLE TEXT-t02.
PARAMETERS p_detail AS CHECKBOX DEFAULT 'X' USER-COMMAND det.
PARAMETERS p_limit TYPE i DEFAULT 10 MODIF ID lim.
SELECTION-SCREEN END OF BLOCK b_view.
INITIALIZATION.
" A start value that DEFAULT cannot express: a first line of the selection table.
APPEND VALUE #( sign = 'I' option = 'BT' low = 1 high = 1000 ) TO s_amt.
AT SELECTION-SCREEN OUTPUT.
" Runs before every display: hide the limit while the checkbox is off.
LOOP AT SCREEN INTO DATA(screen).
IF screen-group1 = 'LIM' AND p_detail = abap_false.
screen-active = 0.
MODIFY SCREEN FROM screen.
ENDIF.
ENDLOOP.
AT SELECTION-SCREEN ON BLOCK b_view.
IF p_detail = abap_true AND p_limit < 1.
MESSAGE 'Enter a limit of at least 1' TYPE 'E'.
ENDIF.
START-OF-SELECTION.
SELECT claim_id, status, amount
FROM zexp_claim
WHERE claim_id IN @s_id
AND status = @p_stat
AND amount IN @s_amt
ORDER BY claim_id
INTO TABLE @DATA(claims)
UP TO @p_limit ROWS.
IF p_detail = abap_true.
LOOP AT claims INTO DATA(claim).
WRITE: / claim-claim_id, claim-status, claim-amount.
ENDLOOP.
ELSE.
WRITE / |{ lines( claims ) } claims match|.
ENDIF.
When the report starts, the user sees the two frames with the amount range 1 to 1000 already entered. Ticking the
checkbox sends a function code, which raises AT SELECTION-SCREEN and then AT SELECTION-SCREEN OUTPUT again, and the
limit field disappears or appears. An empty claim number leaves every claim number in play, and a limit of 0 produces
the error message and the screen stays open. The DATA gs_claim line gives the criteria a typed data object to refer
to after FOR; the older TABLES statement does the same, and you will see it in old programs.
Variants
A variant stores the values of the fields of one selection screen under a name. The values of every parameter and selection criterion are saved, so that the report can later be started with the same entries, without typing them again. Two situations make variants important. A report that is scheduled as a background job has no user at the screen, so the job step names a variant that supplies the values. And a report that a team runs every month with the same criteria gets a variant that each of them chooses.
Variants are created and managed for every program that has selection screens, either in the ABAP Workbench (the program in transaction SE38, then Variants) or while the program is running, by choosing Goto, then Variants on the selection screen: fill in the fields, choose Save as Variant and give a name and a short text. Choosing Get Variant loads one back into the fields. A variant belongs to one selection screen of one program; the keyword documentation says that a variant of a different selection screen is ignored.
A program can use a variant itself with SUBMIT, the statement that starts another executable program. It can pass
a variant, a table of values or single values, with or without showing the screen. With AND RETURN the calling program
continues afterwards in the same session.
Without any variant, a report called from code can be filled directly. The next listing starts the claim report three
ways: with single values, with a table of type RSPARAMS and with a variant, which must exist already and is named here
as an example MONTH_END. It requires an SAP system; not run here.
" 1. Single values: WITH passes values for individual fields.
SUBMIT zexp_claim_sel
WITH s_id BETWEEN 'C-1000' AND 'C-1999'
WITH p_stat = 'APPROVED'
WITH p_detail = abap_false
AND RETURN.
" 2. A table: kind P is a parameter, kind S a selection criterion.
DATA params TYPE STANDARD TABLE OF rsparams WITH EMPTY KEY.
params = VALUE #( ( selname = 'P_STAT' kind = 'P' low = 'OPEN' )
( selname = 'S_ID' kind = 'S' sign = 'I' option = 'CP' low = 'C-1*' ) ).
SUBMIT zexp_claim_sel
WITH SELECTION-TABLE params
AND RETURN.
" 3. A saved variant of the program.
SUBMIT zexp_claim_sel
USING SELECTION-SET 'MONTH_END'
AND RETURN.
Names of parameters and selection criteria are written in uppercase in RSPARAMS, and the addition VIA SELECTION-SCREEN
shows the screen with the values already filled in instead of running immediately. The call authorizes against the
authorization group of the program, so a user who may not run the report cannot start it through SUBMIT either.
Common mistakes
-
Empty means everything. An empty selection table selects all lines. Check
s_id[] IS INITIALand refuse the run, or require a field withOBLIGATORY, when the table is large. -
Name too long. The names of parameters and selection criteria have at most eight characters, and a radio button group four. A longer name is a syntax error.
-
Technical captions. Without a selection text the user sees
P_STAT. Maintain the selection texts in the text elements; see Text Elements and Translation. -
Uppercase surprise. Character parameters are converted to uppercase. Add
LOWER CASEwhen the value is case sensitive. -
The header line.
s_idis the header line ands_id[]the table. Passings_idwhere a table is expected gives a wrong result or a syntax error. -
Work in the wrong event. Checks belong in
AT SELECTION-SCREEN, start values inINITIALIZATIONand the data selection inSTART-OF-SELECTION. Code inAT SELECTION-SCREEN OUTPUTruns on every display, so a databaseSELECTthere runs repeatedly. -
Wrong function code field. Read
sscrfields-ucommfor function codes of selection screens. the keyword documentation recommends it for selection screens. -
Hidden is not empty. A field made inactive with
MODIFY SCREENkeeps its value, and the program still reads it. -
Selection screens in new programs. Selection screens belong to classic ABAP and are not available in ABAP Cloud. New developments for the Public Edition and for ABAP Cloud use RAP and Fiori elements instead, and ABAP Cloud keeps
TYPE RANGE OFandINfor conditions that a program builds itself.
Summary
-
A selection screen collects input for an executable program.
PARAMETERScreates one field and one variable,SELECT-OPTIONScreates a field for values, intervals and exclusions with a selection table, andSELECTION-SCREENarranges the layout. -
A selection table and a ranges table have the same columns:
sign,option,lowandhigh. UseTYPE RANGE OFand not the obsoleteRANGES, and remember that an empty table lets every line pass. -
The runtime raises events in a fixed order:
INITIALIZATION,AT SELECTION-SCREEN OUTPUT, the checking events, and finallySTART-OF-SELECTION. -
LOOP AT SCREENandMODIFY SCREENinAT SELECTION-SCREEN OUTPUTchange the display, using modification groups set withMODIF ID. -
A variant saves the values of one selection screen, so a report can run again, also as a background job;
SUBMITstarts a report with a variant, a table or single values. -
Selection screens exist only in classic Standard ABAP and not in ABAP Cloud.