The different behavior files in SAP RAP

I’m new in SAP RESTful application programming and I had to figure out, how the different files of behavior project, definition and implementation works.

When we create a RAP project depending on our ZCONNECTIONS database table, we receive by default the following files:

File structure of our RAP project

In this post, we focus on the arrow noted files,
where we have with the red arrow the projection file (ZC_CONNECTIONS),
with the green arrow the (root) definition file (ZR_CONNECTIONS) and
finally with the blue arrow the implementation file (ZBP_CONNECTIONS).

Behavior projection

In the projection file, we can build a simple behavior definition for our projection data definition, which means the ZC_CONNECTIONS with the blue D in the screenshot above.

projection;
strict ( 2 );
use draft;

define behavior for ZC_CONNECTIONS
use etag

{
  use create;
  use update;
  use delete;

  use action Edit;
  use action Activate;
  use action Discard;
  use action Resume;
  use action Prepare;
}

Behavior definition

With the behaviour definition, we implement the real definition depending with validation checks, actions and mapping functionalities. It is also linked to the ZR_CONNECTIONS data definition.

managed implementation in class ZBP_CONNECTIONS unique;
strict ( 2 );
with draft;

define behavior for ZR_CONNECTIONS
persistent table zconnections
draft table ZCONNECTIONS_D
etag master LocalLastChangedAt
lock master total etag LastChangedAt
authorization master( global )

{
  field ( mandatory : create )
   CarrID,
   ConnID;

  field ( readonly )
   LocalCreatedAt,
   LocalCreatedBy,
   LastChangedAt,
   LocalLastChangedAt,
   LocalLastChangedBy;

  field ( readonly : update )
   CarrID,
   ConnID;

  create;
  update;
  delete;

  draft action Edit;
  draft action Activate optimized;
  draft action Discard;
  draft action Resume;
  draft determine action Prepare;

  mapping for ZCONNECTIONS
  {
    CarrID = carr_id;
    ConnID = conn_id;
    FlightDate = flight_date;
    FlightTime = flight_time;
    TotalSeats = total_seats;
    LocalCreatedBy = local_created_by;
    LocalCreatedAt = local_created_at;
    LocalLastChangedBy = local_last_changed_by;
    LocalLastChangedAt = local_last_changed_at;
    LastChangedAt = last_changed_at;
  }
}

Behavior implementation

Now via quick fix, we can create an implementation in our behavior implementation file. Notice that we have here a local class within a global class definition. So to switch between the local and global class we need to switch at the bottom of our Eclipse environment via the tabs:

Our implementation in the local class will now provide in the future method with the additional signature FOR VALIDATE ON SAVE and the IMPORTING parameter KEYS, which can be later queried with the Entity Manipulation language (EML). These methods will allow to implement custom ABAP logic.

CLASS LHC_ZR_CONNECTIONS DEFINITION INHERITING FROM CL_ABAP_BEHAVIOR_HANDLER.
  PRIVATE SECTION.
    METHODS:
      GET_GLOBAL_AUTHORIZATIONS FOR GLOBAL AUTHORIZATION
        IMPORTING
           REQUEST requested_authorizations FOR ZR_CONNECTIONS
        RESULT result.
ENDCLASS.

CLASS LHC_ZR_CONNECTIONS IMPLEMENTATION.
  METHOD GET_GLOBAL_AUTHORIZATIONS.
  ENDMETHOD.
ENDCLASS.

Comments

One response to “The different behavior files in SAP RAP”

  1. Bohdan Petrushchak Avatar
    Bohdan Petrushchak

    Hi Julian,

    Thank you ! RAP model with all of its entities and interdependencies is quite complicated and sometimes mind-boggling. I’ve already implemented three simple RAP BOs – two of them without RAP generator, but I’m still having some doubts about the relationships & dependencies between all of these objects.

    But what I definitely do not understand is this: why is all custom ABAP logic associated with RAP BO residing in the local ABAP class ? We have defined a global class for behavior implementation and it is essentially empty. So what is the reasoning / justification behind this approach ? Do you have any insights on that ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ad blocker detected

We have detected that you are using extensions to block ads. Please support us by disabling your ad blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock