Skip to Content
0

Calling procedure with output parameter from XSJS

Jan 19 at 08:05 PM

230

avatar image
Former Member

We are calling a procedure in our XSJS which has an output parameter.

In XSJS we want to read the output parameter.

My code looks like below

var query = "{call\"test"\"test::DELTA_LOAD\"(1,?)}";

var conn = $.db.getConnection();

var pcall = conn.prepareCall(query);

pcall.execute();

//reading the output parameter in the variable status

var status = pcall['e_status'];

Based on status variable i need to send the email with success or failure

Is there any way to get the return parameter from the stored procedure into a variable?

Thanks

Srini

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Florian Pfeffer
Jan 20 at 07:29 AM
0

You should not use the old legacy db interface $.db anymore. Use the $.hdb interface. With that you can use the loadProcedure function to load a procedure. That function returns a JS function which executes your stored procedure. Advantage of that is, that the JS function has a clear interface corresponding to the stored procedure interface. You you get also the result back. Check the example in the documentation here ($.hdb, class Connection, function loadProcedure).

Another option is to use the procedure function of the XS DB utilities (check the example here).

Regards,
Florian

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks for ur reply,

I change to $.hdb.getConnection

var connection = $.hdb.getConnection()

//my procedure has parameters (IN P_GROUP_DAYS INT DEFAULT 1, OUT e_status varchar(1))

var result = connection.loadProcedure('TEST', 'folderpath::DELTA_LOAD');

var status = result.e_status;

connection.close();

By using the above code, i'm not able to return e_status value into 'status' variable. any wrong with the code?

Thanks

Srini

0

The loadProcedure function returns a function which you have to execute:

var testFunction = connection.loadProcedure('TEST', 'folderpath::DELTA_LOAD');
var result = testFunction(10); // 10 is an example for passing an integer
0
Former Member

I got it, Then how to read the output parameter "e_status" in XS?

Thanks

Srini

0

So what do you think is part of the result variable? If you check the example in the documentation (as linked above) it should be already clear.

0
Former Member

Thank you Florian for helping me out.

0