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

Create HANA Stored Procedure and Expose as CAP Service Function (SAP HANA Cloud)

Further combine SAP HANA Cloud native artifacts with the SAP Cloud Application Programming Model (CAP), and expose SQLScript procedures as service functions.

Overview

🎓 intermediate 20 min. SAP HANA CloudIntermediateSAP HANASAP Business Application StudioSAP Cloud Application Programming Model

You will learn

  • โœ”How to create and deploy an SAP HANA Cloud SQLScript stored procedure
  • โœ”How to create a service function implemented via an SAP HANA SQLScript stored procedure
  • โœ”How to use a CAP service exit to implement the service function
Thomas Jung T Thomas Jung July 26, 2024
Created by March 1, 2021
Contributors

Prerequisites

Prerequisites

  • This tutorial is designed for SAP HANA Cloud. It is not designed for SAP HANA on premise or SAP HANA, express edition.
  • You have created database artifacts and loaded data as explained in the previous tutorial.

Steps

Video Version

Video tutorial version:

Step 1 Create stored procedure
โ€”

  1. In the /db/src folder create a new database artifact named sleep of type hdbprocedure

    Create Procedure
    Create Procedure

  2. This is a very simple SAP HANA Stored Procedure that calls the built-in SYNC library to put processing to sleep for 10 seconds. It’s a nice tool to be able to test the impact of long running queries without actually putting unnecessary load on the system.

    sleep
    sleep

    SQL
    PROCEDURE "sleep" ( )
       LANGUAGE SQLSCRIPT
       SQL SECURITY INVOKER
       READS SQL DATA AS
    BEGIN USING SQLSCRIPT_SYNC as SyncLib;
    
    call SyncLib:SLEEP_SECONDS(10);
    
    END
  3. Deploy the to the database again using the SAP HANA Projects view.

    Deploy
    Deploy

  4. Check the deployment log to make sure everything was successfully created in the database.

    Check Log
    Check Log

  5. Open the HDI Container in the Database Explorer

    Open Database Explorer
    Open Database Explorer

  6. This new Procedure is there now and can be tested.

    Test from Database Explorer
    Test from Database Explorer

  7. There isn’t much output from the execution, but the 10 second wait makes testing quite easy.

    10 second wait
    10 second wait

Step 2 Add procedure to CAP service
+

Resources

Discussion

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

Submit detailed feedback Discuss in Community
Steps
Step 1 of 2
1. Create stored procedure 2. Add procedure to CAP service

Learn more →