Also, Node.js supports two kinds of scripts:
CommonJS - it's synchronous and does not support top-level await. In XSJS, all files are loaded as common Java scripts.
The only possible way for your XSJS applications to be up and running on latest Node.js versions is to modify their codes – by migrating them to a new XSJS layer with asynchronous API. See the migration process below to learn what you need to do.
Open your package.json file, and in the dependencies section, add the @Sisn/async-xsjs package
In all your .xsjs and .xsjslib files, for every asynchronous function call, add an await statement.
Every function that uses an await statement must be declared as async.
XSJS files should be loaded as ECMAScript. To do this, in the end of every function in an .xsjslib file, add an export statement.
This is a very simplified sample just to show you the very basic concept.
SAP_SAMPLE will provide you with a tool that can scan your code and help you to modify the need code. However this will needs a manual review and respective testing.
$.import('lib', 'converters');
function select(tableName){
let conn;
try {
conn = $.hdb.getConnection();
let resultSet = conn.executeQuery('SELECT * FROM "' + tableName + '"');
return $.lib.converters.resultSet_to_Entities(resultSet, ["id", "name"]);
} finally {
if (conn) {
conn.commit();
conn.close();
}
}
}
await $.import('lib', 'converters');
async function select(tableName){ let conn;
try {
conn = await $.hdb.getConnection();
let resultSet = await conn.executeQuery('SELECT * FROM "' + tableName + '"');
return $.lib.converters.resultSet_to_Entities(resultSet, ["id", "name"]);
} finally {
if (conn) {
await conn.commit();
conn.close();
}
}
}
export default {select};
also modify the package.json for nodes:
"scripts": { "start": "node --experimental-vm-modules server.js" }
This phrase looks suspicious but this is how new functions as vm-modules are introduced in nodes
Risk
The node.js version 14 will remain in your XSA environment and you could continue to work as of today. Anyhow this version is going out of support by the owner of this component by End of April 2023
We recommend to move to Node.js version18 as the next major release with LTS (long term support) by End of April 2025
The use of asynchronous code is most likely also an improvement in performance.
All this will modification will only work in HANA 2 XSA or HANA Service Cloud Foudry. If you plan to migrate to SAP HANA Cloud you have to migrate your anyhow since the XSJS library is not supported with SAP HANA Cloud.
Alternative: Make your code asynchronous by migrating to SAP Cloud Application Programming model (CAP). This is the base of BTP code development.
Links:
@sap/async-xsjs
async-Migrator
Business Transaction Platform: Cloud Foundry Documentation
Note 3301467 - Migrating SAP HANA XS Classic Applications from XSJS to Async-XSJS
Migrate SAP HANA XS JavaScript Applications to Asynchronous XS JavaScript
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
19 | |
11 | |
9 | |
9 | |
9 | |
8 | |
6 | |
6 | |
6 | |
6 |