15

Create a XSJS application consume calculation view and sent it to Https in HANA...

 1 year ago
source link: https://blogs.sap.com/2023/01/06/create-a-xsjs-application-consume-calculation-view-and-sent-it-to-https-in-hana-xsa/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
January 6, 2023 1 minute read

Create a XSJS application consume calculation view and sent it to Https in HANA XSA

In this section I will discuss about the create a XSJS application consume calculation view and sent it to Http response to SAPUI5 in SAP HANA XSA using WEB IDE.

Architecture :

HANA-XSJS-architecture-1.png

Steps :

1. Create a Calculation view using required tables in the HDI container.  For our case we created a CV CV_EMPLOYEE from table employee. The detail is given below –

ttps://blogs.sap.com/2020/11/23/understanding-the-development-process-of-calculation-view-in-hana-2.0-xsa-environment-using-web-ide/

2. Create a Node.js application and inside lib folder create a employee.xsjs application.

1234.jpg

3. Create the employee.xsjs inside lib folder and implement the below code to access the data.

var employee = [];
var stmnt = null;
var rs = null;
var conn = $.db.getConnection();
var stmnt = conn.prepareStatement( "select * from "PLB_DB.OFFICE"::"CV_EMPLOYEE" );
var rs = stmnt.executeQuery();

if (!rs.next()) {
  $.response.setBody( "Unable to get result" );
  $.response.status =  $.net.http.INTERNAL_SERVER_ERROR;
} else {
	  emp = {};
	  emp.emp_id = resultSet.getString(1);
	  emp.emp_name = resultSet.getString(2);
	  emp.emp_mail_id = resultSet.getString(3);
	  emp.address = resultSet.getString(4);
	  employee.push(emp);
}
rs.close();
pstmt.close();
conn.close();

try{
		$.response.contentType = "application/json";
		$.response.setBody(JSON.stringify(employee));
}
catch(err){
		$.response.contentType = "text/plain";
		$.response.setBody("Got error : [" + err.message + "]");
		$.response.returnCode = 400;
}

4. Build the DB Module first. Then build the Node.js module . Run as Node.js application and you can see the calculation view has been expose in json format in browser.

output.png

Hope this will help.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK