Entering content frame

Pushbuttons on the Screen Locate the document in its SAP Library structure

Pushbuttons were originally the only elements of screens that trigger the PAI event when the user chooses them. As of release 4.6, you can also assign checkboxes, radio buttons and dropdown boxes to function codes. In the attributes of a pushbutton, you can specify a function code up to 20 characters long.

Pushbuttons have a label - the text that you specify statically in the attributes - and can also have icons. If you set the Output field attribute for a pushbutton, you can also set its text dynamically in the ABAP program. To do this, you must create a field in the ABAP program with the same name as the pushbutton. You must then assign the required text to the field before the screen is displayed. You can also assign icons to dynamic texts on pushbuttons by including the icon code in the text. The icon codes are all contained in the include program <ICON>. For example, the ICON_CANCEL (This graphic is explained in the accompanying text) icon has the code @0W@.

In each PAI event, the function code, as long as it is not empty, is placed in the system field syst-ucomm (sy-ucomm) and assigned to the OK_CODE field. Empty function codes are placed in neither the sy-ucomm field nor the OK_CODE field. The function code of a pushbutton is empty if you have not entered it in the corresponding attribute in the Screen Painter. Before you can work with the OK_CODE field, you must assign a name to it in the Screen Painter. For further information, refer to Evaluating Function Codes.

The main way of allowing users to choose functions that trigger the PAI event and send function codes to the program is through the GUI status. The main reason is one of space - the GUI status can contain many more functions than you would be able to place on the screen as pushbuttons.

However, you should use pushbuttons in the following cases:

        Very important and frequently-used function codes that should appear on the screen as well as in the GUI status, for example, the Execute, Display, and Change functions on the initial screen of the ABAP Editor.

        Applications that only use pushbuttons, where function codes in the GUI status make no sense - for example, in a calculator application. The function codes of the corresponding pushbuttons have no corresponding function in the GUI status elements, and only exist as attributes of screen elements.

        When you have a GUI status that is used for a large number of screens, but use it on screens that have a particular function that is not required anywhere else. In this case, you should place it on the screen as a pushbutton.

When you define pushbuttons, you must ensure that your function code is either the same as a corresponding function in the GUI status, or does not accidentally coincide with the function code of an entirely different function. Although the consistency of function codes in GUI statuses is checked in the Menu Painter, this is not possible for pushbuttons, since the GUI status of a screen is not known until runtime.

Example

Pushbuttons on screens.

PROGRAM demo_dynpro_push_button.

DATA: ok_code TYPE sy-ucomm,
      save_ok LIKE ok_code,
      output(8) TYPE c.

CALL SCREEN 100.

MODULE user_command_0100 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'BUTTON_EXIT'.
      LEAVE PROGRAM.
    WHEN 'BUTTON_1'.
      output = 'Button 1'(001).
    WHEN 'BUTTON_2'.
      output = 'Button 2'(002).
    WHEN 'BUTTON_3'.
      output = 'Button 3'(003).
    WHEN 'BUTTON_4'.
      output = 'Button 4'(004).
    WHEN OTHERS.
      
output = save_ok.
  ENDCASE.
ENDMODULE.

The next screen (statically defined) for screen 100 is 100. It has the following layout:

This graphic is explained in the accompanying text

The part of the element list relevant for the screen fields is as follows:

Name

Type

Format

Text

Function Code

output

I/O

CHAR

 

 

BUTTON1

Push

 

Pushbutton 1

BUTTON_1

BUTTON2

Push

 

Pushbutton 2

BUTTON_2

BUTTON3

Push

 

Pushbutton 3

BUTTON_3

BUTTON4

Push

 

Pushbutton 4

BUTTON_4

EXIT_BUTTTON

Push

 

Cancel

BUTTON_EXIT

ok_code

OK

OK

 

 

The input option for the screen field outputhas been switched off in the Screen Painter.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.

PROCESS AFTER INPUT.
  MODULE user_command_0100.

When the user chooses a pushbutton, the PAI event is triggered. The function code of the pushbutton is assigned to the screen field ok_code , which is then passed onto the ABAP field with the same name. The module user_command_0100 is then processed.

Firstly, the contents of the ok_code field are copied to the auxiliary variable save_ok code, and ok_code is initialized. You should always do this, since it ensures that the screen field ok_code has always been initialized before the PBO event and can therefore not unintentionally contain an incorrect value.

Next, in the CASEstructure, a text symbol is assigned to the output field according to the button that the user chose. This is displayed in the output field on the screen. If the user chooses Cancel, the program ends.

 

 

 

Leaving content frame