This post talks about Determine Actions in ABAP RESTful Application Programming Model. This would be one of the most confusing concept from RAP Behavior.

Determine actions allow the consumer to execute determinations and validations on request. Determinations can be usually triggered as side effects which are triggered automatically when some fields are updated on the application.

For Determine Actions case, determinations on save and validations are assigned to a determine action and execute it like any other action.

Determine action is available in Managed RAP BOs, Unmanaged and draft-enabled RAP BOs and Projection BOs (only reuse).

Here is an example of few determinations. Not that these are not determine actions.

1. determination CalculateTravelID on save { create; } 
2. determination CalculateTotalPrice on modify { field BookingFee; } 
3. side effects { field BookingFee affects field TotalPrice; }

1. The determination CalculateTravelID is called in create mode when save is triggered

2. The determination CalculateTotalPrice is called when field BookingFee is updated in modify mode

3. This is a side effect that helps show the fields updated via determination reflect immediately on the application.

However, we can assign the determinations to a determine action so that these can be called as actions.

  determine action trigger_all
  {
    determination ( always ) setID;
    determination ( always ) SalesOrderItem ~ TotalPrice;
  }

Syntax for Defining Determine Actions

The syntax for Determine action is as below.

[internal] determine action
          [(authorization:none  | authorization:update)]
           DetermineActionName [extensible]
          {
           determination [(always)] MyDetermination1;
           determination [(always)] MyDetermination2;
           validation [(always)] MyValidation1;
           validation [(always)] MyValidation2;
           determination [(always)] Child~ChildDetermination;
           validation [(always)] Child~ChildValidation;
           ...
          }

[internal] – The determine action can be only triggered by the RAP BO.

[(authorization:none | authorization:update)] – The authorization can be excluded or authorization implemented for update operation can be used.

DetermineActionName – Action name. For example, trigger_actions

[extensible] – The addition extensible can be used to allow BDEF extensions.

determination [(always)] MyDetermination1; – determination is the keyword and MyDetermination1 is the name of the determination. Similarly validation and validation name can be used.

always – If the optional addition always is used, then all determinations and validations that are part of the determine action are executed regardless of their trigger conditions.

The keywords draft determine action define similar determine action for drafts.

Determinations and validations of child entities can be included using the child~childDetermination or child~childValidation. These validations and determinations should not include delete as the trigger operation.

Messages and failed keys

Determinations and validations assigned to determine actions can return messages to the REPORTED structure, but the failed keys are ignored.

As mentioned earlier, determine action is available in Managed RAP BOs, Unmanaged and draft-enabled RAP BOs and Projection BOs (only reuse).

  • Managed RAP BOs – determine actions do not require an implementation; the determinations and validations included in a determine action must be implemented.
  • Unmanaged and draft-enabled RAP BOs – both determine actions and the determinations and validations included must be implemented in a method FOR MODIFY

Below code example shows, how the multiple determinations can be added in a single determine action.

Sample code for the determine action trigger_all 

First, code the individual determinations.

define behavior for DEMO_SALES_CDS_SO_3 alias SalesOrder
...
{
...
determination setID on save { create; }
...
}
define behavior for DEMO_SALES_CDS_SO_I_3 alias SalesOrderItem
...
{
...
determination TotalPrice on save { create; }
...
}

"... means that there can be other/multiple code lines

Then, combine the determinations into a determine action.

determine action trigger_all
{
  determination ( always ) setID;
  determination ( always ) SalesOrderItem ~ TotalPrice;
}

The determine action can be called in the behavior pool by using EML code as below.

MODIFY ENTITIES OF demo_sales_cds_so_3
       ENTITY SalesOrder
       EXECUTE trigger_all
       FROM VALUE #( ( sokey = '0894EF1643A01EDB90EE45FBFB0C7DAA' )
                     ( sokey = '0894EF1643A01EDB90EE45FBFB0C9DAA'   ) )
                     "Here, keys are hard-coded only for demonstration. 
       MAPPED FINAL(mapped)
       FAILED FINAL(failed)
       REPORTED FINAL(reported).

 COMMIT ENTITIES.

We can use this concept of Determine Actions to trigger determinations at certain point in the behavior regardless whether or not the triggering conditions are met.

Reference: https://help.sap.com/docs/btp/sap-abap-restful-application-programming-model/determine-actions

Visit ABAP RESTful Application Programming Model to explore all articles on ABAP RAP Model.


If you like the content, please subscribe…

Join 4,016 other subscribers

Discovering ABAP YouTube Channel