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

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-OPTIONS that accepts single values, intervals and exclusions.

  • Ranges table: an internal table with the columns sign, option, low and high that 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.

flowchart TD A[LOAD-OF-PROGRAM] --> B[INITIALIZATION: start values] B --> C[AT SELECTION-SCREEN OUTPUT: change the screen] C --> D{User acts} D -->|Enter or a function code| E[AT SELECTION-SCREEN ON field and ON BLOCK: check the input] E -->|error message E| C E --> F[AT SELECTION-SCREEN: last check] F -->|function code of a field or button| C F -->|Execute F8| G[START-OF-SELECTION: the work] G --> H[list output]

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

DEFAULT value

Start value. It can be a literal or a data object.

OBLIGATORY

Required field. Execute does nothing and shows a message while it is empty.

LOWER CASE

Keeps lowercase letters as typed.

AS CHECKBOX

Shows a checkbox. The type is c of length 1, and the value is X when it is ticked.

RADIOBUTTON GROUP grp

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 DEFAULT.

AS LISTBOX VISIBLE LENGTH n

Shows a dropdown list. The list entries are supplied by the program, for example with the function module VRM_SET_VALUES.

VALUE CHECK

Checks the entry against the fixed values of the domain or the foreign key. Without it there is no automatic check.

MATCHCODE OBJECT help

Links the field to a search help of the ABAP Dictionary.

MEMORY ID id

Fills the field from the SET/GET parameter id of the user, the user memory that remembers the last entry.

NO-DISPLAY

Hides the field. A caller can still fill it with SUBMIT.

MODIF ID xyz

Puts the element in the modification group xyz, with three characters, for the screen changes shown below.

USER-COMMAND fcode

Gives a checkbox, radio button group or listbox a function code, so that choosing it raises AT SELECTION-SCREEN immediately. Declare TABLES sscrfields and read sscrfields-ucomm, not sy-ucomm.

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

sign

I includes the lines that fit the condition, E excludes them.

option

The comparison: EQ, NE, GT, GE, LT, LE, CP (matches a pattern) and NP (does not match) when high is initial, and BT (between) and NB (not between) when high is filled.

low

The value for a single comparison, or the lower limit of an interval.

high

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 title and SELECTION-SCREEN END OF BLOCK name group 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, written TEXT-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 COMMENT writes a line of text, SELECTION-SCREEN ULINE a horizontal line and SELECTION-SCREEN SKIP empty lines.

  • SELECTION-SCREEN BEGIN OF LINE and END OF LINE put several elements in one line, and SELECTION-SCREEN PUSHBUTTON adds a button that raises an event with a function code.

  • SELECTION-SCREEN BEGIN OF TABBED BLOCK builds tab pages from subscreens, and SELECTION-SCREEN FUNCTION KEY enables up to five buttons in the application toolbar (function codes FC01 to FC05).

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

INITIALIZATION

Once, before the first screen is shown. Use it for start values that DEFAULT cannot express, for instance a date calculated from today.

AT SELECTION-SCREEN OUTPUT

Before every display of the screen, also after each reaction. This is the place to change screen elements.

AT SELECTION-SCREEN ON para

When the value of a parameter or selection criterion arrives in the program. Use it to check one field.

AT SELECTION-SCREEN ON BLOCK blk

When all fields of a block have arrived.

AT SELECTION-SCREEN ON RADIOBUTTON GROUP grp

When a radio button group has arrived.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR para

When the user presses F4 on a field. The program can show its own list of values. ON HELP-REQUEST FOR para does the same for F1.

AT SELECTION-SCREEN ON EXIT-COMMAND

When the user chooses Back, Exit or Cancel. Use it for cleaning up.

AT SELECTION-SCREEN

Last, after all input has arrived, and also for a function code from a button or a field with USER-COMMAND.

START-OF-SELECTION

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

name

The name of the element, for example P_LIMIT; MODIFY SCREEN does nothing when it is changed.

group1 to group4

The modification groups. The first one holds the three characters of MODIF ID.

active

1 for normal, 0 hides the element completely and sets input and output to 0 and invisible to 1.

input, output, invisible

1 or 0 for ready for input, shown and hidden.

required

1 makes the field required, 0 removes the requirement.

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 INITIAL and refuse the run, or require a field with OBLIGATORY, 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 CASE when the value is case sensitive.

  • The header line. s_id is the header line and s_id[] the table. Passing s_id where 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 in INITIALIZATION and the data selection in START-OF-SELECTION. Code in AT SELECTION-SCREEN OUTPUT runs on every display, so a database SELECT there runs repeatedly.

  • Wrong function code field. Read sscrfields-ucomm for function codes of selection screens. the keyword documentation recommends it for selection screens.

  • Hidden is not empty. A field made inactive with MODIFY SCREEN keeps 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 OF and IN for conditions that a program builds itself.

Summary

  • A selection screen collects input for an executable program. PARAMETERS creates one field and one variable, SELECT-OPTIONS creates a field for values, intervals and exclusions with a selection table, and SELECTION-SCREEN arranges the layout.

  • A selection table and a ranges table have the same columns: sign, option, low and high. Use TYPE RANGE OF and not the obsolete RANGES, 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 finally START-OF-SELECTION.

  • LOOP AT SCREEN and MODIFY SCREEN in AT SELECTION-SCREEN OUTPUT change the display, using modification groups set with MODIF ID.

  • A variant saves the values of one selection screen, so a report can run again, also as a background job; SUBMIT starts a report with a variant, a table or single values.

  • Selection screens exist only in classic Standard ABAP and not in ABAP Cloud.