Skip to Content

How to pass data to a input table parameter of a procedure while calling it from XSJS file

Hi,

How can i pass table data to the input variable of a procedure when i am calling it from a xsjs file.

Here is my code:

hdbprocedure:

PROCEDURE "Schema"."procedures::ProcedureName" (

in it_records table( EMPID integer,

NAME nvarchar(50) ),

in iv_action varchar(10) )

LANGUAGE SQLSCRIPT

SQL SECURITY INVOKER

DEFAULT SCHEMA "Schema" AS

BEGIN

// here i will update the data(it_recordfs) to my DB tables basing on the action(iv_action)//

END;

xsjs:

var conn = $.db.getConnection();

var data = [{"EMPID":123,"NAME":'New'}];

var action = 'insert';

var qry = 'CALL "Schema"."procedures::ProcedureName" (?,?)';

var stmt = conn.prepareCall(qry);

stmt.setString(1,data);

stmt.setString(2, action);

stmt.execute();

When i am executing this, i am getting the error as:

InternalError: dberror(Connection.prepareCall): 8 - invalid argument: Input parameter is inadequate as table parameter: line 1 col 41 (at pos 40) (line 6 position 1 in /services/sample.xsjs)

Can anyone help me on this?

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 28, 2017 at 01:57 PM

    there are a few things you should consider....

    1) use the $.hdb api instead of the $.db api

    2) you can pass a JS array to a stored proc function -- simulates the table as input param in the stored proc

    here is an example:

    https://blogs.sap.com/2015/11/18/callling-stored-proc-with-multiple-values/

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 12, 2017 at 11:09 AM

    Hi

    You can use the newer $.hdb database api.

    var fnSell = connection.loadProcedure('DB_EXAMPLE','icecream.shop::sell');

    var result = fnSell('CHOCOLATE',3,30.0);

    Add comment
    10|10000 characters needed characters exceeded