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

RAP - Determination

2348

How is data automatically derived and enriched in the ABAP RESTful Programming Model? We will look into this question in this article.



Last week we dealt with validation and how you can use it to keep your business object clean. This week we will go into the automatic derivations and how you don't have to let the user fill in all fields.

 

General

A determination can take the work out of filling in fields with information that might come from other data sources. Or information is derived if the user forgets to fill it in. A determination can be simple or complex, but in the end it also ensures that the data in the business object is complete.

 

Creation

In the first step, let's create a determination in our business object, for this we define it in the behavior definition and give the appropriate properties:

determination fillCurrency on modify { create; update; }

 

Here "on modify" and "on save" are available, which trigger the determination differently. "On Modify" triggers every time the data changes and the user enters something new in a field. Above all, quick determinations that do not consume so much performance should be carried out here. "On Save" is only triggered when the data is saved in the save sequence and is particularly suitable for performance-intensive tasks. As with validation, fields and events are available in the curly brackets. Here you can adjust the determination accordingly granular.

You can then generate the method in the class again with CTRL + 1 and do not have to create it manually. The method definition now looks like this:

METHODS fillcurrency FOR DETERMINE ON MODIFY
  IMPORTING keys FOR partner~fillcurrency.

 

Hint: A determination only has to be defined at the level of the interface, since it applies at all times and does not have to and cannot be given to the outside in the projection layer.

 

Implementation

The method interface is very straightforward and contains fewer parameters than with the validations. As always, the affected keys are passed, the only return we have is the table for messages in case something goes wrong during the derivation.

 

Our derivation is correspondingly simple, we read the transferred key and check whether the PaymentCurrency field is filled. If this is not the case, then we set a default value so that the field does not remain empty. The implementation then looks like this:

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

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

 

Hint: In this case, a commit must not be set because we are currently processing the business object. If you try anyway, you will receive an error message from the compiler and activation is not possible.

 

Test

In the next step, we test the determination once in the app. To do this, we create a new data record and fill in the key and the mandatory country field. We created the mandatory field in the last article on validation:

 

After saving, we now get the following image, the currency has been set to default and no longer needs to be filled.

 

Conclusion

The determination is a good way to enrich missing information, you can share fast and slow determinations well and call them up according to the performance. Slow determinations make sense especially when saving, because a change is called up after each field.


Included topics:
RAPBTPDetermination
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 - Translation app (example)

Category - ABAP

Let's take a look at a practical example of developing a RAP application in the ABAP environment and how you can create an app with little effort.

08/02/2024

RAP - Custom Entity Value Help (Deep Dive)

Category - ABAP

With the Custom Entity you have the most freedom in RAP when developing ABAP Cloud applications, but what about potential errors?

07/12/2024

RAP - Deep Action in OData v4

Category - ABAP

In this article we will look at actions with deep structures, how we can create them and pass data to an API endpoint.

05/24/2024

BTP - Connect On-Premise (Consumption Model v2)

Category - ABAP

In this article we want to provide another update on the connection of on-premise systems and how this is done with a communication arrangement.

12/15/2023

RAP - Show app count (Tile)

Category - ABAP

This example is about displaying a counter on the tile of a Fiori Elements application and how such a thing can be implemented.

10/06/2023