This is a test message to test the length of the message box.
Login
ABAP RAP Popup Default values
Created by Software-Heroes

RAP - Popup Default values

923

How can you provide the user with default values in the popup of an action in RAP? In this article we will extend our application.



In the last article, we expanded the popup in our application to include mandatory fields that are checked in the UI. In this article, we'll look at defining default values in the popup.

 

Introduction

When a user triggers an action in the Fiori Elements UI, you usually want to have some information from the user. To make life easier for the user, you can also provide default values in many situations so that the user receives suggestions for input and thus works faster. To do this, we will extend our Report Pattern app with another function.

 

Extension

In this section, we will extend our existing action and implement the logic for the values. Finally, we will run a test to validate the result.

 

Behavior definition

To do this, we will extend our current definition of the "LoadExcelContent" action in the behavior definition. We are currently using a simple action with a parameter, which ensures that a popup is displayed when triggered.

action LoadExcelContent parameter ZBS_S_DRPExcelPopup;

 

To do this, we add DEFAULT FUNCTION in curly brackets to define a new function in which we can set the default values.

action LoadExcelContent parameter ZBS_S_DRPExcelPopup { default function GetDefaultsForExcelPopup; }

 

The name of the function must begin with "GetDefaultsFor" or "GetDfltsFor". Here you already get the information

 

Behavior implementation

If you place the cursor on the name of the function, you can use CTRL + 1 to generate the method in the behavior implementation. Let's take a look at the signature of the new method.

 

We receive the keys of the currently selected entries and can return our values via RESULT. There, next to the key, you will find the %PARAM field, where our parameter structure is defined. To do this, we define a small logic that defines a standard for the comment with the current currency. In addition, the test run flag should always be set for the currency EUR.

LOOP AT keys INTO DATA(key).
  INSERT VALUE #( %tky = key-%tky ) INTO TABLE result REFERENCE INTO DATA(new_line).

  new_line->%param-EventComment = |Default event for { key-Currency }|.
  new_line->%param-TestRun      = SWITCH #( key-Currency
                                            WHEN 'EUR'
                                            THEN abap_true
                                            ELSE abap_false ).
ENDLOOP.

 

Projection

Now comes the most important step. So that the function can be called from the frontend, we have to release it in the projection of our RAP object to the outside. In this case, it is not an action, but a function. Accordingly, the implementation looks like this:

use function GetDefaultsForExcelPopup;

 

Test

Now that we have everything prepared, we can carry out the test in our application. To do this, we open the currency EUR and trigger the action. You can see the result here.

 

Complete example

You can find the complete application in our GitHub repository, we have made the changes to this article in the following commit. There you will find all changes and changed objects at a glance.

 

Conclusion

Setting the default values is easy and flexible with the function, but you also have to implement some logic rather than just a simple assignment. The user will now be able to work with your application faster.

 

Source:
SAP Help - Defaulting Input Parameters for Operations
SAP Community - Defaulting action parameters


Included topics:
RAPBTPPopupDefault values
Comments (0)



And further ...

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


RAP - Popup Mandatory Fields

Category - ABAP

How can you actually define required fields for a popup in RAP? In this article we will go into the details in more detail.

01/14/2025

RAP - Deep Table Action

Category - ABAP

Is it currently possible to pass tables to actions in RAP? This article is intended to provide a better insight into the topic.

01/07/2025

ABAP Cloud - Programming Model

Category - ABAP

Which programming model is used with ABAP Cloud and what can we learn from its predecessor? More details in the article.

01/03/2025

RAP - Side Effects

Category - ABAP

How can you update parts of the Fiori UI without doing a complete refresh? With Side Effects, this is easily possible in ABAP and RAP.

12/27/2024

RAP - Events

Category - ABAP

How can you actually create events in RAP and process them with ABAP? Here you can find out more about event-driven processing.

12/23/2024