### SAP Fiori Launchpad Portal Site package.json Configuration Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Example of a package.json file for a SAP Fiori Launchpad portal site, specifying Node.js engine requirements, dependencies including @sap/site-entry, and a start script. ```json { "engines": { "node": ">=4.0.0" }, "name": "site-entry", "dependencies": { "@sap/site-entry": "^1.9.1" }, "scripts": { "start": "node --harmony node_modules/@sap/site-entry/server.js" } } ``` -------------------------------- ### SAP Fiori Launchpad Portal Site Content Deployer package.json Configuration Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Example of a package.json file for the @sap/site-content-deployer module, specifying Node.js version, dependencies, and a start script for deployment. ```json { "engines": { "node": "4.x" }, "name": "site-content-deployer", "version": "1.9.1", "description": "portal deployer package", "dependencies": { "@sap/site-content-deployer": "^1.9.1" }, "scripts": { "start": "node --harmony node_modules/@sap/site-content-deployer/deploy.js" } } ``` -------------------------------- ### Example Dependencies in package.json Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/set-up-logging-and-tracing-for-your-javascript-multitarget-application-7c242c7.md Illustrates the 'dependencies' section of a package.json file, showing the inclusion of the newly installed @sap/logging module alongside other SAP Node.js modules and common web development packages like Express and Passport. ```json { "dependencies": { "express": "4.18.2", "@sap/xsenv": "4.2.0", "@sap/hdbext": "^8.0.2", "@sap/xssec": "^3.6.0", "passport": "^0.7.0", "@sap/logging": "^7.1.0" } } ``` -------------------------------- ### Initialize XS JavaScript Server with SAP HANA Services Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Demonstrates how to initialize an XSJS server by retrieving service credentials from the environment and starting the application on a specified port. This setup is essential for connecting to SAP HANA, UAA, and other required services. ```javascript 'use strict'; var xsenv = require('@sap/xsenv'); var xsjs = require('@sap/xsjs'); var port = process.env.PORT || 3000; var options = xsenv.getServices({ uaa: 'xsuaa', hana: 'hana-hdi', jobs: 'scheduler', mail: 'mail', secureStore: 'secureStore' }); xsjs(options).listen(port); console.log('Node XS server listening on port %d', port); ``` -------------------------------- ### Install and verify MTA plug-in Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-bas/020-HANA-Cloud-DB-Dev-Get-Started/get-started-with-the-cloud-foundry-command-line-interface-7124693.md Installs the multiapps plug-in required for managing multitarget applications and lists installed plug-ins to verify the installation. ```bash cf install-plugin multiapps -f cf plugins ``` -------------------------------- ### Install Cloud MTA Build Tool via NPM Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-bas/030-HANA-Cloud-DB-Dev-Deployment/the-cloud-mta-build-tool-mbt-1412120.md Installs the MBT globally on the system using the Node Package Manager. This requires Node.js and npm to be installed in the environment. ```bash npm install -g mbt ``` -------------------------------- ### Install SAP Application Router (npm) Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/set-up-authentication-for-your-javascript-multitarget-application-1c16bb3.md Installs the '@sap/approuter' module using npm and saves it as a dependency in the package.json file. This command should be executed in the 'web' directory. ```bash npm install @sap/approuter --save ``` -------------------------------- ### Initialize AMQP Client with TLS and NET Options Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Demonstrates how to instantiate an AMQP client by providing a configuration object containing TLS, NET, SASL, and AMQP-specific settings. This approach allows for granular control over security and connection parameters. ```javascript const options = { tls: { host: 'localhost', port: 5671, ca: [ fs.readFileSync('../../../truststore/cacert.pem'), fs.readFileSync('../../../truststore/cert.pem') ] }, net: { host: 'localhost', port: 5672, }, sasl: { user: 'guest', password: 'guest' }, amqp: { vhost: '/', } }; const client = new AMQP.Client(options); ``` -------------------------------- ### Project Structure for SAP HANA Cloud Multitarget Applications Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-bas/020-HANA-Cloud-DB-Dev-Get-Started/getting-started-with-multitarget-application-development-in-cloud-foundry-on-sa-7f681c3.md This example illustrates a typical project structure for a multitarget application on SAP BTP, including folders for database artifacts, web resources, JavaScript code, OData services, and security configurations. ```tree |- db/ # Database deployment artifacts | \- src/ # Database artifacts: tables, views, etc. |- web/ # Application router/descriptors | \- resources/ # Static Web resources |- js/ # JavaScript artifacts | \- src/ # JavaScript source code | \- odata/ # OData resources (optional) | \- srv/ # OData services \- security/ # Security deployment artifacts/scopes/auths ``` -------------------------------- ### Initialize AMQP Client with TLS and NET Options Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Demonstrates how to configure an AMQP client instance using specific TLS certificates and network settings. This approach allows for secure connections by providing paths to truststore files. ```javascript const options = { tls: { host: 'localhost', port: 5671, ca: [ fs.readFileSync('../../../truststore/cacert.pem'), fs.readFileSync('../../../truststore/cert.pem') ] }, net: { host: 'localhost', port: 5672, }, sasl: { user: 'guest', password: 'guest' }, amqp: { vhost: '/', } }; const client = new AMQP.Client(options); ``` -------------------------------- ### Setup for Static Filter Example Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/create-structured-filter-statement-data-definition-f0238ff.md Sets up the necessary database objects for the static structured filter example. This includes creating a schema SC1 and a parameterized SQL view SC1.MYVIEW with structured filter enabled. ```SQL CREATE SCHEMA SC1; CREATE OR REPLACE VIEW SC1.MYVIEW(IN OUTVAL INT default 1) AS SELECT 1 + :OUTVAL AS PARAMCOL, 1 AS FIXEDCOL FROM DUMMY WITH STRUCTURED FILTER CHECK; ``` -------------------------------- ### Calculate Future Date with ADD_WORKDAYS (SQL) Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/011-SQL-Functions/add-workdays-function-datetime-d22c839.md Calculates a future date by adding a specified number of working days to a start date, considering weekends and public holidays. This example uses a hardcoded start date and duration. ```sql SELECT ADD_WORKDAYS('01', '2014-01-01', 16, 'FCTEST') "result date" FROM DUMMY; ``` -------------------------------- ### Create MQTT Client Instance using Plain TCP Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Demonstrates how to instantiate an MQTT client using plain TCP connection. This requires specifying the host and port for the broker. The `credentials` object can be used for authentication. ```javascript const options = { net: { host: 'localhost', port: 1883 }, credentials: { user: '', password: '' } }; const client = new MQTT.Client(options); ``` -------------------------------- ### Allow-list Service GET Request Example Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/090-HANA-Cloud-DB-Dev-MTA-Routes/application-router-configuration-syntax-5f77e58.md Demonstrates the structure of a GET request to the allow-list service, which is used to filter incoming requests. The parent origin is passed as a URL-encoded parameter. This service helps in controlling access based on the origin of the request. ```http GET url/to/whitelist/service?parentOrigin=https://parent.domain.acme.com ``` -------------------------------- ### Initialize and Configure Tracers in Node.js Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Demonstrates how to obtain a tracer instance using the logging context and how to retrieve status information such as current log levels and enabled states. ```javascript var tracer = req.loggingContext.getTracer(__filename); var level = tracer.getLevel(); var willItBeTraced = tracer.isEnabled('path'); ``` -------------------------------- ### ALTER SEQUENCE Example - Resetting on Database Restart Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/alter-sequence-statement-data-definition-20d06b0.md An example of using the RESET BY clause to define a subquery that determines the sequence's starting value upon database restart. This ensures consistent sequence generation after restarts. ```sql ALTER SEQUENCE "MY_SCHEMA"."MY_SEQUENCE" RESET BY (SELECT MAX(ID) + 1 FROM "MY_SCHEMA"."MY_TABLE"); ``` -------------------------------- ### Setup Schema and Table for Search Examples Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/contains-predicate-20f9524.md Initializes a schema and a column-oriented table with sample data to demonstrate various search functionalities. ```SQL CREATE SCHEMA mySchema; CREATE COLUMN TABLE mySchema.SEARCH_TEXT( Content VARCHAR(20), Descrip VARCHAR(20), Comment VARCHAR(20) ); INSERT INTO mySchema.SEARCH_TEXT VALUES( 'Blue baseball cap', 'Vintage', 'Out of stock'); INSERT INTO mySchema.SEARCH_TEXT VALUES( 'Red car', 'Vintage', 'Taking orders' ); INSERT INTO mySchema.SEARCH_TEXT VALUES( 'Bluish sky', 'Retro', 'Discontinued' ); ``` -------------------------------- ### Create Table for Dynamic Range Partitioning Example Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/heterogeneous-alter-partition-clauses-a4258b8.md Defines a column table with range partitioning on column A and subpartitioning by range on column B, setting up partitions and subpartitions for dynamic range partitioning examples. ```sql CREATE COLUMN TABLE A1 (A INT, B INT NOT NULL) PARTITION BY RANGE (A) ((PARTITION 10 <= VALUES < 20) SUBPARTITION BY RANGE (B) (PARTITION 15 <= VALUES < 20, PARTITION OTHERS), (PARTITION VALUES = 30) ``` -------------------------------- ### LOCATE_REGEXPR Function Example (SQL) Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/011-SQL-Functions/locate-regexpr-function-string-cb48664.md Demonstrates how to use the LOCATE_REGEXPR function to find the starting position of a specific part (day) within a date string using a regular expression pattern. It utilizes optional parameters like START and GROUP for precise matching. ```sql SELECT LOCATE_REGEXPR(START '([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})' IN '20140401' GROUP 3) "locate_regexpr" FROM DUMMY; ``` -------------------------------- ### Move Range Partition Example Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/heterogeneous-alter-partition-clauses-a4258b8.md Demonstrates the SQL syntax for moving one or more first- or second-level range partitions to a new location. The ONLINE parameter can be used when moving partitions to different hosts. ```sql ALTER TABLE T1 MOVE PARTITION 1,2 TO 'MyServer1:34240', PARTITION 3,4 TO 'MyServer2' ONLINE ``` ```sql ALTER TABLE T1 MOVE PARTITION 1,2 TO MyServer1:34240; ``` -------------------------------- ### Create Workload Mappings for Users and Applications Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/create-workload-mapping-statement-workload-management-996978a.md Demonstrates creating workload mappings for specific database users and applications. Includes examples of using the default wildcard character to match application names. ```SQL CREATE WORKLOAD MAPPING "MyWorkloadMapping1" WORKLOAD CLASS "MyWorkloadClass" SET 'USER NAME' = 'ABCADM', 'APPLICATION NAME' = 'BW'; CREATE WORKLOAD MAPPING "MyWorkloadMapping1" WORKLOAD CLASS "MyWorkloadClass" SET 'APPLICATION NAME' = 'BW%' WITH WILDCARD; ``` -------------------------------- ### BITSET Function Syntax and Example (SQL) Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/011-SQL-Functions/bitset-function-numeric-d22d097.md Demonstrates the SQL syntax for the BITSET function, which sets a specified number of bits to 1 in a VARBINARY target number starting from a given index. It takes the target number, start bit index, and the number of bits to set as arguments. ```SQL SELECT BITSET ('0000', 1, 3) "bitset" FROM DUMMY; ``` -------------------------------- ### Setup for Dynamic Filter Example Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/create-structured-filter-statement-data-definition-f0238ff.md Sets up the necessary database objects for the dynamic structured filter example. This includes creating a table T1, a view DYNAMIC_T1_VIEW with structured filter enabled, a table T2 to store filter strings, and a stored procedure to retrieve the filter string. ```SQL CREATE TABLE T1 (year_key nvarchar(10), year_sidE nvarchar(10), customer_sid nvarchar(10), sales int); CREATE VIEW "DYNAMIC_T1_VIEW" AS (SELECT * FROM T1) WITH STRUCTURED FILTER CHECK; CREATE COLUMN TABLE T2 ("filter_string" varchar(5000), "userName" varchar(256)); CREATE PROCEDURE PROC_DYNAMIC_T2_VIEW (OUT VAL VARCHAR(5000)) LANGUAGE SQLSCRIPT SQL SECURITY DEFINER READS SQL DATA AS BEGIN DECLARE v_Val VARCHAR(5000); DECLARE CURSOR c_GetOneOperand FOR SELECT "filter_string" FROM T2 WHERE "userName" = SESSION_USER; OPEN c_GetOneOperand; FETCH c_GetOneOperand INTO v_Val; IF c_GetOneOperand::NOTFOUND THEN VAL = NULL; ELSE VAL = v_Val; END IF; CLOSE c_GetOneOperand; END; ``` -------------------------------- ### Initialize AMQP Client with URI Array Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Shows how to provide connection details as an array of URIs. The client will attempt to connect using the provided sequence, failing over to subsequent URIs if the initial connection fails. ```javascript const options = { uri: [ 'amqp://guest:guest@localhost:5672/vh111', 'amqp://guest:guest@localhost:5672/vh222' ] }; const client = new AMQP.Client(options); ``` -------------------------------- ### Configure @sap/hdi-dynamic-deploy in package.json Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Shows how to add the @sap/hdi-dynamic-deploy dependency and define the start script in a Node.js package.json file. ```json { "name": "deploy", "dependencies": { "@sap/hdi-dynamic-deploy": "1.1.0" }, "scripts": { "start": "node node_modules/@sap/hdi-dynamic-deploy/" } } ``` -------------------------------- ### SQL Setup for Structured Filter Example Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/alter-structured-filter-statement-data-definition-07b14e0.md Provides the necessary SQL statements to set up tables, views, and procedures required for demonstrating the ALTER STRUCTURED FILTER statement. ```sql -- Setup for the following example -- CREATE TABLE T1 (year_key nvarchar(10), year_sidE nvarchar(10), customer_sid nvarchar(10), sales int); INSERT INTO T1 VALUES ('2007', '2007', 'CUSTOMER_A', 1000); CREATE VIEW "DYNAMIC_T1_VIEW" AS (SELECT * FROM T1) WITH STRUCTURED FILTER CHECK; CREATE COLUMN TABLE T2 ("filter_string" varchar(5000), "userName" varchar(256)); CREATE PROCEDURE PROC_DYNAMIC_T2_VIEW (OUT VAL VARCHAR(5000)) LANGUAGE SQLSCRIPT SQL SECURITY DEFINER READS SQL DATA AS BEGIN DECLARE v_Val VARCHAR(5000); DECLARE CURSOR c_GetOneOperand FOR SELECT "filter_string" FROM T2 WHERE "userName" = SESSION_USER; OPEN c_GetOneOperand; FETCH c_GetOneOperand INTO v_Val; IF c_GetOneOperand::NOTFOUND THEN VAL = NULL; ELSE VAL = v_Val; END IF; CLOSE c_GetOneOperand; END; CREATE STRUCTURED FILTER SF_T2_VIEW FOR SELECT ON DYNAMIC_T1_VIEW CONDITION PROVIDER PROC_DYNAMIC_T2_VIEW; ``` -------------------------------- ### Start XSJS Application (start.js) Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/use-the-xsjs-compatibility-layer-2d970b6.md Configures and starts the XSJS application using the @sap/xsjs and @sap/xsenv modules. It retrieves service configurations for SAP HANA and UAA and listens on a specified port. ```javascript var xsjs = require('@sap/xsjs'); var xsenv = require('@sap/xsenv'); var port = process.env.PORT || 3000; var options = xsenv.getServices({ hana:{tag:'hana'}, uaa:{tag:'xsuaa'} }); xsjs(options).listen(port); console.log('XSJS application listening on port %d', port); ``` -------------------------------- ### Create and Populate JSON Table in SAP HANA Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/011-SQL-Functions/json-table-function-json-f8f6916.md Initializes a row table with a JSON string column to serve as the base for subsequent JSON_TABLE queries. This setup is required for all provided examples. ```sql CREATE ROW TABLE T1 (A INT, B NVARCHAR(5000)); INSERT INTO T1 VALUES (1, '{ "PONumber": 1, "Reference": "BSMITH-74635645", "Requestor": "Barb Smith", "User": "BSMITH", "CostCenter": "A50", "ShippingInstructions": { "name": "Barb Smith", "Address": { "street": "100 Fairchild Ave", "city": "San Diego", "state": "CA", "zipCode": 23345, "country": "USA" }, "Phone": [{"type": "Office", "number": "519-555-6310"}] }, "SpecialInstructions": "Surface Mail", "LineItems": [ {"ItemNumber": 1, "Part": {"Description": "Basic Kit", "UnitPrice": 19.95, "UPCCode": 73649587162}, "Quantity": 7}, {"ItemNumber": 2, "Part": {"Description": "Base Kit 2", "UnitPrice": 29.95, "UPCCode": 83600229374}, "Quantity": 1}, {"ItemNumber": 3, "Part": {"Description": "Professional", "UnitPrice": 39.95, "UPCCode": 33298003521}, "Quantity": 8}, {"ItemNumber": 4, "Part": {"Description": "Enterprise", "UnitPrice": 49.95, "UPCCode": 91827739856}, "Quantity": 8}, {"ItemNumber": 5, "Part": {"Description": "Unlimited", "UnitPrice": 59.95, "UPCCode": 22983303876}, "Quantity": 8} ] }'); ``` -------------------------------- ### SAP HANA: Disable Predicate Simplification Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/hint-details-4ba9edc.md This example demonstrates the use of the NO_PREDICATE_SIMPLIFICATION hint in SAP HANA. It guides the optimizer to disable the simplification of predicates, preserving their original form. ```sql Given predicate: a != 0 and a = 0 Without hint: const false With hint: a != 0 and a = 0 ``` -------------------------------- ### Initialize Node.js Project with npm (package.json) Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/use-the-xsjs-compatibility-layer-2d970b6.md Initializes a new Node.js project by defining its name, version, and start script. This file is essential for managing project dependencies and defining execution commands. ```json { "name": "xsjs", "version": "6.0.1", "scripts": { "start": "node start.js" } } ``` -------------------------------- ### Move Table Partitions Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/non-heterogeneous-alter-partition-clauses-f7ae27c.md Syntax for moving non-heterogeneous range partitions to specific indexserver hosts. Includes examples for both online and offline operations. ```SQL ::= MOVE [PARTITION [, [,...] TO [, PARTITION [, [,...] ] TO [,...]] [PHYSICAL][ONLINE] ALTER TABLE T1 MOVE PARTITION 1,2 TO 'MyServer1:34240', PARTITION 3,4 TO 'MyServer2' ONLINE; ALTER TABLE T1 MOVE PARTITION 1 TO MyServer1:34240; ``` -------------------------------- ### Define welcomeFile Property Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/090-HANA-Cloud-DB-Dev-MTA-Routes/application-router-configuration-syntax-5f77e58.md Sets the default HTML file to be served when no specific path is provided in the HTTP request. ```json "welcomeFile": "index.html" ``` -------------------------------- ### Create MQTT Client Instance using TLS Connection Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Illustrates creating an MQTT client instance with a TLS-secured connection. This involves configuring the `net` options with host, port, and certificate authority (CA) files, along with MQTT-specific settings like `clientID` and `keepAlive`. ```javascript const options = { net: { host: 'localhost', port: 1883, ca: [ fs.readFileSync('../../../truststore/cacert.pem'), fs.readFileSync('../../../truststore/cert.pem') ] }, credentials: { user: '', password: '' }, mqtt: { clientID : '', cleanSession : true, keepAlive : 30 } }; const client = new MQTT.Client(options); ``` -------------------------------- ### SAP HANA: Enable Recompilation with SQL Parameters Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/hint-details-4ba9edc.md This example shows the RECOMPILE_WITH_SQL_PARAMETERS hint in SAP HANA. It guides the optimizer to recompile queries with parameters during execution if parameters exist and the plan is not heuristic-based. ```sql SELECT * FROM my_table WHERE id = ? WITH HINT (RECOMPILE_WITH_SQL_PARAMETERS) ``` -------------------------------- ### Connect to SAP HANA Database Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Demonstrates how to initialize the hdbext module and establish a connection to an SAP HANA database using a configuration object. ```JavaScript var hdbext = require('@sap/hdbext'); var hanaConfig = { host : 'hostname', port : 30015, user : 'user', password : 'secret' }; hdbext.createConnection(hanaConfig, function(error, client) { if (error) { return console.error(error); } client.exec(...); }); ``` -------------------------------- ### SAP HANA: Enable JOIN_REMOVAL with MINIMAL Optimization Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/hint-details-4ba9edc.md This example shows how to combine the MINIMAL optimization level with the JOIN_REMOVAL hint in SAP HANA. This guides the optimizer to remove unnecessary join operations. ```sql SELECT * FROM TABLES WITH HINT (OPTIMIZATION_LEVEL(MINIMAL), JOIN_REMOVAL) ``` -------------------------------- ### Initialize VcapApplication and VcapServices with xs-env Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-java-client-libraries-for-cloud-foundry-6511bc0.md Demonstrates how to instantiate VcapApplication and VcapServices objects using either system properties or environment variables. These methods facilitate the retrieval of configuration data from the Cloud Foundry runtime environment. ```Java public static VcapApplication fromSystemProperty() throws IllegalArgumentException { return VcapApplication.from(System.getProperty(VCAP_APPLICATION)); } public static VcapApplication fromEnvironment() throws IllegalArgumentException { return VcapApplication.from(System.getenv(VCAP_APPLICATION)); } public static VcapServices fromSystemProperty() throws IllegalArgumentException { return VcapServices.from(System.getProperty(VCAP_SERVICES)); } public static VcapServices fromEnvironment() throws IllegalArgumentException { return VcapServices.from(System.getenv(VCAP_SERVICES)); } ``` -------------------------------- ### Look up HDI Data Source using Java Annotations Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/sap-hana-cloud-hdi-data-source-29639df.md Example of looking up the HDI data source in Java code using the `@Resource` annotation. This injects the DataSource object directly. ```java @Resource(name = "jdbc/my-hdi-container") private DataSource ds; ``` -------------------------------- ### XSJS Server Configuration Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md This snippet demonstrates how to configure and start an XSJS server using the @sap/xsjs library, including service bindings for UAA, HANA, scheduler, mail, and secure store. ```APIDOC ## POST /sap-archive/sap-hana-cloud-hana-database ### Description Configures and starts an XSJS server for SAP HANA Cloud HANA Database. This endpoint allows for the integration of various SAP services like UAA, HANA, Job Scheduler, Mail, and Secure Store, enabling authentication, database connectivity, job management, and email functionality. ### Method POST ### Endpoint /sap-archive/sap-hana-cloud-hana-database ### Parameters #### Query Parameters - **port** (number) - Optional - The port number for the XSJS server to listen on. Defaults to 3000. #### Request Body - **options** (object) - Required - An object containing service credentials and application options. - **uaa** (object) - Optional - UAA configuration for JWT authentication and business-user propagation to SAP HANA. - **hana** (object) - Optional - SAP HANA database connection parameters. - **jobs** (object) - Optional - Job scheduler connection parameters for registering and updating job execution status. - **mail** (object) - Optional - Mail options for the XS JavaScript `$.net.Mail` API. - **secureStore** (object) - Optional - SAP HANA database connection parameters for secure store connectivity. - **rootDir** (string) - Optional - Location of XS JavaScript files. Defaults to 'lib'. - **rootDirs** (array) - Optional - An array of directories for XS JavaScript files. Overrides `rootDir`. - **maxBodySize** (string) - Optional - Maximum body size accepted by xsjs. Defaults to '1 MB'. - **anonymous** (boolean) - Optional - Enable anonymous access without user credentials. Defaults to `false`. - **formData** (object) - Optional - Special restrictions over form-data submitted to the server. - **destinationProvider** (function) - Optional - Custom function for `$.net.http.readDestination`. - **ca** (array) - Optional - Trusted SSL certificates for outgoing HTTPS connections. - **compression** (boolean) - Optional - Enable compression for text resources. Defaults to `true`. - **auditLog** (object) - Optional - Object containing audit-log credentials. - **context** (object) - Optional - Extend the default context in `@sap/xsjs` scripts. Defaults to `{}`. - **libraryCache** (object) - Optional - Contains the `@sap/xsjs` libraries that should be cached. Defaults to `{}`. - **redirectUrl** (string) - Optional - URL to redirect to when the root path is requested. ### Request Example ```json { "options": { "uaa": "xsuaa", "hana": "hana-hdi", "jobs": "scheduler", "mail": "mail", "secureStore": "secureStore" } } ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the server has started. #### Response Example ```json { "message": "Node XS server listening on port 3000" } ``` ``` -------------------------------- ### SQL Example: Counting All Rows in MyProducts Table Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/011-SQL-Functions/count-function-aggregate-28c3b57.md This SQL query uses the COUNT(*) aggregate function to return the total number of rows present in the 'MyProducts' table. It's a straightforward way to get a row count. ```sql SELECT COUNT(*) FROM "MyProducts"; ``` -------------------------------- ### SAP Fiori Launchpad Portal Site Content Deployer mtad.yaml Configuration Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Example of an mtad.yaml file snippet showing the binding of the site-content-deployer module to the portal-service, requiring a resource of type com.sap.portal.site-content. ```yaml … modules: - name: site-content-deployer- type: javascript.nodejs requires: - name: sap-portal-services-client- … resources: - name: sap-portal-services-client- type: com.sap.portal.site-content parameters: config: siteId: ``` -------------------------------- ### Create Library and Call Member Procedure Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/call-statement-procedural-20d364c.md Illustrates creating a library named 'MyLib' with a member procedure 'MemberProc' and then calling this member procedure. The procedure takes an integer input and outputs a table with one NVARCHAR column. The CALL statement uses a placeholder (?) for the output parameter. ```sql CREATE LIBRARY MyLib AS BEGIN PUBLIC PROCEDURE MemberProc(IN i INT, OUT tv TABLE(Col1 NVARCHAR(10))) AS BEGIN tv = SELECT :i * 100 AS Col1 FROM DUMMY; END; END; CALL MyLib:MemberProc(1, ?); ``` -------------------------------- ### Get Token Information in Node.js Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/070-HANA-Cloud-DB-Dev-App-Services/user-account-and-authentication-services-c6f36d5.md Provides an example of how to retrieve the JSON Web Token (JWT) associated with the current user's security context in a Node.js application. The token contains claims about the user and their authorizations. ```javascript const xssec = require('@sap/xssec'); const xsenv = require('@sap/xsenv'); const services = xsenv.getServices({ uaa: { plan: 'application' } }); const udf = xssec.createSecurityContext(services.uaa); // Get the JWT token const token = udf.getToken(); console.log('JWT Token:', token); ``` -------------------------------- ### Configure Container-Specific Parameters using SQL Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/di-ref/10-HDI-Cloud-Administration/13-HDI-Cloud-Admin-Maintain-HDI/sap-hdi-configuration-parameters-1d9582a.md Demonstrates how to configure a specific HDI container by populating parameter tables and calling the CONFIGURE_CONTAINER_PARAMETERS procedure. This requires defining configuration and parameter tables based on _SYS_DI.TT_PARAMETERS. ```sql -- prepare configuration parameters table create table MY_CONFIG_PARAMETERS like _SYS_DI.TT_PARAMETERS; insert into MY_CONFIG_PARAMETERS(KEY, VALUE) values ('make.max_parallel_jobs', '10'); -- prepare parameters table create table MY_PARAMETERS like _SYS_DI.TT_PARAMETERS; -- call procedure call #DI.CONFIGURE_CONTAINER_PARAMETERS(MY_CONFIG_PARAMETERS, MY_PARAMETERS, ?, ?, ?); ``` -------------------------------- ### Extract Substring from String and Binary Types Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/011-SQL-Functions/substring-function-string-20e8341.md Examples demonstrating the use of the SUBSTRING function to extract specific character sequences from a string and byte sequences from a binary literal. The function takes the input value, the start position, and an optional length as parameters. ```SQL SELECT SUBSTRING ('1234567890',4,2) "substring" FROM DUMMY; SELECT SUBSTRING(x'ABCDEF',1,2) "substring" FROM DUMMY; ``` -------------------------------- ### SAP HANA: Force Column Search Operator Parallelism Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/sql-ref/010-SQL-Reference/012-SQL-Statements/hint-details-4ba9edc.md This SQL example demonstrates using the PARALLEL_COLUMN_SEARCH hint in SAP HANA to guide the optimizer to force parallelism for the column search operator. This can improve performance for multiple column searches. ```sql SELECT * FROM (SELECT t1.a, t1.b, SUM(t1.c) AS s1 , ROW_NUMBER() OVER (PARTITION by t1.b) AS rr1 FROM t1,t2 WHERE t1.a+0=t2.a+0 GROUP BY t1.a, t1.b) UNION ALL (SELECT t2.a, t2.b, SUM(t2.c) AS s2, ROW_NUMBER() OVER (PARTITION BY t2.b) AS rr2 FROM t2 GROUP BY t2.a, t2.b) WITH HINT (NO_CS_EXPR_JOIN, PARALLEL_COLUMN_SEARCH) ``` -------------------------------- ### Look up HDI Data Source using JNDI in Java Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/sap-hana-cloud-hdi-data-source-29639df.md Example of looking up the HDI data source in Java code using JNDI (Java Naming and Directory Interface). This method involves obtaining a Context and performing a lookup. ```java Context ctx = new InitialContext(); return (DataSource) ctx.lookup("java:comp/env/jdbc/my-hdi-container"); ``` -------------------------------- ### Configure Messaging Client Options with Environment Variables (JavaScript) Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/060-HANA-Cloud-DB-Dev-App-Code/standard-sap-node-js-packages-5451327.md Demonstrates how to use the '@sap/xb-msg-env' package to generate client options for '@sap/xb-msg' based on environment variables like VCAP_SERVICES and SAP_XBEM_BINDINGS. It shows the input JSON structure for environment variables and the resulting JavaScript code to obtain client options. ```json { "VCAP_SERVICES": { "rabbitmq": [ { "credentials": { "hostname": "10.11.11.11", "ports": { "15672/tcp": "8888", "5672/tcp": "9999" }, "port": "9999", "username": "user", "password": "password", "uri": "amqp://user:password@10.11.11.11:9999" }, "syslog_drain_url": null, "volume_mounts": [], "label": "rabbitmq", "provider": null, "plan": "v3.6-container", "name": "myService", "tags": [ "rabbitmq", "mbus", "pubsub", "amqp" ] } ] }, "SAP_XBEM_BINDINGS": { "outputs": { "myOutA" : { "service": "myService", "address": "topic:Cars/Velocity/milesPerHour", "reliable": false } } } } ``` ```javascript const env = require('@sap/xb-msg-env'); const opt = env.msgClientOptions('myService', [], ['myOutA']); ``` -------------------------------- ### Setting up Authentication with OAuth 2.0 Source: https://github.com/sap-archive/sap-hana-cloud-hana-database/blob/main/docs/devguide-for-cf-mta-webide/index.md This snippet provides a conceptual example of setting up authentication using OAuth 2.0, often used in SAP BTP applications. It outlines the basic flow and parameters involved in an authorization code grant flow. This is a fundamental step in securing applications. ```javascript const express = require('express'); const passport = require('passport'); const OAuth2Strategy = require('passport-oauth2').Strategy; passport.use(new OAuth2Strategy({ authorizationURL: 'https://oauth.example.com/auth', tokenURL: 'https://oauth.example.com/token', clientID: 'YOUR_CLIENT_ID', clientSecret: 'YOUR_CLIENT_SECRET', callbackURL: '/auth/callback' }, function(accessToken, refreshToken, profile, done) { // User profile retrieval logic } )); ```