Skip to Content

SAP HANA XS Advanced, Creating a Simple OData Service

Creating a Simple OData Service
You will learn

Create a simple OData service connecting to your table and data.

jung-thomasThomas JungJanuary 5, 2021
Created by
ccmehil
September 6, 2016
Contributors
jung-thomas
ccmehil

Prerequisites

  • Step 1

    Right mouse click on the core_xsjs/lib/xsodata folder and choose New->File.

    New file

    Enter the name as businessPartners.xsodata and click OK.

    file name
  • Step 2

    You want to define an OData service to expose the business partner table. This table is in defined in the BusinessPartners.hdbtable artifact.

    MD.BusinessPartners

    The syntax of the XSODATA service is relatively easy for this use case. You need only define a namespace (your package path), the name of the HANA Table you will base the service from (MD.BusinessPartner) and the name or alias of the OData entity (BP). Therefore the content of the XSODATA file would be:

    text
    Copy
    service {
    "MD.BusinessPartner" as "BusinessPartners";
    }
    
    odata service

    You can ignore the error marker in the xsodata editor. If it a false error, unfortunately.

  • Step 3

    Save the file and build the Node.js core_xsjs module. Then run the html5 module (defined as web earlier). Once it opens a separate browser tab, change the URL path to /xsodata/businessPartners.xsodata?$format=json to test this new service. The resulting document describes the service entities. You have the one entity named BP.

    test oData
  • Step 4

    You can now adjust the URL slightly and add the /$metadata parameter to the end of it.

    For Example: /xsodata/businessPartners.xsodata/$metadata

    You can see the field descriptions for all the attributes of the OData service.

    access metadata
  • Step 5

    In order to view the data of the entity, you would append BP to the end of the URL:

    For Example:
    /xsodata/businessPartners.xsodata/BusinessPartners?$format=json

    You are now able to see the data from the businessPartner table.

    Business Partner data
  • Step 6

    You can also experiment with standard OData URL parameters like $top, $skip, or $filter. These options are interpreted and handled by the OData service for you. You get complex service handling without any coding. For example the following URL would return only three business partner records and would skip the first five records. Such parameters are helpful when implementing server side scrolling, filtering, or sorting in table UI elements.

    For Example:
    /xsodata/businessPartners.xsodata/BusinessPartners?$top=3&$skip=5&$format=json

    output
Back to top