XS Procedures is a library to call stored procedures in HANA from XS as if they were Javascript functions.
Members
-
<static> configuration :Object
-
A global configuration object specifying tracing, schema into which temporary tables are written, and argument passing mode.
Type:
- Object
Properties:
Name Type Argument Default Description trace
<optional>
notrace trace - a method to be used for tracing procedure calls Properties
Name Type Description debug
function called for debug level logs warning
function called for warning level logs info
function called for info level logs argumentPassingMode
string <optional>
'ltt' can be either 'ltt' or 'gtt'. 'ltt' will create local temporary tables, 'gtt' will create global temporary tables tempSchema
string indicates a schema used for creating temporary tables -
<static> notrace :Object
-
A constant to be used configuration.trace if no tracing is required
Type:
- Object
-
<static> simpletrace :Object
-
A constant to be used in configuration.trace if simple tracing to default $.trace is required
Type:
- Object
Methods
-
<static> allProcedures(schema, package) → {Object}
-
Returns an object with properties for all stored procedures and values containing functions which calls these stored procedure
Parameters:
Name Type Description schema
string the schema name where the stored procedures are located package
string the package name where the stored procedures are located Returns:
- an object with a property for each of the procedures available for the given schema and procedure name.- Type
- Object
Example
var XSProc = $.import("sap.hana.xs.libs.dbutils", "procedures"); // import the library XSProc.setTempSchema("MYSCHEMA"); // specify a temporary schema var getRating = XSProc.allProcedures("MYSCHEMA","my.package").RATINGPROC; // create a function as proxy for the procedure // the procedure RATINGPROC has the signature (in IN_RATING ACTIVITYRATING, in FACTOR INTEGER, out RESULT USERRATING) with // types: type ACTIVITYRATING {ACTIVITYID: Integer; USERID: Integer; RATING: Integer;}; // type USERRATING { USERID: Integer; RATING: Integer;}; var result = getRating([{ACTIVITYID: 1001, USERID: 1, RATING: 3}, {ACTIVITYID: 1011, USERID: 1, RATING: 1}], 3); // call the procedure // result === {"RESULT":[{"USERID":1,"RATING":6},{"USERID":2,"RATING":6}]}
-
<static> procedure(schema, package, proc, config) → {procedures~procedurecaller}
-
Returns a function which calls a stored procedure.
Parameters:
Name Type Argument Description schema
string the schema name where the stored procedure is located package
string the package name of the stored procedure proc
string the name of the stored procedure config
Object <optional>
a configuration object containing one or several of the following properties Properties
Name Type Argument Description connection
$.db.Connection <optional>
a connection object to be used for calling the procedure input
function <optional>
an array of functions each of which is applied to the corresponding element in the array of input arguments before invoking the procedure output
function | string <optional>
an array of functions each of which is applied to the corresponding element in the array of output objects. It can also be the string 'raw' if the unmodified ResultSet should be returned Returns:
- a function which calls a stored procedure.- Type
- procedures~procedurecaller
Example
var XSProc = $.import("sap.hana.xs.libs.dbutils", "procedures"); // import the library XSProc.setTempSchema("MYSCHEMA"); // specify a temporary schema var getRating = XSProc.procedure("MYSCHEMA","my.package", "RATINGPROC"); // create a function as proxy for the procedure // the procedure RATINGPROC has the signature (in IN_RATING ACTIVITYRATING, in FACTOR INTEGER, out RESULT USERRATING) with // types: type ACTIVITYRATING {ACTIVITYID: Integer; USERID: Integer; RATING: Integer;}; // type USERRATING { USERID: Integer; RATING: Integer;}; var result = getRating([{ACTIVITYID: 1001, USERID: 1, RATING: 3}, {ACTIVITYID: 1011, USERID: 1, RATING: 1}], 3); // call the procedure // result === {"RESULT":[{"USERID":1,"RATING":6},{"USERID":2,"RATING":6}]}
-
<static> procedureOfSchema(schema, proc, config) → {procedures~procedurecaller}
-
procedureOfSchema - Returns a function which calls a stored procedure
Parameters:
Name Type Argument Description schema
string the schema name where the stored procedure is located proc
string the name of the stored procedure config
Object <optional>
a configuration object containing one or several of the following properties Properties
Name Type Argument Description connection
$.db.Connection <optional>
a connection object to be used for calling the procedure input
function <optional>
an array of functions each of which is applied to the corresponding element in the array of input arguments before invoking the procedure output
function | string <optional>
an array of functions each of which is applied to the corresponding element in the array of output objects. It can also be the string 'raw' if the unmodified ResultSet should be returned Returns:
- a function which calls a stored procedure.- Type
- procedures~procedurecaller
Example
var XSProc = $.import("sap.hana.xs.libs.dbutils", "procedures"); // import the library XSProc.setTempSchema("MYSCHEMA"); // specify a temporary schema var getRating = XSProc.procedure("MYSCHEMA", "RATINGPROC"); // create a function as proxy for the procedure // the procedure RATINGPROC has the signature (in IN_RATING ACTIVITYRATING, in FACTOR INTEGER, out RESULT USERRATING) with // types: type ACTIVITYRATING {ACTIVITYID: Integer; USERID: Integer; RATING: Integer;}; // type USERRATING { USERID: Integer; RATING: Integer;}; var result = getRating([{ACTIVITYID: 1001, USERID: 1, RATING: 3}, {ACTIVITYID: 1011, USERID: 1, RATING: 1}], 3); // call the procedure // result === {"RESULT":[{"USERID":1,"RATING":6},{"USERID":2,"RATING":6}]}
-
<static> setTempSchema(schemaName) → {procedures}
-
Sets the name of the schema into which temporary tables are written during procedure calls
Parameters:
Name Type Description schemaName
string the name of the schema Returns:
- this object so that the function can be called in a fluent style- Type
- procedures
Type Definitions
-
procedurecaller(IN1, IN2) → {Object}
-
Parameters:
Name Type Description IN1
number | string | Date a Javascript scalar send to a scalar input parameter named IN1 of the stored procedures IN2
Object a Javascript array containing the rows sent to an input table-valued parameter named IN2 of the stored procedure Returns:
OUT - a Javascript array containing as properties the output parameters of the stored procedure. Each property contains either a scalar (if the output parameter is scalar) or an array containing objects representing the rows (if the output parameter is table-valued). In the latter case, each row contains an object with properties for each column. If the procedure returns a result set which is not declared, such as an unassigned SELECT, the OUT additionally contains numbered items which correspond to these result sets.- Type
- Object