Referencing a Data Source

Objective

After completing this lesson, you will be able to reference a data source

Data Source Reference

Development flow: Referenced data source

A data source is referenced in the SAP Gateway Service Builder (SEGW). The data model and service implementation are generated together by referencing a CDS view as data source.

Development steps: Data source reference

The starting point is a project in the SEGW. First the CDS view is referenced as data source. This reference already includes entity types and entity sets as well as associations and association sets if selected. Generating the runtime artifacts includes generating the source code for all read operations based on SADL. After registering the service, these read operations can be tested.

Write operations can be implemented by integrating a managed runtime or implementing the CUD-methods directly. But this is then separated from referencing a CDS view as data source.

Screenshot flow about how to reference a data source in SEGW

Choose ReferenceData Source on the Data Model node of the SAP Gateway project and enter the CDS data definition in the CDS-Entity field. After that, you can include additional data definitions by selecting the according associations.

Screenshots of data source reference in SEGW

The Data Source References are visible as an own node in the Data Model. Expand CDS-Entity Exposures to see the created entity types, entity sets, associations, and association sets based on the referenced data definitions. These elements can only be changed by changing the reference. You can switch between the external OData names and the internal data definition names by choosing the External Names respectively Internal Names button.

Under Runtime Artifacts, a complete set of editable provider classes is generated and available as usual for SAP Gateway projects. This offers full access to the ABAP implementation without limitations. But the Service Implementation node stays empty. This is because code mapping is not supported for referenced data sources.

The Service Implementation will be populated if the data model is extended directly without referencing a data source. So it is possible to combine the declarative way of creating a data model with a generated data model, based on a data source reference. For the declarative part, code mapping is then possible.

Create an SAP Gateway Service by Referencing a Data Source

Business Example

You are a developer or solution architect in your company. You want to implement a SAP Gateway service by referencing a CDS view as data source.

Template:
None
Solution:
GW100_S_REFERENCE (SAP Gateway Project)

Note

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

Note

Whenever the values or object names in this exercise include ##, replace ## with the number of your user.

Prerequisites

The packages were created in exercise Define a Data Model Based on a Data Dictionary Structure .

Task 1: Create an SAP Gateway Project for Referencing a Data Source

Steps

  1. In the SAP Gateway Service Builder of your SAP S/4HANA (S4H) system, create a new project named ZGW100_##_REFERENCE in your ZGW100_##_BES package.

    1. In the SAP Easy Access of your S4H, search for SAP Gateway Service Builder or start transaction SEGW.

    2. In the SAP Gateway Service Builder, choose Create Project.

    3. In the Create Project popup, enter the following values:

      FieldValue
      ProjectZGW100_##_REFERENCE
      Descriptionyour choice
      PackageZGW100_##_BES
    4. Choose Continue.

    5. Choose Save.

    6. In the Prompt for transportable workbench request popup, in the Request field, select the transport request provided to you.

    7. Choose Continue.

Task 2: Reference a CDS View as Data Source

Steps

  1. Create a referenced data source for the CDS view GW100_C_Supplier, including a navigation to articles.

    1. Right-click the Data Model node and choose ReferenceData Source.

    2. In the Reference Data Source Wizard popup, in the CDS-Entity field, enter GW100_C_Supplier.

    3. Choose Next.

    4. Choose _ARTICLE as selected.

    5. Choose Finish.

    6. Choose Save.

  2. Generate the runtime objects and add them to your package ZGW100_##_BES.

    1. Choose Generate Runtime Objects.

    2. In the Model and Service Definition popup, to accept the proposed names, choose Continue.

    3. In the Package field, enter ZGW100_##_BES.

    4. Choose Save.

    5. For every popup, choose the transport request provided to you.

Task 3: Register the SAP Gateway Service and Test the Query and Read Operations

Steps

  1. In the SAP Gateway Service Builder of your S4H, register and activate the service in your S4H using your ZGW100_##_FES package.

    1. Double-click the Service Maintenance node.

    2. Right-click the LOCAL_GW system.

    3. Select Register.

    4. ChooseYes that you will be redirected to the service maintenance.

    5. In the Select System Alias (Hub to Backend) popup, in the System Alias field, enter LOCAL.

    6. Choose Continue.

    7. In the Add Service popup, in the Package Assignment field, enter ZGW100_##_FES.

    8. Choose Continue.

    9. For every popup, choose the transport request provided to you.

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

    1. Choose SAP Gateway Client.

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

    3. Choose Entity Set.

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

    5. Choose Add URI Option.

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

      Example

      /sap/opu/odata/SAP/ZGW100_##_REFERENCE_SRV/Supplier?$top=2
    7. 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/odata/SAP/ZGW100_##_REFERENCE_SRV/Supplier?$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/odata/SAP/ZGW100_##_REFERENCE_SRV/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".
  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 with guid in front.

      Example

      /sap/opu/odata/SAP/ZGW100_##_REFERENCE_SRV/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.
  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 /to_Article to the URI.

      Example

      /sap/opu/odata/SAP/ZGW100_##_REFERENCE_SRV/Supplier(guid'00505604-4e85-1edd-b9b4-a81d353342c0')/to_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 to_Article with ?$expand=

      Example

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

      Result

      The HTTP Response displays the supplier including its articles.

Log in to track your progress & complete quizzes