In the last article, we created projection layer for Travel BO( Business Object). Today, we will create Service for the created BO.
Steps:
- Create Service Definition
Right click on ABAP on Cloud package




@EndUserText.label: 'Travel processor service definition'
define service ZHA_SA_SD_TRAVEL_PROCESSOR {
expose ZHA_SA_TRAVEL_PROCESSOR as Travel;
expose ZHA_SA_BOOKING_PROCESSOR as Booking;
expose ZHA_SA_BOOKING_SUPPL_PROCESSOR as BookSuppl;
expose /DMO/I_Agency as Agency;
expose /DMO/I_Customer as Customer;
expose /DMO/I_Carrier as Carrier;
expose /DMO/I_Connection as Connection;
expose /DMO/I_Supplement as Supplement;
expose I_Currency as Currency;
expose I_Country as Country;
expose /DMO/I_Overall_Status_VH as TravelStatus;
expose /DMO/I_Booking_Status_VH as BookingStatus;
}
2. Create Service Binding for Odata V2



Publish Odata


3. Create Service Binding for Odata V4


Save and Activate
Publish Odata service

4. Test run
Open V2 Odata >> Select Travel Entity >> Click Service URL


Open V4 Odata >> Select Travel Entity >> Click Service URL


Default service document for Odata V2 is xml, however for Odata V4 it is json.
Output
Odata V2 for Customer Entity
/sap/opu/odata/sap/ZHA_SA_SB_TRAVEL_PROC_V2/Customer?sap-client=100&$format=json

Odata V4 for Customer Entity
/sap/opu/odata4/sap/zha_sa_sb_travel_proc_v4/srvd/sap/zha_sa_sd_travel_processor/0001/Customer?sap-client=100

As you can see in Odata V2, we have metadata information for every record, which is not in Odata V4.
Therefore, Odata V4 is light weight as compared to Odata V2 and latest format.
5. Test Fiori application
Go to Odata V2 service binding >> Right click on Travel Entity >> Launch Fiori Elements App Preview


Go to Settings >> Select all columns


Go to Adapt Filters >>Select required filters >> Click Ok



Click Go

You can see the data is loaded

6. Create Metadata(MDE) File
Why MDE file needed?
In the current Fiori element report, we need to select the columns and filters every time we open the Fiori elements, which is not good for user experience.
In the metadata file, we will set the default user experience.
Steps:
Pre-requisite:
Add @Metadata.allowExtensions: true extension in Travel processor projection view.
- Right click on Travel processor projection view >> New Metadata Extension



@Metadata.layer: #PARTNER
annotate entity ZHA_SA_TRAVEL_PROCESSOR with
{
@UI.selectionField: [{ position : 10 }]
TravelId;
@UI.selectionField: [{ position : 20 }]
AgencyId;
@UI.selectionField: [{ position : 30 }]
CustomerId;
// BeginDate;
// EndDate;
// BookingFee;
@UI.selectionField: [{ position : 40 }]
TotalPrice;
// CurrencyCode;
@UI.selectionField: [{ position : 50 }]
Description;
@UI.selectionField: [{ position : 60 }]
OverallStatus;
// CreatedBy;
// CreatedAt;
// LastChangedBy;
// LastChangedAt;
/* Associations */
// _Agency;
// _Booking;
// _Currency;
// _Customer;
// _OverallStatus;
}
Now, Launch the Fiori elements again
You can see the selection fields coming by default.

Add UI annotation for column display
@Metadata.layer: #PARTNER
annotate entity ZHA_SA_TRAVEL_PROCESSOR with
{
@UI.selectionField: [{ position : 10 }]
@UI.lineItem: [{ position : 10 }]
TravelId;
@UI.selectionField: [{ position : 20 }]
@UI.lineItem: [{ position : 20 }]
AgencyId;
@UI.selectionField: [{ position : 30 }]
@UI.lineItem: [{ position : 30 }]
CustomerId;
@UI.lineItem: [{ position : 40 }]
BeginDate;
// EndDate;
// BookingFee;
@UI.selectionField: [{ position : 40 }]
@UI.lineItem: [{ position : 50 }]
TotalPrice;
// CurrencyCode;
@UI.selectionField: [{ position : 50 }]
Description;
@UI.selectionField: [{ position : 60 }]
@UI.lineItem: [{ position : 60 }]
OverallStatus;
// CreatedBy;
// CreatedAt;
// LastChangedBy;
// LastChangedAt;
/* Associations */
// _Agency;
// _Booking;
// _Currency;
// _Customer;
// _OverallStatus;
}
Click on Go

And, you can see the columns displayed.

Thank for visiting!
Sangeeta Singh

Leave a Reply