Pushbuttons on the Selection Screen 

Similar to pushbuttons on screens , pushbuttons on selection screens can also be defined with function codes. To create a pushbutton on the selection screen you use the following statement during the definition of the selection screen:

SELECTION SCREEN PUSHBUTTON [/]pos(len) push
 USER-COMMAND fcode [MODIF ID key].

The [/]pos(len) parameters and the MODIF ID addition have the same function as for the formatting options for underlines and comments.

push determines the pushbutton text. For push, you can specify a text symbol or a field name with a maximum length of eight characters. This character field must not be declared with the DATA statement, but is generated automatically with length len. The field must be filled before the selection screen is called.

For fcode, a standard table has to be specified. When the user clicks on the pushbutton on the selection screen, the runtime environment triggers the AT SELECTION-SCREEN event and the function code fcode is transferred to the ucommcomponent of the interface work area sscrfields. You must use the TABLESstatement to declare the sscrfieldsstructure in the ABAP program.

After the AT SELECTION-SCREEN event has been processed, the system displays the selection screen again. The only way to exit the selection screen and carry on processing the program is to choose Execute (F8). Consequently, the pushbuttons are more suitable for controlling dynamic modifications of the selection screen than for controlling the program flow.

You can only see the pushbuttons of a selection screen if you call that screen. However, standard selection screens in executable programs are only called if they contain at least one input field declared using the PARAMETERS or SELECT-OPTIONS statements. This means that pushbuttons on a standard selection screen which do not include at least one input field are pointless. User-defined selection screens, on the other hand, can be called even if they do not contain an input field. In this case pushbuttons, on selection screens without input fields, are possible.

Example

REPORT demo_sel_screen_pushbutton.

TABLES sscrfields.

DATA flag(1) TYPE c.

SELECTION-SCREEN:
 BEGIN OF SCREEN 500 AS WINDOW TITLE tit,
 BEGIN OF LINE,
 PUSHBUTTON 2(10) but1 USER-COMMAND cli1,
 PUSHBUTTON 12(10) text-020 USER-COMMAND cli2,
 END OF LINE,
 BEGIN OF LINE,
 PUSHBUTTON 2(10) but3 USER-COMMAND cli3,
 PUSHBUTTON 12(10) text-040 USER-COMMAND cli4,
 END OF LINE,
 END OF SCREEN 500.

AT SELECTION-SCREEN.

 CASE sscrfields.
 WHEN 'CLI1'.
 flag = '1'.
 WHEN 'CLI2'.
 flag = '2'.
 WHEN 'CLI3'.
 flag = '3'.
 WHEN 'CLI4'.
 flag = '4'.
 ENDCASE.

START-OF-SELECTION.

 tit = 'Four Buttons'.
 but1 = 'Button 1'.
 but3 = 'Button 3'.

 CALL SELECTION-SCREEN 500 STARTING AT 10 10.

 CASE flag.
 WHEN '1'.
 WRITE / 'Button 1 was clicked'.
 WHEN '2'.
 WRITE / 'Button 2 was clicked'.
 WHEN '3'.
 WRITE / 'Button 3 was clicked'.
 WHEN '4'.
 WRITE / 'Button 4 was clicked'.
 WHEN OTHERS.
 WRITE / 'No Button was clicked'.
 ENDCASE.

This example defines four pushbuttons on a selection screen that is displayed as a dialog box. The selection screen is defined in a statement chain for keyword SELECTION-SCREEN.

If the text symbols text-020 and text-040 are defined as 'Button 2' and 'Button 4', the four pushbuttons appear as follows on the selection screen displayed as a dialog box.

This graphic is explained in the accompanying text

cli1, cli2, cli3and cli4 are used for fcode. If the user chooses a pushbutton, the runtime environment triggers the AT SELECTION-SCREEN event. Only once the user selects execute  does the program continue after CALL SELECTION-SCREEN.