Entering content framePushbuttons on the Screen Locate the document in its SAP Library structure

Pushbuttons are the only elements of screens that trigger the PAI event when the user chooses them. 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 Reading 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:

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 LIKE 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 itself. 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 OUTPUT has 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 CASE structure, 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