Skip to Content
0
Jan 31, 2017 at 12:54 PM

How could I connect to SAP HXE schema via Node and create an OData service from view?

1089 Views Last edit Feb 01, 2017 at 11:19 AM 10 rev

Dear experts,

I use the SAP HANA Express edition to create a MTA.

1. Question)

I would like to connect from the Node.js-module to the SAP HXE and then I would like to SELECT data and INSERT data INTO Tables and Views in the schema "SYSTEM", which I created with a .hdbcds-file (I didn't use a hdi-container to create the database tables). How could I SELECT Data as json from SYSTEM views from a node.js-module.

I tried to use the sap-hdbext and the node-hdb javascript package for node.js to establish the connection and then I tried to execute simple SQL commands?

https://github.com/SAP/node-hdb

https://help.sap.com/saphelp_hanaplatform/helpdata/en/54/513272339246049bf438a03a8095e4/content.htm#loio54513272339246049bf438a03a8095e4__section_ilt_mkt_vt

http://www.sap.com/developer/tutorials/xsa-node-dbaccess.html

2. Question)

I would like to create an OData service from the CDS views in the SYSTEM schema. How can I create an OData service from views which are not in a hdi-container?I only found examples which use tables from a hdi-container. I will use the OData service for a master-detail fiori application.


This is my app.js file :

"use strict";

var xsjs = require("sap-xsjs");
var xsenv = require("sap-xsenv");
var port = process.env.PORT || 3000;

var options = {
anonymous : true, // remove to authenticate calls
redirectUrl : "/index.xsjs"
};

// configure HANA
try {
options = Object.assign(options, xsenv.getServices({ hana: {tag: "hana"} }));
} catch (err) {
console.log("[WARN]", err.message);
}

// configure UAA
try {
options = Object.assign(options, xsenv.getServices({ uaa: {tag: "xsuaa"} }));
} catch (err) {
console.log("[WARN]", err.message);
}

var hdbext = require("sap-hdbext");
var hanaConfig = {
host : "hxehost",
port : 39015,
user : "SYSTEM",
password : "PW"
};

hdbext.createConnection(hanaConfig, function(error, client) {
if (error) {
return console.error(error);
}
client.exec("select * from SYSTEM.TableXY", function (err, rows) {
client.end();
if (err) {
return console.error("Execute error:", err);
}
console.log("Results:", rows);
});
});

app.listen(port);
console.log("listening at:", port);


This is my package.json file :

{
"dependencies": {
"sap-xsenv": "1.2.4",
"sap-xsjs": "1.11.3",
"body-parser": "^1.15.2",
"express": "~4.13.4",
"sap-hdbext":"latest"

},
"devDependencies": {
"sap-xsjs-test": "1.2.2"
},
"files": [],
"main": "app.js",
"name": "tinyjs",
"scripts": {
"start": "node app.js",
"test": "node app.js"
},
"engines": {
"node": "6.x"
},
"version": "1.0.0"
}

_schema-version: '2.0'
ID: supplier
version: 0.0.1

modules:
- name: tinyjs
type: nodejs
path: tinyjs