This is a test message to test the length of the message box.
Login
|
ABAP RAP Action
Created by Software-Heroes

RAP - Action

8178

In this article, we'll take a look at actions, how they are structured, and what they actually do with the RAP Business Object.

Advertising


In the last RAP articles we dealt with the topic of validations and determinations, we now want to complete this with the actions. In this article you will learn how to define actions and implement them.

 

Introduction

The easiest way to think of actions is as buttons on an interface, you can trigger them externally and they perform different steps. In most cases, data of the RAP business object is also affected. Similar to validations and determinations, they must be created in the object's behavior definition.

 

Deployment

In the first step we define two simple actions in the behavior definition, you only have to specify the "action" and a name. In this case we define two actions, one normal and one static. The two actions and their methods can be generated via CTRL + 1 in order to implement the coding later.

action fillEmptyStreets;
static action clearAllEmptyStreets;

 

So that the actions can also be used in the app or interface, they must be announced in the projection. It can only be used when it is made available to the outside world.

use action fillEmptyStreets;
use action clearAllEmptyStreets;

 

In order for the actions to now appear on the UI, the Metadata Extension must be extended. For this purpose, any field can be extended with further annotations. By expanding LineItem, the buttons appear above the list. The most important thing is the definition of the "type" and the "dataAction" so that the button is displayed and triggers the correct action.

@UI.selectionField : [ { position: 10 } ]
@UI.lineItem: [
  { position: 20, importance: #MEDIUM },
  { position: 10, type: #FOR_ACTION, label: 'Fill', dataAction: 'fillEmptyStreets' },
  { position: 20, type: #FOR_ACTION, label: 'Clear All', dataAction: 'clearAllEmptyStreets' }
]
@UI.identification: [{ position: 10, qualifier: 'PARTNER_INFO' }]
@EndUserText.label: 'Partner'
@EndUserText.quickInfo: 'Identifier of the partner'
PartnerNumber;

 

The buttons are now also displayed on the UI and can be used:

 

Finally, let's implement the two actions. The "fillEmptyStreets" action fills a data set with an empty street with a value. The "clearAllEmptyStreets" action now clears the values again, but no other streets. The implementation looks like this:

METHOD clearAllEmptyStreets.
  SELECT FROM zbs_dmo_partner
    FIELDS partner, street
    WHERE street = 'EMPTY'
    INTO TABLE @DATA(lt_partner_data).

  LOOP AT lt_partner_data INTO DATA(ls_partner).
    MODIFY ENTITIES OF ZBS_I_RAPPartner IN LOCAL MODE
      ENTITY Partner
      UPDATE FIELDS ( Street )
      WITH VALUE #( ( PartnerNumber = ls_partner-partner Street = '' %control-Street = if_abap_behv=>mk-on ) ).
  ENDLOOP.

  INSERT VALUE #(
    %msg = new_message_with_text( text = |{ lines( lt_partner_data ) } records changed|
    severity = if_abap_behv_message=>severity-success )
  ) INTO TABLE reported-partner.
ENDMETHOD.


METHOD fillEmptyStreets.
  READ ENTITIES OF ZBS_I_RAPPartner IN LOCAL MODE
    ENTITY Partner
    FIELDS ( Street )
    WITH CORRESPONDING #( keys )
    RESULT DATA(lt_partner_data).

  LOOP AT lt_partner_data INTO DATA(ls_partner) WHERE Street IS INITIAL.
    MODIFY ENTITIES OF ZBS_I_RAPPartner IN LOCAL MODE
      ENTITY Partner
      UPDATE FIELDS ( Street )
      WITH VALUE #( ( %tky = ls_partner-%tky Street = 'EMPTY' %control-Street = if_abap_behv=>mk-on ) ).
  ENDLOOP.
ENDMETHOD.

 

Actions

In the example above we used two actions, a normal "Action" and a "Static Action". The normal action is initially inactive and can only be used once one or more records in the list have been selected. The action is only performed on this record.

The second action is always active because it affects the entire object and is not dependent on a selected data record. The action is correspondingly different, because here we have to read all the keys ourselves from the database and are not handed them over.

 

Messages

Actions bring with them the possibility of returning corresponding messages to the user. In our example implementation, we printed a simple success message that generated a message toast that disappeared after a few seconds.

 

However, there is also the possibility of generating more messages here. If more messages are generated, then the form changes to a popup, if other types are used, the message is displayed differently or perhaps it has to be confirmed first.

 

Conclusion

Actions give the RAP object further possibilities to act on the data without making changes directly. The actions can be simple and change data or trigger complex actions such as reading data via an interface.


Included topics:
RAPBTPActionREX1
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Tuesday and Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ADT - RAP Extension Assistent [MIA]

Category - ABAP

You want to extend a RAP object and don't know exactly where to start? Perhaps the Extension Assistant can help you and guide you through the process step by step.

03/06/2026

ADT - RAP Analyzer [MIA]

Category - ABAP

Getting to grips with and understanding existing RAP objects can not always be easy, especially when dealing with complex objects. Questions such as which pattern is used and which objects are important usually need to be worked out.

02/24/2026

RAP - Position of Buttons

Category - ABAP

In this article, we'll look at the different button positions. Where can we place the various actions in RAP, and how do we use them?

02/17/2026

RAP - Analytical Table

Category - ABAP

Let's take a look at the last missing piece of the puzzle in RAP to replace the ALV and how we can set up the Analytical Table with minimal effort.

02/13/2026

RAP - Mixed Content

Category - ABAP

How do we actually get different content into the same column in the List Report? Let's look at a practical example using our Sales App.

02/10/2026