SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Executing SAP HANA Cloud Tasks from the Command Line

Learn how to execute administrative tasks from the command line which can be more efficient and less error prone when performing repetitive tasks.

Overview

🎓 intermediate 20 min. SAP HANA CloudIntermediateSAP HANA Cloud SAP HANA DatabaseSAP HANA Cloud Data Lake

You will learn

  • โœ”How to execute SQL commands against an SAP HANA Cloud instance using hdbsql or dbisql from the command line
  • โœ”An overview of two different runtimes that SAP HANA Cloud can be provisioned into
  • โœ”How to use the BTP, CF, and service manager command line interfaces (CLIs) with an SAP HANA Cloud instance SAP HANA Cloud Central can be used to perform many administrative tasks for SAP HANA Cloud instances within a graphical interface such as creating, deleting, starting, stopping, updating, upgrading, cloning, or running diagnostic checks.
    SAP HANA Cloud Central
    SAP HANA Cloud Central
    A text-based interface can be faster, more efficient, and less error prone when performing repetitive tasks. This tutorial will provide examples of performing administrative tasks using the command line.
    running and scheduling tasks
    running and scheduling tasks
    > Access help from the SAP community or provide feedback on this tutorial by navigating to the “Feedback” link located on the top right of this page.
Unknown U Unknown May 2, 2025
Created by September 23, 2023
Contributors

Prerequisites

Prerequisites

  • An SAP BTP account
  • An SAP HANA Cloud instance
  • SAP HANA Cloud Clients

Steps

Step 1 Executing SQL Statements from a shell
โ€”

hdbsql is a command line tool that is included in the SAP HANA Client which can be used to run SQL statements from a shell or script.

Additional details on how to install the SAP HANA Client and on using hdbsql can be found in the tutorial mission Use Clients to Query an SAP HANA Database.

The example shown below uses HANA_Configuration_Overview_SHC which is one of the many queries included in the SAP Note: 1969700 - SQL Statement Collection for SAP HANA. Note that the entries with the suffix _SHC are for SAP HANA Cloud, SAP HANA databases.

  1. Open the SAP Note, download the zip file, and unzip its contents. It contains many diagnostic queries for an SAP HANA database. The download section shown below is near the bottom of the SAP Note.

    download attachment
    download attachment

    The HANA_Configuration_Overview_SHC.txt diagnostic query will be used.

    hana configuration overview
    hana configuration overview

  2. Create a hdbuserstore key that contains the SQL endpoint (host:port), user, and password needed to connect to the SAP HANA database instance.

    Shell
    hdbuserstore Set AdminUserKey <SQL ENDPOINT> DBADMIN <PASSWORD>

    The list of keys can be seen with the command below.

    Shell
    hdbuserstore List
  3. Run the command.

    Shell
    hdbsql -A -o results.txt -U AdminUserKey -I HANA_Configuration_Overview_SHC.txt
    type results.txt

    An example of the result is shown below.

    Executing SQL from a command line using hdbsql
    Executing SQL from a command line using hdbsql

  4. Review the options used.

    • -A provides an aligned output
    • -o results.txt writes the output to a file named results.txt
    • -U AdminUserKey instructs hdbsql to retrieve the host, port, user name and password from the user store. This is helpful when running scripts as the credentials are not included in the command line
    • -I HANA_Configuration_Overview_SHC.txt specifies the SQL to be executed
  5. Should you wish to run a diagnostic script against an SAP HANA Cloud, data lake Relational Engine use dbisql.

    Instructions to install the data lake client and use dbisql are in the tutorial mission Use Clients to Query a Data Lake Relational Engine.

  6. Create a file named diagnosticQuery.sql and add the contents below. For additional details see sa_conn_info System Procedure.

    SQL
    CALL sa_conn_info();

    Execute the SQL.

    Shell
    dbisql -c "uid=<USER_ID>;pwd=<PASSWORD>;host=<SQL ENDPOINT>;ENC=TLS(tls_type=rsa;direct=yes)" diagnosticQuery.sql
    Shell
    dbisql -c 'uid=<USER_ID>;pwd=<PASSWORD>;host=<SQL ENDPOINT>;ENC=TLS(tls_type=rsa;direct=yes)' diagnosticQuery.sql

    An example of the result is shown below.

    dbisql
    dbisql

Step 2 SAP HANA Cloud runtimes
+
Step 3 Overview of the CLIs
+
Step 4 Examples using the BTP CLI
+
Step 5 Additional Examples using the BTP CLI (Optional)
+
Step 6 Examples using the CF CLI
+
Step 7 Examples using the Service Manager CLI
+
Step 8 Knowledge check
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 8
1. Executing SQL Statements from a shell 2. SAP HANA Cloud runtimes 3. Overview of the CLIs 4. Examples using the BTP CLI 5. Additional Examples using the BTP CLI (Optional) 6. Examples using the CF CLI 7. Examples using the Service Manager CLI 8. Knowledge check

Learn more →