7.3    Modeling an OData Service

OData model creation is at the heart of application development in SAP Gateway. In this section, we’ll give you an overview of the OData service modeling methods and discuss in detail the different modeling phases for an OData service.

There are two ways to create OData services with SAP Gateway:

  1. Service development
    This is a code-based option and is very flexible for developing highly efficient and specialized services.
  2. Service generation
    This is a quicker approach to building a service with a lot less effort. There are three options to generate SAP Gateway services with this approach, which you can choose from (see
    Figure 7.22):

In the service-creation process, there are three main phases (see Figure 7.22):

OData Service-Creation Process

Figure 7.22    OData Service-Creation Process

Application developers can then create services in several ways and implement them by binding to the existing data sources or new data sources.

We covered the basic concepts of OData and SAP Gateway Service Builder in the previous sections. In the next sections, we’ll look at the different steps for the service development and service-generation processes.

7.3.1    Importing OData Services

To reduce the time required to create entity types and complex types in your data model, SAP Gateway Service Builder provides various import options, used for both the service-development and service-generation processes. In this section, we’ll look at the options for importing OData services. Under the Data Model folder (shown in Figure 7.23), you’ll see different entries in which you can create different OData entities.

The first step to model an OData service is to create entity types and assign them some properties. You can create the entity types manually, you can import them (from the context menu, under Import, choose Data Model from File, DDIC Structure, RFC/BOR Interface, or Search Help), or you can redefine the services (from the context menu, under Redefine, choose BOPF, OData, BW Query, or GenIL).

In the sections that follow, we’ll walk through the different functions shown in Figure 7.23 that can be used to import a data model: Data Model from File, DDIC Structure, RFC/BOR Interface, and Search Help.

Import Functions

Figure 7.23    Import Functions

Data Model from File

The Data Model from File function allows you to import the data model from files such as EDMX files (created using Microsoft Visual Studio) or XML files (metadata files). An EDMX file is an XML file that defines the conceptual model, a storage model, and the mapping between these models. To import the EDMX file, right-click Data Model and choose ImportData Model from File. This opens the File Import wizard.

Follow these steps to use the wizard:

  1. Click Browse to import the data model file (see Figure 7.24).
    Importing File

    Figure 7.24    Importing File

  2. Select the data model file, then click Open (see Figure 7.25). Click Next.
    Selecting EDMX File

    Figure 7.25    Selecting EDMX File

  3. Click Allow to grant access to the file (see Figure 7.26).
    Granting Access

    Figure 7.26    Granting Access

  4. Click Finish, and you’ll see the data model imported into the project (see Figure 7.27).
Imported Data Model

Figure 7.27    Imported Data Model

DDIC Structure

These data dictionary objects connect the database layer and the SAP application layer. For every transparent table, there is a physical table on the database. When a table is activated, a physical table definition is created in the database that the table definition stores in the ABAP Data Dictionary (DDIC). You can import views, database tables, or structures using the DDIC structure import method. You can then reuse the structure to develop new entity types and complex types easily, reducing the development time significantly.

To use this option, follow these steps:

  1. Right-click Data Model, then choose ImportDDIC Structure to open the DDIC Structure Import wizard.
  2. Enter the Name, and select an ABAP Structure. Click Next (see Figure 7.28).
    Importing DDIC Structure

    Figure 7.28    Importing DDIC Structure

  3. Select the parameters/fields and click Next (see Figure 7.29).
    Selecting Parameters

    Figure 7.29    Selecting Parameters

  4. Click Finish, and you’ll see the data model imported into the project (see Figure 7.30).
    Imported DDIC StructureDDIC structureimport

    Figure 7.30    Imported DDIC Structure

RFC/BOR Interface

The ABAP back-end system includes powerful tools to generate services quickly based on data from different SAP applications. Standard SAP APIs such as RFCs, BAPIs, or Business Object Repository (BOR) make it easier to get data from different SAP Business Suite applications. This approach is commonly used, because most SAP Gateway OData services are based on remote function modules. This function again reduces the development time needed to create entity types in your data model. Using this function, you can import existing data sources and create new entity types easily by reusing the imported sources.

To import the RFC/BOR, right-click Data Model, then choose ImportRFC/BOR Interface. This opens the RFC/BOR Import wizard. At the end of this section, we’ll show you how to create an OData service using this method (see Figure 7.31).

Importing RFC/BOR InterfaceRFC/BOR interface

Figure 7.31    Importing RFC/BOR Interface

Search Help

The Search Help function allows you to import and reuse an existing search help from the system to create a new entity type. To enable the import of search help, follow these steps:

  1. Right-click Data Model, then choose ImportSearch Help. This opens the Import from Search Help wizard.
  2. Enter the Entity Type Name, then select the Import Search Help field. Click Next (see Figure 7.32).
    Selecting Search Help

    Figure 7.32    Selecting Search Help

  3. Select the parameters and click Next (see Figure 7.33).
    Selecting Parameters

    Figure 7.33    Selecting Parameters

  4. Click Finish, and you’ll see the search help imported into the project (see Figure 7.34).
    Imported Search HelpSearch help

    Figure 7.34    Imported Search Help

So far, we’ve reviewed the different import methods available in SAP Gateway Service Builder. Next, let’s build a data model using one of the import methods and generate an OData service.

Exercise

In this exercise, we’ll show you how to create a data model and generate an OData service by importing the RFC/BOR interface. In this scenario, we’ll be using a Sales Order Header data (BOR) example.

Create a Project

The first step is to create a project by following these steps:

  1. Log in to the ABAP back-end server, and run Transaction SEGW.
  2. Create a new project by clicking inline image.
  3. Enter the Project name and Description, then click Local Object (see Figure 7.35).
New Project

Figure 7.35    New Project

Import the BOR Interface to Create the Entity Types

Next, you need to import the BOR interface. Follow these steps:

  1. Right-click on Data Model, select Import, then click RFC/BOR Interface (see Figure 7.36).
    Importing RFC/BOR

    Figure 7.36    Importing RFC/BOR

  2. As shown in Figure 7.37, enter the Entity Type Name.
    Selecting BOR

    Figure 7.37    Selecting BOR

  3. From the Type dropdown, select Business Object Repository.
  4. Click on the Name field and press (F4) to get the list of BOR methods.
  5. From the list shown in Figure 7.38, expand EpmSalesOrder, then select GetList.
    GetList MethodGetList

    Figure 7.38    GetList Method

  6. Click Continue inline image.
  7. You should now see the selected BOR method in the Name field. Click Next (see Figure 7.39).
    BOR Method

    Figure 7.39    BOR Method

  8. Select Soheaderdata(), then click Next (see Figure 7.40).
    Sales Order Header

    Figure 7.40    Sales Order Header

  9. In the next screen, you’ll see all the entities of Soheaderdata; Sales Order ID (SO_ID) is automatically selected as a Key. Click Finish, and make sure there are no errors (see Figure 7.41).
    Sales Order ID

    Figure 7.41    Sales Order ID

    The Entity Sets and the Service Implementation are automatically created, as shown in Figure 7.42.
    New Project

    Figure 7.42    New Project

  10. Save your project by clicking inline image.
Map to Data Source

In this step, you map the parameters of the data source with the properties of the entity set. Follow these steps:

  1. Right-click GetEntitySet(Query), then select Map to Data Source (see Figure 7.43).
    Map Entity to Data Source

    Figure 7.43    Map Entity to Data Source

  2. As shown in Figure 7.44, from the Type dropdown list, select Business Objects Repository.
    Data Source AttributesData sourceattribute

    Figure 7.44    Data Source Attributes

  3. Enter “EmpSalesOrder.GetList” in the Name field.
  4. Click Continue inline image.
  5. Click on the Propose Mapping button to map the fields, and you’re automatically provided with the mapping proposal between entity sets and the data source. SAP Gateway Service Builder automatically performs certain checks to verify the mapping (see Figure 7.45).
    Propose Mapping

    Figure 7.45    Propose Mapping

  6. Save your project by clicking inline image.
Generate Runtime Objects

The next step is to generate runtime objects:

  1. Select the project, and then click Generate inline image. On the next screen, you’ll see the model and service definition details.
  2. Click Continue inline image, or press (Enter) (see Figure 7.46).
    Generating Runtime ObjectsRuntimeobjects

    Figure 7.46    Generating Runtime Objects

  3. On the Create Object Directory Entry screen, click Local Object (see Figure 7.47).
Saving Local Object

Figure 7.47    Saving Local Object

You should now be able to see the generated MPC, DPC, and service registration details under the Runtime Artifacts folder (see Figure 7.48).

Runtime Artifacts

Figure 7.48    Runtime Artifacts

Register the OData Service

In this step, you’ll register the service to the SAP Gateway hub. If the SAP Gateway deployment is a hub deployment, then you must register the technical detail service with the SAP Gateway system. The following are the steps to register a service with the system. If your deployment is an embedded deployment (i.e., SAP Gateway components are deployed in the SAP Business Suite), then you can skip this step because the technical details will be registered automatically.

Follow these steps:

  1. Right-click the SAP Gateway hub system under the Service Maintenance folder, and select Register (see Figure 7.49).
    Registering Service

    Figure 7.49    Registering Service

  2. Press (F4) to select the system, select the SAP Gateway system, and click Continue inline image.
  3. Select Local Object, then click Continue inline image (see Figure 7.50).
    Selecting Package

    Figure 7.50    Selecting Package

Activate the OData Service

Now that you’ve registered the service, it’s time to activate it in the SAP Gateway server. Follow these steps:

  1. Run Transaction IWFND/MAINT_SERVICE.
  2. Click the Add Selected Services button.
  3. Enter “LOCAL” in the System Alias field.
  4. Enter “ZSALES*” as the External Service Name and press (Enter).
  5. Select ZSALESORDER_HEADER_SRV, then click the Add Selected Services button (see Figure 7.51).
    Adding Selected Service

    Figure 7.51    Adding Selected Service

  6. Select Local Object, then click Continue inline image (see Figure 7.52).
    Adding ServiceODataadd service

    Figure 7.52    Adding Service

  7. In the pop-up that appears, click Continue inline image (see Figure 7.53).
    Information Pop-up

    Figure 7.53    Information Pop-up

Test the OData Service

Now that you’ve successfully modeled, generated, and registered the service, you need to test it. Follow these steps:

  1. Go back to the Activate and Maintain Services screen by clicking inline image.
  2. Filter the service that you just activated by clicking the Filter button.
  3. On the Filter for Service Catalog screen, enter “ZSALESORDER_HEADER_SRV” in the External Service Name field, then click Continue inline image (see Figure 7.54).
    Service Name

    Figure 7.54    Service Name

  4. Select the service and click the Gateway Client button, as shown in Figure 7.55.
    Service CatalogServicecatalog

    Figure 7.55    Service Catalog

  5. The SAP Gateway client opens with the Sales Order Header service. Click the Execute button (see Figure 7.56).
    Testing Service

    Figure 7.56    Testing Service

    You should now receive the HTTP response with the status code 200 (see Figure 7.57).
    HTTP Response

    Figure 7.57    HTTP Response

  6. To view the sales order data, add SoheaderdataSet to the following Request URI: /sap/opu/odata/sap/ZSALESORDER_HEADER_SRV/ (see Figure 7.58). Click Execute.
    Request URIURI

    Figure 7.58    Request URI

In the HTTP Response area, you’ll see the sales order header information with the status code 200 (see Figure 7.59).

Sales Order Header Set

Figure 7.59    Sales Order Header Set

In this section, you learned how to create a data model by using import methods. In the next section, we’ll show you a different way to generate an OData model, by redefining an existing service.

7.3.2    Redefining OData Services

Using SAP Gateway Service Builder, you can redefine a service from an existing OData service that was created using SAP Gateway and from the external services developed using different back-end frameworks (SAP BW query service, GenIL Service). In this section, we’ll give an overview of each of these functions. Figure 7.60 shows the dropdown to access the Redefine option.

Redefine Functions

Figure 7.60    Redefine Functions

You use redefining techniques when you want to extend an existing data model by adding new entities, adding a new property to an existing entity, or adding an association or navigation property. Using these redefining methods, you can quickly and easily build a data model and extend it in SAP Gateway Service Builder. After the extended data model is generated, SAP Gateway Service Builder generates a new OData service with the new changes you added in the data model.

In the sections that follow, we’ll go through the options shown in Figure 7.60.

BOPF Service

The BOPF service allows you to consume business objects in the Business Object Processing Framework (BOPF) by using SAP Gateway BOPF Integration (GBI). This framework is based on object-oriented ABAP, which provides a set of generic services and functionalities to speed up and modularize development. To use this option, follow these steps:

  1. Right-click Data Model and choose RedefineBOPF Service. This opens the BOPF Configuration wizard.
  2. Select the Business Object and the Default Query, then click Next (see Figure 7.61).
    BOPF ConfigurationBOPF

    Figure 7.61    BOPF Configuration

  3. In the Service Registration area, enter descriptions in the Description fields for the Model Name and the Service Name. Click Next (see Figure 7.62).
    Entering Descriptions

    Figure 7.62    Entering Descriptions

  4. Select the fields and click Finish. You should now see the fields from the business objects added to your project (see Figure 7.63).
    Redefining BOPF

    Figure 7.63    Redefining BOPF

OData Service (GW)

Using the OData Service (GW) function, you can extend an existing OData service created in an SAP Gateway OData service. You can not only extend the existing OData service but also overwrite an existing one by using this function in SAP Gateway Service Builder. In Chapter 9, Section 9.2, we’ll explain the step-by-step process of how to extend a transactional app by redefining it using this method.

To access this option, right-click Data Model and choose RedefineOData Service (GW). This opens the OData Service wizard (see Figure 7.64).

OData Service

Figure 7.64    OData Service

BW Query Service

Using the BW Query Service function, you can create SAP Fiori apps on an SAP BW query. The SAP BW Easy Queries feature provides an external interface for accessing analytic queries in SAP BW. At the end of this section, we’ll show you how to create a data model and how to generate an OData service using this function.

To use this option, right-click Data Model and choose RedefineBW Query Service. This opens the Service Generator for BW Query Service wizard (Figure 7.65). The Query Name field is where you enter the name of the SAP BW query. We’ll discuss this method in greater detail in an exercise at the end of this section.

SAP BW Query Service

Figure 7.65    SAP BW Query Service

GenIL Service

Generic Interaction Layer (GenIL) is the connection between the Business Object Layer (BOL) and the back-end business engine. This layer handles the data transfer from the BOL to the APIs of the business engine. By using this function in SAP Gateway Service Builder, you can create a data model from this framework.

To access this option, right-click Data Model and choose RedefineGenIL Service. Using the input help will list all the GenIL objects that are available (see Figure 7.66). A plug-in in SAP Gateway Service Builder provides a wizard that will guide you through the steps to create a service using this framework.

GenIL ServiceGenIL

Figure 7.66    GenIL Service

OData Service

This function lets you create a data model on an existing OData service. This function is different from the OData Service (GW) option, because the latter will let you redefine an OData service generated using SAP Gateway. In this function, you define the HTTP Destination and the Service Namespace.

To use this function, follow these steps:

  1. Right-click Data Model and choose RedefineOData Service. This opens the External Service wizard.
  2. Enter the HTTP Destination, Service Namespace, and Service Name. Click Next (see Figure 7.67).
    Service Name

    Figure 7.67    Service Name

    OData Service Example

    We used an example OData service: http://services.odata.org/Northwind/Northwind.svc. You need to define this RFC destination using Transaction SM59.

  3. Enter descriptions in the Description fields for the model and service, then click Next (see Figure 7.68).
  4. Select the fields and click Finish on the last screen to create a data model in the project.
Service Registration Details

Figure 7.68    Service Registration Details

Next, we’ll round out this section with an example exercise.

Exercise

Let’s look at a use case in which a customer needs a custom SAP Fiori app on an SAP BEx query. To achieve this, you first need to understand how to generate an OData service based on an SAP BEx query, which we’ll explain next. We made a copy of the 0FIN_PA_T10_Q0001 query and saved it as Z0FIN_PA_T10_Q0001. We’ll be using this query in the remainder of this section.

The following sections walk through the individual steps.

Enable External Access to an SAP BEx Query

The first step is to enable the SAP BW query for external access:

  1. Open the SAP BEx query Z0FIN_PA_T10_Q0001 in the SAP BEx query designer.
  2. Go to the Extended tab in the Properties of the query.
  3. Check the By Easy Query box, then save the query (see Figure 7.69).
Allowing External Access

Figure 7.69    Allowing External Access

Generate OData Service

In this step, you’ll generate an OData service on top of an SAP BEx query:

  1. Log in to the front-end server, and run Transaction SEGW.
  2. Create a new project by clicking inline image.
  3. Enter the project technical name and description, then click Continue inline image (see Figure 7.70).
    Create Project

    Figure 7.70    Create Project

  4. Right-click the Data Model folder and choose RedefineBW Query Service (see Figure 7.71).
    Selecting SAP BW Query Service

    Figure 7.71    Selecting SAP BW Query Service

  5. Select Controller for Easy Queries (SAP BW) from the Access Type dropdown.
  6. Click inline image to open the list of queries (see Figure 7.72).
    Query Name

    Figure 7.72    Query Name

  7. You should now see the query for which you set the easy query property, as shown in Figure 7.73.
    Selecting SAP BW Query

    Figure 7.73    Selecting SAP BW Query

  8. Click Continue inline image.
  9. You should now see the SAP BEx query in the Query Name field. Click the Next button.
  10. Enter descriptions for the model name and service name, then click Next (see Figure 7.74).
    Entering Description

    Figure 7.74    Entering Description

  11. Select all services by clicking inline image, then click Finish (see Figure 7.75).
    Selecting All Objects

    Figure 7.75    Selecting All Objects

    You should now see the data model with the Entity Types, Associations, Entity Sets, and so on (see Figure 7.76).
    Redefined Data ModelDatamodel

    Figure 7.76    Redefined Data Model

  12. Generate the runtime objects by selecting the project folder and clicking Generate inline image.
  13. You’ll see the technical details of the MOD, DPC, and service. Click Continue inline image (see Figure 7.77).
    Runtime ArtifactsRuntimeartifacts

    Figure 7.77    Runtime Artifacts

  14. Select Local Object.
Add the Service to SAP Gateway

In this section, you’ll add the service to SAP Gateway. Follow these steps:

  1. Run Transaction IWFND/MAINT_SERVICE.
  2. Click Add Service.
  3. Search for the external service named “ZNETSALES_SRV”.
  4. Select ZNETSALES_SRV, then click the Add Selected Services button (see Figure 7.78).
    Adding Selected Service

    Figure 7.78    Adding Selected Service

  5. Click Continue inline image (see Figure 7.79).
    Adding Service

    Figure 7.79    Adding Service

  6. Click Continue inline image again to close the information pop-up.
Test the Service

In this section, you’ll finally test the service. Follow these steps:

  1. Click Back to return to the Activate and Maintain screen.
  2. Filter Service Catalog for “ZNETSALES_SRV”.
  3. Select the service, then click Gateway Client (see Figure 7.80).
    Testing Service

    Figure 7.80    Testing Service

  4. Click Execute to test the service (see Figure 7.81).
SAP BW Query Elements

Figure 7.81    SAP BW Query Elements

7.3.3    Include SAP Gateway OData Service

The methods we discussed in Section 7.3.1 and Section 7.3.2 are limited to the scope of the underlying data source. The third way to create an OData service is through mashups. The Include function is used when you want to combine your existing data model with a different data model; for example, you can mash up two or more services to form a completely new service without changing the existing service. You can access the Include Service Creation wizard by right-clicking Data Model and choosing IncludeOData Service (GW) (see Figure 7.82).

Include Services

Figure 7.82    Include Services

Enter the Technical Service Name and Version, then click Continue inline image (see Figure 7.83).

Technical Service Name

Figure 7.83    Technical Service Name