Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  SAP GUI User Dialogs →  General Dynpros →  Dynpro Fields →  Screen Fields - Examples 

Dynpros, Pushbuttons

This example demonstrates how pushbuttons on dynpros can be processed.

Other versions: 7.31 | 7.40 | 7.54

Source Code

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.

Description

The static next dynpro number of dynpro 100 is 100. The screen field of output is defined as not ready for input in Screen Painter. When the user chooses a pushbutton, the PAI event is triggered. The function code of the pushbutton is assigned to the dynpro field ok_code, which is then assigned to 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. This procedure is always recommended since it makes sure that the dynpro field ok_code is also reinitialized in the PBO event and does not contain any unwanted values. 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 dynpro. If the user chooses Cancel, the program ends.