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.
First, you need to create the service definition as follows:
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.
Next, you need to create the service binding. Here you define which OData you use based on the binding type:
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.
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.
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.