Friday, 13 January 2023

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:


SAP HANA XSA, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Tutorial and Materials, SAP HANA Calculation

SAP HANA XSA, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Tutorial and Materials, SAP HANA Calculation

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 –


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

SAP HANA XSA, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Tutorial and Materials, SAP HANA Calculation

3. Add this DB module db_plb to node.js module(with XSJS support) as a required module.

SAP HANA XSA, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Tutorial and Materials, SAP HANA Calculation

4. 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 "DB_PLB.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;
}

5. Build the DB Module first. Run as Node.js application and you can see the calculation view has been expose in son format in browser.

SAP HANA XSA, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Tutorial and Materials, SAP HANA Calculation

No comments:

Post a Comment