By

Create Behavior Definition for BO

Description

In the 𝗥𝗘𝗦𝗧𝗳𝘂𝗹 𝗔𝗕𝗔𝗣 𝗣𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴 𝗠𝗼𝗱𝗲𝗹 (𝗥𝗔𝗣), a 𝗕𝗲𝗵𝗮𝘃𝗶𝗼𝗿 𝗗𝗲𝗳𝗶𝗻𝗶𝘁𝗶𝗼𝗻 describes the behavior of a 𝗕𝘂𝘀𝗶𝗻𝗲𝘀𝘀 𝗢𝗯𝗷𝗲𝗰𝘁 (𝗕𝗢)—in other words, which operations are allowed on it.

  • The 𝗕𝘂𝘀𝗶𝗻𝗲𝘀𝘀 𝗢𝗯𝗷𝗲𝗰𝘁 (𝗕𝗢) has the same name as its 𝗿𝗼𝗼𝘁 𝗲𝗻𝘁𝗶𝘁𝘆.
  • The 𝗥𝗔𝗣 𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸 𝗮𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗰𝗮𝗹𝗹𝘆 𝗴𝗲𝗻𝗲𝗿𝗮𝘁𝗲𝘀 the required code for standard 𝗖𝗥𝗨𝗗 (𝗖𝗿𝗲𝗮𝘁𝗲, 𝗥𝗲𝗮𝗱, 𝗨𝗽𝗱𝗮𝘁𝗲, 𝗗𝗲𝗹𝗲𝘁𝗲) operations for the BO.
  • Based on the 𝗯𝗲𝗵𝗮𝘃𝗶𝗼𝗿 𝗱𝗲𝗳𝗶𝗻𝗶𝘁𝗶𝗼𝗻, the RAP framework determines whether the scenario is 𝗺𝗮𝗻𝗮𝗴𝗲𝗱 or 𝘂𝗻𝗺𝗮𝗻𝗮𝗴𝗲𝗱.
  • A 𝗕𝘂𝘀𝗶𝗻𝗲𝘀𝘀 𝗢𝗯𝗷𝗲𝗰𝘁 can have only one 𝗕𝗲𝗵𝗮𝘃𝗶𝗼𝗿 𝗗𝗲𝗳𝗶𝗻𝗶𝘁𝗶𝗼𝗻.

Steps

  1. Go to root Entity >> Right Click >> New Behavior Definition
Screenshot of a software interface displaying various options for creating a new behavior definition in the ZHA_SA_DATA project.

2. Choose Implementation Type(Managed or Unmanaged ) and Click Next. Behavior definition will be created with all the entities.

User interface for creating a new Behavior Definition in programming model, displaying fields for Project, Package, Name, Description, Original Language, Root Entity, and Implementation Type.

3. Provide valid alias names.

managed implementation in class zbp_ha_sa_travel1 unique;
strict ( 2 );
define behavior for ZHA_SA_TRAVEL1 alias Travel
//persistent table <???>
lock master
authorization master ( instance )
//etag master <field_name>
{
create ( authorization : global );
update;
delete;
field ( readonly ) TravelId;
association _Booking { create; }
}
define behavior for zha_sa_booking1 alias Booking
lock dependent by _Travel
authorization dependent by _Travel
//etag master <field_name>
{
update;
delete;
field ( readonly ) TravelId, BookingId;
association _Travel;
association _BookingSupplement { create; }
}
define behavior for zha_sabooksuppl1 alias BookingSuppl
persistent table /dmo/booksuppl_m
lock dependent by _Travel
authorization dependent by _Travel
//etag master <field_name>
{
update;
delete;
field ( readonly ) TravelId, BookingId, BookingSupplementId;
association _Travel;
association _Booking;
}


4. Provide the table names, data will be written by RAP in this table.

//Create BDEF
define behavior for ZHA_SA_TRAVEL1 alias Travel
persistent table /dmo/travel_m
lock master
authorization master ( instance )
//etag master <field_name>
{
create ( authorization : global );
update;
delete;
field ( readonly ) TravelId;
association _Booking { create; }
}

We have a class in behavior definition zbp_ha_sa_travel1 where you can optionally write code.

Also, if you noticed “strict ( 2 );” Keyword which indicates strict SAP guidelines needs to be followed for the development, else errors will be appear at the time of activation.

“Lock master” handles the lock-unlock.

“authorization master(instance) handles the security of data”

authorization master( instance )

“etag master is the timestap field”

etag master LastChangedAt

5. This is managed scenario, so we are asking the RAP to autogenerate crud data.

managed implementation in class zbp_ha_sa_travel unique;
strict ( 2 );
define behavior for ZHA_SA_TRAVEL alias Travel
persistent table /dmo/travel_m
lock master
authorization master ( instance )
etag master LastChangedAt
{
//Create BDEF
create ( authorization : global );
update;
delete;
//field ( readonly ) TravelId;
association _Booking { create; }
}
define behavior for ZHA_SA_BOOKING alias Booking
persistent table /dmo/booking_m
lock dependent by _Travel
authorization dependent by _Travel
etag master LastChangedAt
{
update;
delete;
field ( readonly ) TravelId;
association _Travel;
association _BookingSupplement { create; }
}
define behavior for ZHA_SA_BOOKSUPPL alias BookingSuppl
persistent table /dmo/booksuppl_m
lock dependent by _Travel
authorization dependent by _Travel
//etag master <field_name>
{
update;
delete;
field ( readonly ) TravelId, BookingId;
association _Travel;
association _Booking;
}

All the code will be generated once we activate the BDEF.

6. Create Behavior Definition Projection Layer

Screenshot of a software interface for creating a new behavior definition, displaying fields for project, package, name, description, original language, root entity, and implementation type.
projection;
strict ( 2 );
define behavior for zha_sa_travel_proj //alias <alias_name>
{
use create;
use update;
use delete;
use association _Booking { create; }
}
define behavior for zha_sa_booking_proj //alias <alias_name>
{
use update;
use delete;
use association _Travel;
use association _BookingSupplement { create; }
}
define behavior for zha_sa_booksuppl_proj //alias <alias_name>
{
use update;
use delete;
use association _Travel;
use association _Booking;
}

7. Provide the alias names for all the entities

projection;
strict ( 2 );
define behavior for zha_sa_travel_proj alias Travel
{
use create;
use update;
use delete;
use association _Booking { create; }
}
define behavior for zha_sa_booking_proj alias Booking
{
use update;
use delete;
use association _Travel;
use association _BookingSupplement { create; }
}
define behavior for zha_sa_booksuppl_proj alias BookingSuppl
{
use update;
use delete;
use association _Travel;
use association _Booking;
}

Save and Activate

7. Run the FIORI Application

A screenshot of an interface displaying an entity set and associations related to travel bookings, including options like 'Open Fiori Elements App Preview' and 'New ABAP Test Class'.
Screenshot of an SAP Fiori Elements interface with input fields for Travel ID, Agency ID, Customer ID, Total Price, Description, and Overall Status, including a highlighted 'Create' button and a section for viewing or managing travel requests.

As you can see Create Button is available now.

New lines can be created clicking upon the Create button

User interface for creating a new travel object in SAP, featuring fields for Travel ID, Customer ID, Agency ID, Description, starting and ending dates, overall status, booking fee, total price, and currency code.

8. Create the implementation class, at least basic implementation we need to display data.

Screenshot of a software interface for creating a new ABAP behavior class, with fields for project, package, name, description, original language, and behavior definition.
CLASS lhc_Travel DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
IMPORTING keys REQUEST requested_authorizations FOR Travel RESULT result.
METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION
IMPORTING REQUEST requested_authorizations FOR Travel RESULT result.
ENDCLASS.
CLASS lhc_Travel IMPLEMENTATION.
METHOD get_instance_authorizations.
ENDMETHOD.
METHOD get_global_authorizations.
ENDMETHOD.
ENDCLASS.

Save and activate

Before(No data displayed)

Screenshot of the SAP Fiori Elements app interface displaying fields for Travel ID, Agency ID, Customer ID, Total Price, Description, and Overall Status, along with a table showing travel requests and a message indicating no data found.

After:( Data is visible, also you can see delete button is enabled once we select any line)

Screenshot of a travel request management system displaying various travel requests with their IDs, agency affiliations, and overall statuses such as 'Open', 'Accepted', and 'Rejected'.

We will continue the RAP journey in the next article.

Thanks for reading!

Leave a Reply

Discover more from HANAxABAP

Subscribe now to keep reading and get access to the full archive.

Continue reading