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:

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.
Leave a Reply