ABAP Keyword Documentation → ABAP − Reference → ABAP RESTful Programming Model → Business Service
Business Service Definition
Other versions:
7.31 | 7.40 | 7.54
Syntax
[@EndUserText.label: 'label_text']
[Annotation]
[Annotation]
...
DEFINE SERVICE service_name
{
EXPOSE
CDS_entity_name [AS CDS_entity_alias];
[EXPOSE CDS_entity_name [AS CDS_entity_alias]; ...]
EXPOSE projection_view_name [AS projection_view_alias];
[EXPOSE projection_view_name [AS projection_view_alias]; ...]
}
Effect
The business service definition (or service definition for short) is a repository object that enables a consumer-specific perspective on the underlying data model. The service definition defines which CDS entities and which data model of the behavior are provided for consumption as part of the business service.
If a business object is to be made available, the following entities are to be provided in the service definition:
- Target entities for the compositions and associations in the business object
- The CDS view of the value help provider and the text provider, to use the value help and the text assignments
The service definition is independent of the type of service protocol (for example, OData) used for the business service.
The following points apply for the syntax of the service definition:
- Optionally, the service definition can start with the CDS annotation @EndUserText.label. The annotation value label_text describes the service definition and consists of a string with a maximum of 60 characters.
- Annotations @Scope: [#SERVICE] can be specified in the service definition before the statement DEFINE SERVICE.
- The service definition name service_name follows the Naming Conventions and Namespaces of the repository objects.
- The CDS entities to be provided as part of the business service are grouped together in brackets {...}, each after the keyword EXPOSE. Optionally, you can assign an alias, which is defined after the keyword AS. The aliases are then used instead of the names of the CDS entities when the business service is accessed.
- According to the CDS syntax rules, every EXPOSE statement ends with a semicolon.
Remarks
- A CDS entity or a business model can be made available by multiple service definitions in different contexts.
- The service definition must be associated with at least one service binding.
Example
In the following example, the data from the ABAP flight data reference scenario (or flight data scenario for short) is used. It represents a legacy business logic that can be used to create and edit flight bookings. The CDS view /DMO/I_Travel represents the root node Travel of the business object for managing flight trips.
The underlying data model and the behavior of the root entity Travel are described in ABAP BDL - Example. The data model example defines
- The root entity /DMO/I_Travel with composition /DMO/I_Booking and associations to the CDS entities /DMO/I_Agency, /DMO/I_Customer, I_CurrencyText, and/DMO/I_Status_Text
- The child entity /DMO/I_Booking with associations to the CDS entities /DMO/I_Travel, /DMO/I_Customer, /DMO/I_Carrier, and /DMO/I_Connection
- The CDS views of the value help provider and the text provider DMO/I_Customer, /DMO/I_Carrier, /DMO/I_Connection, I_CurrencyText, /DMO/I_Agency, and /DMO/I_Status_Text
The following example shows the service definition /DMO/I_Travel_SD for the business object Travel:
define service /DMO/I_TRAVEL_SD
{
expose /DMO/I_Travel as Travel;
expose /DMO/I_Booking as Booking;
expose /DMO/I_Agency as Agency;
expose /DMO/I_Customer as Customer;
expose I_CurrencyText as Currency;
expose /DMO/I_Status_Text as Status;
expose /DMO/I_Carrier as Carrier;
expose /DMO/I_Connection as Connection;
}