on 08-09-2015 8:23 AM
Hi,
I try to get familiar with "XS Procedures API" (SPS09).
http://help.sap.com/hana/SAP_HANA_Developer_Guide_for_SAP_HANA_Web_Workbench_en.pdf
"Calling Procedures with Arguments that Reference an Existing Table"
"The WITH OVERVIEW expression also allows you to write the results of a procedure into a global temporary table; that is, a table that is truncated at session close. To use XS Procedures to write the results of a procedure into a global temporary table, you do not specify a name for the result table; you include an empty string (''), as illustrated in the following example:
var conn = $.db.getConnection(); resCall = getRating(rating, 3, '', conn); // {"RESULT": [{"variable":"RESULT","table":"\"SCHEMA\". \"RESULT_5270ECB8F7061B7EE10000000A379516\""}]} "
My question is how can I query the temporary table, after I called the Procedures.
If I debug the procedures I can see the entries of the table (ex_value). But how can I see the entries of the global temporary table?
Does anyone has a simple example, where I can check the steps after calling a procedures?
Thanks for your help,
Dirk
Hello Dirk,
you can query the temporary table via the db interface.
Simple example which queries the top 10 objects from table "_SYS_REPO"."ACTIVE_OBJECT".
Procedure:
PROCEDURE "TEST"."test.procedures::test_for_xsjs_xsproc" ( OUT et_active_object "_SYS_REPO"."ACTIVE_OBJECT" )
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
READS SQL DATA AS
BEGIN
et_active_object = select top 10 * from "_SYS_REPO"."ACTIVE_OBJECT";
END
XSJS:
var oConnection = $.db.getConnection();
var XSProc = $.import("sap.hana.xs.libs.dbutils", "procedures");
XSProc.setTempSchema("TEST");
var oProcedure = XSProc.procedure("TEST", "test.procedures", "test_for_xsjs_xsproc", {connection: oConnection});
var oResult = oProcedure('');
var oPrepStatement = oConnection.prepareStatement("SELECT * FROM " + oResult.ET_ACTIVE_OBJECT[0].table );
var oResultSet = oPrepStatement.executeQuery();
var sResult = "";
while(oResultSet.next()){
sResult += oResultSet.getString(2) + "</br>";
}
$.response.contentType = "text/html";
$.response.setBody(sResult);
Best Regards,
Florian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Dirk,
cause you are on SPS09 you can of course use the new $.hdb interface.
Here sample xsjs for the sample procedure above producing the same result than the xsjs with the "old" code:
var oConnection = $.hdb.getConnection();
var fnProcedure = oConnection.loadProcedure("TEST", "test.procedures::test_for_xsjs_xsproc");
var result = fnProcedure();
var activeObjects = result.ET_ACTIVE_OBJECT;
var sResult = "";
for (var i = 0; i < activeObjects.length; i++) {
sResult += activeObjects[i].OBJECT_NAME + "</br>";
}
$.response.contentType = "text/html";
$.response.setBody(sResult);
Best Regards,
Florian
what is even better is that the new DB api to load the stored proc could return the output as a JSON object.. if you define an output param as a table (or table type) then on your xsjs you can simply access that objct as response['yourOutPutVariableName'] -- this would be your json object going back therefore no need to create an additional object and you can also iterate thru it as a javascript array. it is very handy
You can create a XS JavaScript Debug Configuration in Eclipse to be able to debug your XSJS coding.
I personally prefer the HANA Web-based development workbench which is quite good in the meantime (>= SPS09). With the corresponding rights you can directly debug your coding within the browser using the Web-based development workbench. If you are interested in this please check the first chapter in http://help.sap.com/hana/SAP_HANA_Developer_Guide_for_SAP_HANA_Web_Workbench_en.pdf.
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.