Function skipping the squesnce of statements execution

26 Views Asked by At

I have below JavaScript function to connect to HANA DB and run a stored procedure using HANA DB library. In this function, processor is not wating for db connection function statement to be completed.its running the next line of the db function call before its completed fully.

Function is as below.

function ExecuteHANAStoredProcedure(query) {
    var hdb = require('@sap/hdbext');
    var xsenv = require("@sap/xsenv");
    var run_status;
    var hdbOptions_hana = xsenv.getServices({
        hana: {
            tag: "hana"
        }
    });
    var hanaConfig = {
        host: hdbOptions_hana.hana.host,
        port: hdbOptions_hana.hana.port,
        user: hdbOptions_hana.hana.user,
        password: hdbOptions_hana.hana.password,
        encrypt: true,
        sslValidateCertificate: false
    };
    console.log('run_status @ just before the main function ' + run_status);
    hdb.createConnection(hanaConfig, function(error, client) {
        if (error) {
            console.log('Failed with error: ' + error.message);
        }
        try {
            var xyz = client.exec(query);
        } catch (error) {
            console.error('Client Catch Error----' + error.message);
            run_status = error.message;
        } finally {
            console.log('run_status in Finally Error----' + run_status);
            return run_status
        }
        console.log('run_status  @ end of connection function ' + run_status);
    });
    console.log('run_status @ last line of main function ' + run_status);
}

After running this function... Result is coming as below.

8/27/23 2:46:45.077 PM [APP/4-0] OUT run_status @ just before the main function undefined
8/27/23 2:46:45.077 PM [APP/4-0] OUT run_status @ last line of main function undefined
8/27/23 2:46:45.114 PM [APP/4-0] OUT run_status @ end of connection function no data found: "AASL_FDF_CONFIG"."Agile-Analytics.Deployment.FDF.FDF_PREPARE.CORE::PROC_SPECIAL_LEDGER_LINES_PREPARE_INBOUND_QUEUE": line 111 col 8 (at pos 6290):

I am struggling to understand why the processor jumping to the next statement before completing its previous statement.

Here what I am expecting is.

8/27/23 2:46:45.077 PM \[APP/4-0\] OUT run_status @ just before the main function undefined

8/27/23 2:46:45.077 PM [APP/4-0] OUT run_status @ end of connection function no data found: "AASL_FDF_CONFIG"."Agile-Analytics.Deployment.FDF.FDF_PREPARE.CORE::PROC_SPECIAL_LEDGER_LINES_PREPARE_INBOUND_QUEUE": line 111 col 8 (at pos 6290):

8/27/23 2:46:45.114 PM [APP/4-0] OUT run_status @ last line of main function no data found: "AASL_FDF_CONFIG"."Agile-Analytics.Deployment.FDF.FDF_PREPARE.CORE::PROC_SPECIAL_LEDGER_LINES_PREPARE_INBOUND_QUEUE": line 111 col 8 (at pos 6290):
0

There are 0 best solutions below