Programming

How to Define a Business Service with CDS and SAP Fiori Elements

In this blog post, we’ll show you how to define, register in the system, and test the business service for a sample SAP Fiori application.

 

The ABAP platform can act as both a service provider and a service consumer. That is, it can both call and consume a service and provide it to other applications. In the ABAP RESTFul application programming model, the business service is a REST-based service provided for consumption. It therefore acts as a service provider. Through the business service, the data model defined and the behavior defined are provided to the caller of the service. This service consumer will be an SAP Fiori elements application.

 

The business service consists of a service definition and a service binding. Let’s now create these two components for our application.

 

Creating a Service Definition

First, you need to create the service definition as follows:

  1. Open the context menu for the CDS projection view ZC_CERTIFICATE of the certificate management and select the entry New Service Definition.

Creating a New Service Definition

  1. Name the service definition “ZUI_Certificate_U” and assign a meaningful description to it.

Assigning a Name and Description to the Service Definition

  1. In the screen that follows next, you need to select the Define Service Confirm the creation by clicking the Finish button.

Selecting the Define Service Template

 

Now you must define the entities of the service definition by making the CDS views of the relevant entities known using the expose keyword. In our concrete case, you need to make the CDS views ZC_Certificate and ZC_Certificatestate known in this way. You don’t have to publish the _Material- Text entity, which is linked by association, because it’s only used for displaying the material description and later as a search aid for materials. Optionally, you can also assign alias names at this point to facilitate using the service.

 

The service definition now has the structure shown here:

 

@EndUserText.label: 'Service Definition for manage Certificates'

define service ZUI_Certificate {

   expose ZC_Certificate as Certificate;

   expose ZC_CertificateState as CertificateState;

   expose I_MaterialText as Material_VH;

   expose ZI_Status_VH as Status_VH;

}

 

Save and enable this service definition.

 

Creating the Service Binding

Next, you need to create the service binding. Here you define which OData you use based on the binding type:

  1. Open the context menu for the service definition you just created and select the New Service Binding 

Creating a New Service Binding

  1. Since the service is supposed to be used later as part of an SAP Fiori application, you want to select the OData V2 - UI option in the Binding Type Name the service binding “ZUI_Certificate_ODATA_O2” and assign a meaningful description to it. 

Creating the Service Binding

  1. Click the Next button to create the service binding.

You can use the Publish button to publish the service binding (see the next figure). This enables the local service endpoint for the OData service. Now your newly created OData service can be consumed.

 

Publishing the Service Binding

 

As part of the service binding, you can also launch a preview of the SAP Fiori elements application. To do this, you must select the desired root entity, here the entity with the Certificate alias, and click the Preview button.

 

Launching the SAP Fiori Elements Preview via the Service Binding

 

Because you haven’t defined any UI annotations yet, the preview currently remains empty. You can assign the UI annotations and test the user interface at this point.

 

Editor’s note: This post has been adapted from a section of the book ABAP RESTful Application Programming Model: The Comprehensive Guide by Lutz Baumbusch, Matthias Jäger, and Michael Lensch.

Recommendation

ABAP RESTful Application Programming Model
ABAP RESTful Application Programming Model

You’ve worked with ABAP, SAP Fiori, and core data services—now see how these technologies and more come together in the ABAP RESTful application programming model. Learn to develop applications optimized for SAP S/4HANA, whether your system is on-premise or in the cloud. Follow step-by-step instructions to build new ABAP applications, update legacy applications, and reuse existing source code. Make the new model work for you!

Learn More
SAP PRESS
by SAP PRESS

SAP PRESS is the world's leading SAP publisher, with books on ABAP, SAP S/4HANA, SAP IBP, intelligent technologies, SAP Business Technology Platform, and more!

Comments