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

Execute SQL Commands and Create Custom Notifications with SAP Automation Pilot and SAP Alert Notification Service

Learn an approach to schedule SQL statements which are run against an SAP HANA Cloud database and send an email based on the results of the execution.

Overview

🎓 beginner 30 min. SAP HANA CloudBeginnerSAP HANA Cloud SAP HANA DatabaseSAP Alert Notification Service For SAP BTPSAP Automation PilotPython

You will learn

  • โœ”How to create a command in SAP Automation Pilot which connects to and queries an SAP HANA Cloud database instance
  • โœ”How to perform queries using the provided ExecuteHanaCloudSqlStatement
  • โœ”How to perform queries using hdbcli, the SAP HANA client driver for Python
  • โœ”How to conditionally send a notification (email) with the results of the query using the SAP Alert Notification Service
  • โœ”How to schedule an SAP Automation Pilot command
Unknown U Unknown September 7, 2025
Created by June 28, 2022
Contributors

Prerequisites

Prerequisites

  • Access to the SAP Business Technology Platform (BTP) that includes SAP HANA Cloud, SAP Alert Notification Service, and SAP Automation Pilot. These services are available in the SAP BTP free tier.

Steps

Intro

SAP HANA Cloud provides built-in alerts for items such as long running statements, table row counts, expiring database passwords, or low disk space. This tutorial will demonstrate an approach that can be used to create a notification for use cases not covered by the built-in alerts. The hotels dataset described in the tutorial Create Database Objects with SAP HANA Database Explorer contains a maintenance table where work items are described.

maintenance table
maintenance table

An SAP Automation Pilot command will be created to check if any maintenance items are unassigned, and if so, an email will be generated. The final step in the tutorial will demonstrate how to schedule the command to run once a week.

scenario
scenario

If you do not already have the HOTELS.MAINTENANCE table in an SAP HANA Cloud database, please create it now by following the first 2 steps in the Create Database Objects with SAP HANA Database Explorer tutorial.


If you do not have a subscription to the SAP Automation Pilot service, step 1 of the tutorial Take Action Following a SAP HANA Cloud Database Alert with SAP Automation Pilot provides details on how to so.


If you do not have an instance of the SAP Alert Notification service, see step 5 of the tutorial Alerts in SAP HANA Database and Data Lake.


Step 1 Create an SAP Automation Pilot command
โ€”

This step will create a catalog, an input, and a command in the SAP Automation Pilot. The command in subsequent steps will execute SQL against the database to determine if there are any unassigned maintenance items.

  1. In the SAP Automation Pilot, create a new catalog.

    create a catalog
    create a catalog

    Specify the values below.

    LabelValue
    NameCustNotif
    Display nameCustom Notifications
    DescriptionA user catalog which will hold inputs and commands demonstrating how to perform a custom notification
  2. Create an input to store the connection details for an SAP HANA Cloud database.

    create input
    create input

    Specify the values below.

    LabelValue
    CatalogCustom Notifications
    NameSAPHANADB
    DescriptionContains the details to connect to a specific SAP HANA Cloud database
  3. Add the following keys to the input.

    input with keys
    input with keys

    Key NameTypeSensitiveDescriptionValue
    hostStringnoHost value for a SAP HANA Cloud databaseCopy the SQL Endpoint from SAP HANA Cloud Central and remove :443
    portNumbernoPort value for a SAP HANA Cloud database443
    userStringnoThe user ID to connect the databaseUSER1
    passwordStringyesThe password to connect the databasePassword1

    Storing values in an input enables the values to be reused across different commands. If a value needs to be updated, it only has to be updated in one place.

  4. Create a command.

    create command
    create command

    Specify the values below.

    LabelValue
    CatalogCustom Notifications
    NameCheckMaintenanceItems
    DescriptionPerform a check to see if there are any unassigned maintenance items
  5. In the newly created command, select input and add an additional value which is the SAPHANADB input.

    add additional values
    add additional values

    Specify the values below.

    LabelValue
    AliasscriptInput
    Value TypeInput
    InputSAPHANADB

    An alternative method of passing parameters to the command uses the input keys in the contract section. This is shown in step 4.

  6. Add an output key.

    output key
    output key

    Specify the values below.

    LabelValue
    NamecheckResult
    Typestring
    SensitiveNo
    DescriptionJSON string of the result
  7. Under Configuration, add an executor.

    Add executor
    Add executor

    Click on Here and specify the values below.

    Add an executor
    Add an executor

    LabelValue
    AliasQueryDB
    CommandExecuteScript (Version: 2)
    Automap Parameterstrue

    :2 indicates that this is version 2 of the command.

    Automap parameters is not used in this tutorial, so its value can be enabled or disabled.

  8. Select QueryDB and then press the edit parameters button.

    parameters
    parameters

    Paste in the following code for the script parameter.

    Python
    #!/usr/bin/env python3
    
    print("Hello from QueryDB!")
  9. Select the output and choose Edit.

    edit output
    edit output

    LabelValue
    checkResult$(.QueryDB.output.output[0])

    This will take the result printed in the QueryDB executor and set it to the output of the command.

    For additional details on the use of the $(...) used above, see Dynamic Expression.

  10. Trigger the execution.

    trigger the command
    trigger the command

    Additional inputs are not needed.

    trigger command dialog
    trigger command dialog

    After a few seconds, the output can be seen.

    execution output
    execution output

    Output value
    Output value

    A quick way to return to the command after executing it is to click on the link shown below.

    Return to command
    Return to command

At this point, a command has been created and executed. In the next two steps, two different techniques of executing SQL against an SAP HANA Cloud database will be shown.

Step 2 Perform a query using the ExecuteHanaCloudSqlStatement command
+
Step 3 Perform a query using hdbcli in a Python script
+
Step 4 Forward results to the SAP Alert Notification Service
+
Step 5 Send a notification when there are unassigned maintenance items
+
Step 6 Scheduling commands
+
Step 7 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 7
1. Create an SAP Automation Pilot command 2. Perform a query using the ExecuteHanaCloudSqlStatement command 3. Perform a query using hdbcli in a Python script 4. Forward results to the SAP Alert Notification Service 5. Send a notification when there are unassigned maintenance items 6. Scheduling commands 7. Knowledge check

Learn more →