ABAP RAP

Actions

Scope

This slide set covers the standard features of the managed scenario. The following topics should be learned:

  • Actions
  • Basics of EML to implement actions

Interaction between Behavior and Implementation

After something is defined in the behavior, you can generate the corresponding methods into the implementation using Quick Assist:

Actions (Definition)

You can add custom actions. This requires updates in several artifacts:

  • Behavior - define the action
  • Implementation - implement the action
  • CDS - make the action visible in the UI

Types of actions

Distinguish between:

  • Actions - modify data (instance-related)
  • Factory actions - create instances
  • Static actions - modify data without an instance context
  • Functions - read-only operations

At most one structured importing parameter and one structured returning parameter are allowed. Objects can be passed as well.

Example: Cancel action — Cancel Tasks

Requirement: allow selecting multiple tasks in the list and cancel them with one action.

Cancel action — Behavior

The CANCEL action has no parameters and no return value. Declare it in the behavior as action cancel;

projection implementation in class zbp_c_tasks unique;
strict ( 2 );

define behavior for zc_tasks //alias <alias_name>
{
  create;
  update;
  delete;

  action cancel ;

  field ( readonly ) Author,
                     ChangedAt,
                     CreatedAt;

EML

EML is part of the ABAP language and operates on the transactional buffer.

  • Definition:
    • Entity Manipulation Language (EML) is a declarative extension used to access and manipulate entities (Business Objects) in RAP.
    • EML enables create, update and delete operations in a simplified, structured way.
    • EML is comparable to SQL's DML.
  • Use cases:
    • Used inside Behavior implementations and to manage entity state in RAP.

Cancel action — Implementation

Notes

  • IN LOCAL MODE bypasses authorization checks.
  • The FOR loop allows cancelling multiple instances.
  • Use UPDATE FIELDS( status ) to update only that field.
  • VALUE is the constructor operator; the internal table in the WITH clause can be constructed differently.

Implementation

CLASS lhc_zc_tasks IMPLEMENTATION.

  METHOD cancel.
    MODIFY ENTITIES OF zc_tasks IN LOCAL MODE
      ENTITY zc_tasks
     UPDATE FIELDS ( status )
     WITH VALUE #( FOR key IN keys ( %tky = key-%tky
                                     status = 'CANCELED' ) ).


  ENDMETHOD.

ENDCLASS.

Cancel action — CDS

The action becomes visible only after the CDS is annotated accordingly:

      @UI.lineItem:[ { position: 10 },
                     { type: #FOR_ACTION, 
                       dataAction : 'cancel', 
                       label: 'Cancel Tasks' } ]

The annotation is added to a field (for example the first shown field) to make the action available in the list UI.