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

Parallel Processing and Parameters

Leverage SQLScript in stored procedures, user defined functions, and user defined libraries.

Overview

🎓 intermediate 15 min. SAP HANAIntermediateSqlSAP HANA CloudSAP Business Application Studio

You will learn

  • โœ”How to take full advantage of parallel processing in SAP HANA by using table variables
Rich Heilman R Rich Heilman November 1, 2022
Created by February 11, 2021
Contributors

Prerequisites

Prerequisites

Steps

Intro

In this exercise, we will modify the code of procedure get_po_header_data so that it takes full advantage of the parallel processing within HANA by using table variables.


Step 1 Edit previous procedure
โ€”

  1. Return to your procedure called get_po_header_data.

    Existing Procedure
    Existing Procedure

  2. Define two tabular output parameters which will be used to explicitly pass the results of the SELECT statements to the caller.

    Define output
    Define output

  3. Next, assign SELECT statements to the output parameters as shown here.

    assign select
    assign select

  4. The completed code should be similar to this.

    SQLScript
    PROCEDURE "get_po_header_data"(
             OUT EX_PO_CREATE_CNT TABLE(
               CREATE_CNT INTEGER,
               "CREATEDBY" NVARCHAR(255)),
            OUT EX_PO_CHANGE_CNT TABLE(
               CHANGE_CNT INTEGER,
               "MODIFIEDBY" NVARCHAR(255))  )
       LANGUAGE SQLSCRIPT
       SQL SECURITY INVOKER
       --DEFAULT SCHEMA <default_schema_name>
       READS SQL DATA AS
    BEGIN
    
    ex_po_create_cnt =  SELECT COUNT(*) AS CREATE_CNT, "CREATEDBY"
         FROM "OPENSAP_PURCHASEORDER_HEADERS" WHERE ID IN (
                         SELECT "POHEADER_ID"
                              FROM "OPENSAP_PURCHASEORDER_ITEMS"
              WHERE "PRODUCT_PRODUCTID" IS NOT NULL)
                GROUP BY  "CREATEDBY";
    
    ex_po_change_cnt = SELECT COUNT(*) AS CHANGE_CNT, "MODIFIEDBY"
         FROM "OPENSAP_PURCHASEORDER_HEADERS"  WHERE ID IN (
                         SELECT "POHEADER_ID"
                              FROM "OPENSAP_PURCHASEORDER_ITEMS"
              WHERE "PRODUCT_PRODUCTID" IS NOT NULL)
                 GROUP BY  "MODIFIEDBY";
    
    END
Step 2 Save, deploy, run and check results
+

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. Edit previous procedure 2. Save, deploy, run and check results

Learn more →