Show TOC

Calling User-Defined Selection ScreensLocate this document in the navigation structure

Use

You can create user-defined selection screens in executable programs, function modules, and module pools. There are three ways of calling user-defined selection screens.

Call From a Program

From any program in which selection screens are defined, you can call these screens at any point of the program flow using the following statement:

          
CALL SELECTION-SCREEN numb [STARTING AT x1 y1]
          
[ENDING AT x2 y2].
            

This statement calls selection screen number numb . The selection screen called must be defined in the calling program either as the standard selection screen (screen number 1000) or as a an independent selection screen (any screen number). You must always use CALL SELECTION-SCREEN to call selection screens, and never CALL SCREEN . If you use CALL SCREEN , the system will not be able to process the selection screens.

You can display a user-defined selection screen as a modal dialog box using the STARTING AT and ENDING AT additions. This is possible even if you have not used the AS WINDOW addition in the definition of the selection screen. However, you are recommended to do so, since warnings and error messages that occur during selection screen processing will then also be displayed as modal dialog boxes (see example below).

When it returns from the selection screen to the program, the CALL SELECTION-SCREEN statement sets the return value sy-subrc as follows:

  • sy-subrc = 0 if the user has chosen Execute on the selection screen

  • sy-subrc = 4 if the user has chosen Cancel on the selection screen

Any time a selection screen is processed , the selection screen events are triggered. System field sy-dynnr of the associated event blocks contains the number of the selection screen that is currently active.

          


          
REPORT demo_call_selection_screen.
          
SELECTION-SCREEN BEGIN OF BLOCK sel1 WITH FRAME TITLE tit1.
          
PARAMETERS: cityfr TYPE spfli-cityfrom,
          
cityto TYPE spfli-cityto.
          
SELECTION-SCREEN END OF BLOCK sel1.
          
SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW.
          
SELECTION-SCREEN INCLUDE BLOCKS sel1.
          
SELECTION-SCREEN BEGIN OF BLOCK sel2
          
WITH FRAME TITLE tit2.
          
PARAMETERS: airpfr TYPE spfli-airpfrom,
          
airpto TYPE spfli-airpto.
          
SELECTION-SCREEN END OF BLOCK sel2.
          
SELECTION-SCREEN END OF SCREEN 500.
          
INITIALIZATION.
          
tit1 = 'Cities'.
          
AT SELECTION-SCREEN.
          
CASE sy-dynnr.
          
WHEN '0500'.
          
MESSAGE w159(at) WITH 'Screen 500'.
          
WHEN '1000'.
          
MESSAGE w159(at) WITH 'Screen 1000'.
          
ENDCASE.
          
START-OF-SELECTION.
          
tit1 = 'Cities for Airports'.
          
tit2 = 'Airports'.
          
CALL SELECTION-SCREEN 500 STARTING AT 10 10.
          
tit1 = 'Cities again'.
          
CALL SELECTION-SCREEN 1000 STARTING AT 10 10.
          


          


            

The above executable program contains definitions for the standard selection screen and a user-defined screen number 500. Selection screen 500 is provided for display as a modal dialog box and contains the block sel1 of the standard selection screen. Note the times when the titles of the individual screens are defined. For the purpose of demonstration, the program calls warning messages with message class AT during the AT SELECTION-SCREEN event.

When you start the program, the following sequence of screens is displayed:

  1. The standard selection screen. If the user chooses Execute , the system displays the warning SCREEN 1000 in the status bar.

  2. Once the user has confirmed the warning by choosing Enter , selection screen 500 is called as a modal dialog box. When the user chooses Execute , the system displays the warning SCREEN 500, also in a dialog box.

  3. When the user has confirmed this warning, the standard selection screen is called again, but this time as a modal dialog box. Since you cannot define the standard selection screen as a modal dialog box, the warning message displayed when the user chooses Execute appears in the status bar and not as a modal dialog box.

Consequently, you can only exit this selection screen using Cancel , since there is no Enter function in the dialog box to confirm the warning message.

Call as a Report Transaction

When creating transaction codes for report transactions , you can define any user-defined selection screen of the executable program for which you create the transaction code as the initial screen. When the program is then started using the transaction code, the user-defined selection screen and not the standard selection screen is called between the INITIALIZATION and the START-OF-SELECTION event.

Example

You create a report transaction with transaction code SELSCREEN500 for the example program above:

When you call the transaction, the executable program is started directly with selection screen 500 as a full screen. When the user chooses Execute , the warning is displayed as a modal dialog box because selection screen 500 was originally defined as a modal dialog box.

The sequence of screens then continues in the same way as described from point 2 onwards in the above example.

Call as a Dialog Transaction

You can use as the initial screen any selection screen in executable programs and module pools that are called with transaction codes for dialog transactions. The selection screen is then the first screen of a screen sequence .

You must ensure that the program flow moves on to the correct next screen during selection screen processing .

Let us consider the following module pool:

          
*&----------------------------------------------------*
          
*& Modulpool SAPMSSLS *
          
*&----------------------------------------------------*
          
INCLUDE msslstop.
          
INCLUDE msslsevt.
            

Include msslstop contains the following definition of selection screen 500:

          


          


          
*&----------------------------------------------------*
          
*& Include MSSLSTOP *
          
*&----------------------------------------------------*
          
PROGRAM sapmssls.
          
SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW.
          
SELECTION-SCREEN BEGIN OF BLOCK sel1 WITH FRAME.
          
PARAMETERS: cityfr LIKE spfli-cityfrom,
          
cityto LIKE spfli-cityto.
          
SELECTION-SCREEN END OF BLOCK sel1.
          
SELECTION-SCREEN BEGIN OF BLOCK sel2 WITH FRAME.
          
PARAMETERS: airpfr LIKE spfli-airpfrom,
          
airpto LIKE spfli-airpto.
          
SELECTION-SCREEN END OF BLOCK sel2.
          
SELECTION-SCREEN END OF SCREEN 500.
            

Include msslsevt processes the AT SELECTION-SCREEN event:

          
*------------------------------------------------------*
          
* INCLUDE MSSLSEVT *
          
*------------------------------------------------------*
          
AT SELECTION-SCREEN.
          
...
          
LEAVE TO SCREEN 100.
          


            

When we create a transaction code for program sapmssls , we enter screen 500 as the initial screen.

Transaction SELSCREEN_DIALOG starts the program and displays the selection screen.

You can process the user entries from the selection screen either at the AT SELECTION-SCREEN event, or at a later point in the application logic. When the AT SELECTION-SCREEN event (PAI of the selection screen) has been processed, the program moves on to the next screen 100.