Using Pushbuttons

Use

You can use pushbuttons on forms to allow the user to choose different functions from a dynamic document. When the user clicks the pushbutton, an event is triggered. You must register a handler method for this event in your ABAP program.

Prerequisites

You must already have created a dynamic document and added a form to it using the add_form method.

Procedure

  1. In the declaration part of your program, declare an object reference variable with the type REF TO cl_dd_button_element .
  2. In a local class in your program, write a handler method for the clicked event of class cl_dd_button_element . It does not matter whether it is a static method or an instance method. The method should contain the processing logic for what will happen when the user clicks the button.

    Remember to include the special parameter sender in the interface of the method. If you have more than one pushbutton in the dynamic document, you can use the attribute sender->name to identify which one the user actually chose.

  3. Call the add_button method for the form instance with which you are currently working.

    The method returns an object reference to the button, which you should assign to the reference variable you declared in step 1.

  4. Use the object reference to the button to register its clicked event.

By default, each element on a form is displayed on a separate line. However, it often makes sense to display a pushbutton on the same line as an associated input field. To do this, use the method line_with_layout.

Result

When the user clicks the pushbutton on the dynamic document, your handler method will be called.

In the handler method, you can access the attributes of all other elements on the form (for example, to find out the contents of an input field).

See also:

add_button