sqlhanahana-sql-scripts4hanaxsjs

Error when trying to call SAP HANA stored procedure from service side


I am trying to call a SAP HANA hdbprocedure from my service side using below code.

var con = ConLib.getHDBConnection();
var uploadStmt = con.loadProcedure("_SYS_BIC" , "procname");
var result = uploadStmt("samplefield1",  "samplefield2", {"DATA":[{"id1":"id_1001","id2":"id_2001","year_col":"2018"}, {"id1":"id_1002","id2":"id_2002","year_col":"2019"}]})

The procedure takes below paramaters as input.

PROCEDURE procname (
IN field1 VARCHAR(100),
IN field2 VARCHAR(100)
IN in_table_data "schema_name"."hdbdd_file_name.table_type"
){}

The in_table_data is defined as below in hdbdd_file_name.hdbdd file.

Type table_type {
id1 : String(100);
id2 : String(100);
year_col : String(4);}

I am getting below error when I call the procedure from my service side.

" Error occured in processRequest method $.hdb.Connection.executeProcedure: Parameter at  position 3 is not of type that can be processed "

Could you please suggest what needs to be changed either at the DB side or service side to fix this issue.

Thank you in advance.


Solution

  • I'm under the impression that the definition of the array in your calling statement is incorrect:

    var result = uploadStmt("samplefield1", "samplefield2", {"DATA":[{"id1":"id_1001","id2":"id_2001","year_col":"2018"}, {"id1":"id_1002","id2":"id_2002","year_col":"2019"}]})

    instead, try it like so:

    var result = uploadStmt("samplefield1"
                          , "samplefield2"
                , [{id1: 'id_1001', id2: 'id_2001', year_col: '2018'}
                 , {id1: 'id_1002', id2: 'id_2002', year_col: '2019'}]
                           )