This tutorial will guide you through the creation of a service to publish data from a database schema that is not managed by an HDI container.

You will learn

This tutorial will walk you through the integration of a non HDI-managed database, such as a replicated database, into an HDI container and how to access it using a SQL anonymous connection.

Details

Step 1: Load data into a database schema in SystemDB

This tutorial needs a replicated database or a schema that is not managed by an HDI container. An example of such schema is an ABAP or ERP database, which you may need to integrate to your XS Advanced development. You will simulate this by creating a schema and importing data into it.

Note: This tutorial will use the default System database in an SAP HANA, express edition instance. Use a tenant database if you have a different system or one available.

Begin by connecting to your SAP HANA SystemDB using the + sign in the Database Explorer and choose SAP HANA Database (Multitenant):

Set the connection parameters to your System database, or the database of your choice. Make sure the selected user has access to the database schema.

You can now see the schemas in your database and open the SQL console:

Step 2: Create a Schema and table and Import data

Paste the following code into a SQL console to create a custom schema and a table in it:

Note: You can find out what the right port is (i.e., 30013 or 30015 for instance number 00) by running xs apps or netstat in the OS console.

And execute it in a console:

Step 4: Add the service as a resource for the nodejs module

Back in the Development tool in the SAP Web IDE for SAP HANA, open the mta.yaml editor and add a resource called CROSS_SCHEMA_LOCATIONS, with type org.cloudfoundry.existing-service and the following parameter:- Key: service-name- Value: CROSS_SCHEMA_LOCATIONS

Add the newly-declared resource as a dependency for the node.js module:

Save the mta.yaml file.

Step 5: Extend the server.js file

Open the file server.js file in the js folder and add the following code:

Replace index.html with /xsjs/locations.xsjs. You should now see that the database user is the schema owner and the XS layer session user is the user you are logged in with.

Step 7: Add the service as a resource to the HDI container

You will now edit the mta.yaml file so you can use it in your XS Advanced development in, for example, CDS artifacts. Open the MTA editor and add the following a new resource that will be very similar to the resource required by the js module, but with some additional properties. Add a resource called CrossSchemaServices, type org.cloudfoundry.existing-service, with service-name and CROSS_SCHEMA_LOCATIONS as the key-value pair in Parameters and locations-service-name and ${service-name} in Properties.

Now add the new resource as a requirement for the db module. Add CrossSchemaService in Group SERVICE_REPLACEMENTS. Add the property key with value hdi-locations-service and property service with value ~{locations-service-name}.

After all additions and assuming you have been following the tutorials series in a sequence, your mta.yaml file in the code editor should look similar to this: