By

Create Behavior Definition for BO-Part 2

To save data properly using Behavior definition Data mapping is important. As of now field names are different in our BO entity and the table /dmo/travel_m where we want to store the data.

Travel Entity:

Code snippet showing data field mappings for travel-related identifiers including travel_id, agency_id, and customer details.

Travel Table:

Code snippet defining a database table for travel management, including fields like travel_id, customer_id, booking_fee, total_price, and status.

For example Root entity field is TravelId and table field is travel_id.

Let’s start with mapping.

  1. Open the BDEF ZHA_SA_TRAVEL and add mapping fields for /dmo/travel_m,
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 ( authorization : global );
update;
delete;
// field ( readonly ) TravelId;
association _Booking { create; }
mapping for /dmo/travel_m{
TravelId = travel_id;
AgencyId = agency_id;
CustomerId = customer_id;
BeginDate = begin_date;
EndDate = end_date;
TotalPrice = total_price;
CurrencyCode = currency_code;
BookingFee = booking_fee;
LastChangedAt = last_changed_at;
LastChangedBy = last_changed_by;
CreatedAt = created_at;
CreatedBy = created_by;
OverallStatus = overall_status;
Description = description;
}
}
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; }
mapping for /dmo/booking_m{
TravelId = travel_id;
BookingId = booking_id;
BookingDate = booking_date;
CustomerId = customer_id;
CarrierID = carier_id;
ConnectionId = connection_id;
FlightDate = flight_date;
CurrencyCode = currency_code;
BookingStatus = booking_status;
LastChangedAt = last_changed_at;
}
}
define behavior for ZHA_SA_BOOKSUPPL alias BookingSuppl
persistent table /dmo/booksuppl_m
lock dependent by _Travel
authorization dependent by _Travel
etag master LastChangedAt
{
update;
delete;
field ( readonly ) TravelId, BookingId;
association _Travel;
association _Booking;
mapping for /dmo/booksuppl_m{
TravelId = travel_id;
BookingId = booking_id;
BookingSupplementId = booking_supplement_id;
SupplementId = supplement_id;
price = price;
CurrencyCode = currency_code;
LastChangedAt = last_changed_at;
}
}

Save and activate

2. We will check if we are able to save data now.

3. Run the application

Screenshot of a menu or list in a software application, highlighting options related to Fiori Elements App and ABAP Test Class.
Screenshot of SAP Fiori Elements App preview interface, displaying filter fields for Travel ID, Agency ID, Customer ID, Total Price, and Description, with a 'Go' button highlighted for submitting travel requests.
Screenshot of a travel requests management interface showing fields for Travel ID, Agency ID, Customer ID, and Overall Status, with a list of travel requests including their statuses and a highlighted 'Create' button.

Click on create button to create the travel data

Enter details and Click create

A user interface for travel booking in SAP, displaying fields for Travel ID, Customer ID, Agency ID, Description, starting and end dates, booking fee, total price, and currency code, with a 'Create' button highlighted.

Create Booking details

Screenshot of a travel booking interface with accepted status, showing travel details including Travel ID, Customer ID, agency information, dates, and pricing in USD.
A screenshot of a booking details interface displaying fields for Customer ID, Flight Number, Airline ID, Flight Date, Flight Price, Currency Code, and Booking Status.

Create Supplement Details

Screenshot of an SAP booking interface showing booking details including customer ID, flight number, airline ID, flight date, flight price, and booking status, along with a 'Create' button highlighted.
Screenshot of SAP interface showing 'Supplement Details' section with fields for 'Product Price' set to 400.00 and 'Currency Code' input labeled 'USD'.

Object is created

Screenshot of SAP interface showing supplement details, including product price of 400.00 USD and currency code USD.

Now, let’s see the Travel ID in search.

As you can see Travel ID created successfully with managed behavior definition.

Screenshot of the SAP Fiori Elements App preview displaying travel request fields including Travel ID, Agency ID, Customer ID, Total Price, Description, and Overall Status.

Thanks for reading!

Leave a Reply

Discover more from HANAxABAP

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

Continue reading