Defining Business Services

Objective

After completing this lesson, you will be able to define Business Services

Business Service Definition and Binding

Development flow: business service

A business service is created in the ABAP Development Tools (ADT). The data model and service implementation are generated together by creating a service definition and service binding.

Visualization of business services for OData V2 and V4

In the area of business services, a service definition exposes CDS Views as a generic service. A service binding then marks it as a special kind of service. You can create an OData V2 or V4 service for API- or UI-usage. Service definitions and bindings are created in the ADT, the generated OData services are registered in transaction /IWFND/MAINT_SERVICE or /IWFND/V4_ADMIN respectively.

Note

For more details about developing OData V4 services in ABAP please read SAP note 2485370Development of OData V4 services using code based implementation.
Development steps: Business service

The starting point is a CDS view in the ADT. First the CDS view is exposed in the service definition defining also the entity name. Adding the service definition to a service binding generates SAP Gateway runtime artifacts when activating the service binding. These runtime artifacts are tagged as system code and are not visible or even changeable in any ABAP editor. All read operations are generated based on SADL. After registering the service, these read operations can be tested.

Write operations can only be implemented by integrating a managed runtime. But this is then separated from publishing a CDS view as SAP Gateway service.

Create a Service Definition and Binding

Screenshot flow about how to create a service definition and binding in ADT

Service definitions and bindings are ABAP repository objects and a substantial part of the business services. They can only be created and edited in the ADT. In the first step, the service definition just defines the name of the service. The CDS views are added later in the source code.

In the second step, the service binding refers to the service definition and sets the binding type, which are mainly communication protocols. The following binding types are supported:

  • Information Access (InA) to consume the service in a UI.

    InA is used to connect to the SAP HANA enterprise search.

  • Open Date (OData) V2 to consume the service in a UI or as Web API.

    Naming convention: <Name space>_UI/API_<App/API name>_02

  • Open Data (OData) V4 to consume the service in a UI or as Web API.

    Naming convention: <Name space>_UI/API_<App/API name>_04

  • Structured Query Language (SQL) to consume the service as Web API.

    SQL is used to connect to a database.

Source code and screenshot in ADT correlating service definition and binding

By exposing a CDS View in a service definition, the name of the entity set can be defined. For the entity type, "Type" is automatically appended to the entity set name.

The entity set names and navigation properties based on the associations in the CDS views are visible in the service binding on the right. For OData V2, multiple versions of a service definition can be added to a service binding visible on the left. For OData V4, multiple service definitions can be added to one service binding to allow cross-service navigation.

Publish a Service Binding

Screenshots about publishing OData V2 service endpoint in ADT

For OData V2, publishing of the local service endpoint registers the OData service in the AS ABAP of the service binding (embedded deployment). The service catalog entry is saved as a local object and can therefore not be assigned to any transport request. Publishing in ADT is meant for testing only.

Hint

You must first unpublish the local service endpoint in ADT before you can register the service and assign it to a transport request in SAP Gateway Service Maintenance.
Screenshots about publishing OData V4 service endpoint in ADT

For OData V4, activating the service binding registers a service group with the same name including all services in the SAP Gateway Backend Service Administration (/IWBEP/V4_ADMIN). The service group represents the service binding in the SAP Gateway service administration for OData V4. Changing or deleting the service binding will also change or delete the service group.

Note

It is recommended to always apply changes via the service binding, not the service group, to prevent inconsistencies.

Publishing of the local service endpoint publishes the service group in the AS ABAP of the service binding (embedded deployment). The service group is saved as a local object and can therefore not be assigned to any transport request. Publishing in ADT is meant for testing only.

An OData V4 service binding can currently not be published locally using ADT if one of the following options in the Client Administration (SCC4) applies:

  1. The client has the client role Customizing.
  2. Changes and transports for client specific objects are set to one of the options:

    1. Automatic recording of changes
    2. No changes allowed

If one of these options apply, the SAP Gateway Service Administration (/IWFND/V4_ADMIN) must be used to publish the service group. For more details, please read SAP Note 3101976Publishing OData V4 service is throwing error: Publishing of XXXXXXXXXX in Customizing client not allowed.

Define a Business Service Definition and Binding

Business Example

You are a developer or solution architect in your company. You need to implement a business service based on a CDS view.

Template:
GW100_C_ArticleNavigation (CDS Data Definition)
GW100_C_SupplierNavigation (CDS Data Definition)
Solution:
GW100_UI_SupplierList_02 (Business Service Binding)
GW100_UI_SupplierList (Business Service Definition)

Note

This exercise requires an SAP Learning system. Login information are provided by your system setup guide.

Note

You may continue with your solution of the previous exercise or copy the templates to Z##_C_ArticleList and Z##_C_SupplierList. Whenever the values or object names in this exercise include ##, replace ## with the number of your user.

Prerequisites

The CDS data definitions for supplier and article including their association were implemented in the exercises Implement OData.Publish in a CDS View and Implement a Navigation Using Associations in CDS Views.

Task 1: Create a Business Service Definition

Steps

  1. In Eclipse connected to your SAP S/4HANA (S4H) system, create the service definition Z##_UI_SupplierList in your ZGW100_##_BES package. Expose your Z##_C_Supplier data definition as Supplier and your Z##_C_Article data definition as Article.

    1. In Eclipse connected to your S4H, expand <your system>Favorite PackagesZGW100_##_BES.

    2. Right-click the ZGW100_##_BES node and choose NewOther ABAP Repository Object.

    3. In the New ABAP Repository Object popup, select Business ServicesService Definition.

    4. Choose Next.

    5. In the New Service Definition popup, in the Name field, enter Z##_UI_SupplierList.

    6. In the Description field, enter a value of your choice.

    7. Choose Next.

    8. Select your transport request and choose Next.

    9. Select the template Define Service.

    10. Choose Finish.

    11. Replace entity_name with Z##_C_Article as Articleand chooseEnter..

    12. Add expose Z##_C_Supplier as Supplier; one line beneath expose Z##_C_Article as Article;.

    13. Your code should look like this:

      Code Snippet
      12345
      @EndUserText.label: 'Supplier List ##' define service Z##_UI_SupplierList { expose Z##_C_Article as Article; expose Z##_C_Supplier as Supplier; }
    14. Choose Activate.

Task 2: Create an OData V2 Business Service Binding

Steps

  1. Create the service binding Z##_UI_SUPPLIERLIST_02 in your ZGW100_##_BES package. Choose OData V2 - UI as binding type.

    1. In Eclipse connected to your S4H, expand <your system>Favorite PackagesZGW100_##_BESBusiness ServicesService Definitions.

    2. Right-click the Z##_UI_SUPPLIERLIST node and choose New Service Binding.

    3. In the New Service Binding popup, in the Name field, enter Z##_UI_SUPPLIERLIST_02.

    4. In the Description field, enter a value of your choice.

    5. In the Binding Type dropdown, choose OData V2 - UI.

    6. Choose Next.

    7. Select your transport request and choose Finish.

    8. Choose Activate.

Task 3: Publish an OData V2 Service Binding and Test the Metadata

Steps

  1. In Eclipse connected to your S4H, publish the Z##_UI_SUPPLIERLIST_02 service binding. Test the service’s metadata.

    1. In Eclipse connected to your S4H, in the Z##_UI_SupplierList service binding, choose Publish on the right.

    2. Choose Service URL.

    3. In the Select a certificate popup, select your certificate and choose OK.

    4. Replace ?sap-client=100 with $metadata and choose Enter.

      Example

      https://<host>:<port>/sap/opu/odata/SAP/Z##_UI_SUPPLIERLIST_02/$metadata

      Result

      The Web browser displays the metadata of the service.
  2. In the SAP Gateway Service Maintenance of your S4H, check the registration of Z##_UI_SUPPLIERLIST_02. Test the service’s metadata in the SAP Gateway Client.

    1. In the SAP Easy Access of your S4H, search for SAP Gateway Service Maintenance or start transaction /IWFND/MAINT_SERVICE.

    2. In the SAP Gateway Service Maintenance, choose Filter.

    3. In the Filter for Service Catalog popup, in the Technical Service Name field, enter Z##*.

    4. Choose Continue.

    5. Select Z##_UI_SUPPLIERLIST_02.

    6. Choose SAP Gateway Client.

    7. In the SAP Gateway Client, select HTTPS as Protocol.

    8. Choose Add URI Option.

    9. In the Add URI Option popup, double-click $metadata.

    10. Choose Execute.

      Example

      /sap/opu/odata/SAP/Z##_UI_SUPPLIERLIST_02/$metadata

      Result

      The HTTP Response displays the metadata of the service.

Task 4: Test the Query and Read Operations of an OData V2 Service Binding

Steps

  1. In the SAP Gateway Client of your S4H, test the paging operation for suppliers in your service. Query the first two suppliers.

    1. In the SAP Gateway Client, choose Entity Set.

    2. In the Entity Sets popup, double-click Supplier.

    3. Choose Add URI Option.

    4. In the Add URI Option popup, double-click $top=2.

      Example

      /sap/opu/odata/SAP/Z##_UI_SUPPLIERLIST_02/Supplier?$top=2
    5. Choose Execute.

      Result

      The HTTP Response displays the first two suppliers.
  2. Test the sorting operation for suppliers in your service. Query suppliers sorted by their company name ascending.

    1. In the Request URI field, add &$orderby=CompanyName asc to the URI.

      Example

      /sap/opu/odata/SAP/Z##_UI_SUPPLIERLIST_02/Supplier?$top=2&$orderby=CompanyName asc
    2. Choose Execute.

      Result

      The HTTP Response displays the first two suppliers ordered by company name ascending.
  3. Test the filter operation for suppliers in your service. Query the suppliers whose e-mail address starts with "supplier".

    1. In the Request URI field, add &$filter=startswith(EmailAddress, 'supplier') to the URI.

      Example

      /sap/opu/odata/SAP/Z##_UI_SUPPLIERLIST_02/Supplier?$top=2&$orderby=CompanyName asc&$filter=startswith(EmailAddress, 'supplier')
    2. Choose Execute.

      Result

      The HTTP Response displays the first two suppliers ordered by company name ascending whose e-mail address starts with "supplier".
  4. Test the read operation for suppliers in your service. Read a single supplier.

    1. In the Request URI field, replace all query options by the key of a supplier with guid in front.

      Example

      /sap/opu/odata/SAP/Z##_UI_SUPPLIERLIST_02/Supplier(guid'00505604-4e85-1edd-b9b4-a81d353342c0')

      Hint

      Copy the self link of a supplier from the HTTP Response.
    2. Choose Execute.

      Result

      The HTTP Response displays the selected supplier.
  5. Test the navigation between suppliers and articles in your service. Query the articles of a supplier.

    Hint

    If no articles are found for a supplier, make sure to select a supplier with an e-mail address starting with "supplier".
    1. In the Request URI field, add /to_Article to the URI.

      Example

      /sap/opu/odata/SAP/Z##_UI_SUPPLIERLIST_02/Supplier(guid'00505604-4e85-1edd-b9b4-a81d353342c0')/to_Article
    2. Choose Execute.

      Result

      The HTTP Response displays the articles of the supplier.
  6. Test the expand operation for suppliers and articles in your service. Read a supplier including its articles.

    1. In the Request URI field, replace the / in front of to_Article with ?$expand=

      Example

      /sap/opu/odata/SAP/Z##_UI_SUPPLIERLIST_02/Supplier(guid'00505604-4e85-1edd-b9b4-a81d353342c0')?$expand=to_Article
    2. Choose Execute.

      Result

      The HTTP Response displays the supplier including its articles.

Define a Business Service Binding for OData V4

Business Example

You are a developer or solution architect in your company. You need to create a business service binding for OData V4 based on a business service definition.

Template:
GW100_UI_SupplierList (Business Service Definition)
Solution:
GW100_UI_SupplierList_04 (Business Service Binding)

Note

This exercise requires an SAP Learning system. Login information are provided by your system setup guide.

Note

You may continue with your solution of the previous exercise or copy the template to Z##_UI_SupplierList. Whenever the values or object names in this exercise include ##, replace ## with the number of your user.

Prerequisites

The data binding was created in the exercise Define a Business Service Definition and Binding.

Task 1: Create an OData V4 Business Service Binding

Steps

  1. Create the service binding Z##_UI_SUPPLIERLIST_04 in your ZGW100_##_BES package. Choose OData V4 - UI as binding type.

    1. In Eclipse connected to your S4H, expand <your system>Favorite PackagesZGW100_##_BESBusiness ServicesService Definitions.

    2. Right-click the Z##_UI_SUPPLIERLIST node and choose New Service Binding.

    3. In the New Service Binding popup, in the Name field, enter Z##_UI_SUPPLIERLIST_04.

    4. In the Description field, enter a value of your choice.

    5. In the Binding Type dropdown, choose OData V4 - UI.

    6. Choose Next.

    7. Select your transport request and choose Finish.

    8. Choose Activate.

Task 2: Publish the Service Group of an OData V4 Service Binding

Steps

  1. In the SAP Gateway Service Administration of your S4H, publish the Z##_UI_SUPPLIERLIST_04 service group for system alias LOCAL.

    1. In the SAP Easy Access of your S4H, search for SAP Gateway Service Administration or start transaction /IWFND/V4_ADMIN.

    2. In the SAP Gateway Service Administration, choose Publish Service Groups.

    3. In the System Alias field, enter LOCAL.

    4. In the Service Group ID field, enter Z##*.

    5. Choose Get Service Groups.

    6. Select Z##_UI_SUPPLIERLIST_04 and choose Publish Service Group.

    7. In the Publish Service Group popup, choose Continue.

    8. In the Enter Customizing Request popup, choose Create Request.

    9. In the Create Request popup, in the Short Description field, enter a value of your choice.

    10. Choose Save.

    11. In the Enter Customizing Request popup, choose Continue.

    12. In the Information popup, choose Continue.

    13. Choose Back.

Task 3: Test an OData V4 Service Binding

Steps

  1. In the SAP Gateway Service Administration, open the SAP Gateway Client and test the service’s metadata.

    1. In the SAP Gateway Service Administration, expand Service Groups on the left.

    2. Double-click Z##_UI_SUPPLIERLIST_04.

    3. Select the Z##_UI_SUPPLIERLIST service and choose Service Test.

    4. In the SAP Gateway Client, select HTTPS as Protocol.

    5. Choose Execute.

      Example

      /sap/opu/odata4/sap/z##_ui_supplierlist_04/srvd/sap/z##_ui_supplierlist/0001/$metadata?sap-statistics=true

      Result

      The HTTP Response displays the metadata of the service.
  2. In the SAP Gateway Client of your S4H, test the paging operation for suppliers in your service. Query the first two suppliers.

    1. In the SAP Gateway Client, select HTTPS as Protocol.

    2. Choose Entity Set.

    3. In the Entity Sets popup, double-click Supplier.

    4. Choose Add URI Option.

    5. In the Add URI Option popup, double-click $top=2.

      Example

      /sap/opu/odata4/sap/z##_ui_supplierlist_04/srvd/sap/z##_ui_supplierlist/0001/Supplier?sap-statistics=true&$top=2
    6. Choose Execute.

      Result

      The HTTP Response displays the first two suppliers.
  3. Test the sorting operation for suppliers in your service. Query suppliers sorted by their company name ascending.

    1. In the Request URI field, add &$orderby=CompanyName asc to the URI.

      Example

      /sap/opu/odata4/sap/z##_ui_supplierlist_04/srvd/sap/z##_ui_supplierlist/0001/Supplier?sap-statistics=true&$top=2&$orderby=CompanyName asc
    2. Choose Execute.

      Result

      The HTTP Response displays the first two suppliers ordered by company name ascending.
  4. Test the filter operation for suppliers in your service. Query the suppliers whose e-mail address starts with "supplier".

    1. In the Request URI field, add &$filter=startswith(EmailAddress, 'supplier') to the URI.

      Example

      /sap/opu/odata4/sap/z##_ui_supplierlist_04/srvd/sap/z##_ui_supplierlist/0001/Supplier?sap-statistics=true&$top=2&$orderby=CompanyName asc&$filter=startswith(EmailAddress, 'supplier')
    2. Choose Execute.

      Result

      The HTTP Response displays the first two suppliers ordered by company name ascending whose e-mail address starts with "supplier".
  5. Test the read operation for suppliers in your service. Read a single supplier.

    1. In the Request URI field, replace all query options by the key of a supplier in rounded brackets.

      Example

      /sap/opu/odata4/sap/z##_ui_supplierlist_04/srvd/sap/z##_ui_supplierlist/0001/Supplier(00505604-4e85-1edd-b9b4-a81d353342c0)

      Hint

      Copy the self link of a supplier from the HTTP Response.
    2. Choose Execute.

      Result

      The HTTP Response displays the selected supplier.
  6. Test the navigation between suppliers and articles in your service. Query the articles of a supplier.

    Hint

    If no articles are found for a supplier, make sure to select a supplier with an e-mail address starting with "supplier".
    1. In the Request URI field, add /_Article to the URI.

      Example

      /sap/opu/odata4/sap/z##_ui_supplierlist_04/srvd/sap/z##_ui_supplierlist/0001/Supplier(00505604-4e85-1edd-b9b4-a81d353342c0)/_Article
    2. Choose Execute.

      Result

      The HTTP Response displays the articles of the supplier.
  7. Test the expand operation for suppliers and articles in your service. Read a supplier including its articles.

    1. In the Request URI field, replace the / in front of _Article with ?$expand=

      Example

      /sap/opu/odata4/sap/z##_ui_supplierlist_04/srvd/sap/z##_ui_supplierlist/0001/Supplier(00505604-4e85-1edd-b9b4-a81d353342c0)?$expand=_Article
    2. Choose Execute.

      Result

      The HTTP Response displays the supplier including its articles.

Log in to track your progress & complete quizzes