Preface – This post is part of the SAP ABAP RAP series.
Table of Contents
Introduction
Using persistent data sources, we are going to implement a query for the OData service to get an application with the read-only feature. This OData service will be consumed by the Fiori Element application.
This article will provide the step-by-step guide to build a read-only list reporting application.
- Create data model with CDS views.
- Add associations to CDS views for navigation purpose.
- Add relevant annotations.
- Changing UI field labels and description
- Create OData service
- Create a Service Definition
- Expose CDS views
- Create Service Binding
- Publish OData service
- Application preview
Create data model with CDS views
Procedure
- Launch ADT (ABAP Development Tool).
- Select package for your development.
- Right-click on package and choose NEW > Other Repository Objects > Core Data Services > Data Definition.
- Provide the details (Name, Description).
- Select Next and provide the Transport Request number.
- Select Finish.
Result Screen
An inactive version of the data definition is created. You need to provide the data source name and add the elements in the CDS views. Similarly, create all the required CDS views.
Figure 2: Generated Template code
Add associations to CDS views for navigation purpose
- Define association and cardinality
- Define mapping condition
- Add association element list in CDS view
Add relevant annotations
Add required annotations to fields (see the below figure).
Changing UI field labels and description
UI field labels and description allows you to customize your UI application. You can add text annotation (@ObjectModel.text.association:'<_AssocToTextProvider>’),value help (@Consumption.valueHelpDefinition: [{ entity: { name: ‘<target_view>’ , element: ‘<target_element>’ }}]), search capability ( @Search.searchable: true ) and as many functionality to your field element.
Create OData service
a. Create a service definition
In service definition, we will expose our data models.
Procedure
- Launch ADT (ABAP Development Tool).
- Select package for your development.
- Right-click on package and choose NEW > Other Repository Objects > Business Service > Service Definition.
- Provide the details (Name, Description).
- Select Next and provide the Transport Request number.
- Select Finish.
b. Expose CDS views
In service definition, add the CDS view that you want to expose to UI. You can provide an alias also for the same. Once the CDS views are exposed, activate the service definition.
c. Create Service Binding
In service definition, we will expose our data models.
Procedure
- Launch ADT (ABAP Development Tool).
- Select package for your development.
- Right-click on the package and choose NEW > Other Repository Objects > Business Service > Service Binding.
- Provide the details (Name, Description).
- Select Next and provide Transport Request number.
- Select Finish.
When you open the created service binding from editor you can see the below screen. As soon as the service binding is created, it is registered in your local system.
Activate the service binding and it is ready for consumption.
d. Publish OData service
Once you activate the service binding, the OData service is published and is activated in SAP Gateway. Now it can be consumed by UI5 application.
The service URL on the right side will provide the metadata information of OData service. Preview button will navigate you to the resulting UI service.
Application preview
The resulting UI5 application will look like this:
0 Comments