Site icon DataFlair

SQL Stored Procedures in SAP HANA – An Essential Application for SAP HANA

SQL Stored Procedures in SAP HANA topics

FREE Online Courses: Elevate Skills, Zero Cost. Enroll Now!

In our DataFlair series of learning application of SQL in SAP HANA, our last topic is SQL stored procedures in SAP HANA. So, let’s start by taking an insight into SQL stored procedures.

What are SQL Stored Procedures?

An SQL stored procedure is a set or group of SQL statements with a user-assigned name. This collection of SQL statements is known as a procedure and is stored in the RDBMS as a group of reusable statements.

We use these stored procedures primarily to access and modify the data residing in databases in a certain way. One major advantage of SQL stored procedures is that they can be used in multiple databases and can be shared by multiple programs.

SAP HANA SQL Stored Procedures

Following the basic concept of stored procedures, SAP HANA SQL stored procedures are also a unit or module i.e. a set of SQL statements made to perform a specific task. In SAP HANA, stored procedures are used to creating modular designs for large programs with complex designs.

Also, a different procedure can be called by another procedure. This process is the calling program. SQL procedures stores SQL statements aimed at performing a specific task at the database according to the proper process flow.

In SAP HANA, the SQL stored procedures can be created as read-only procedures or read-write procedures. Also, the stored procedures can be created at two levels in SAP HANA, at a Schema Level (in Catalog Node) or at a Package Level (in Content Node) depending on the user’s preference.

The task stored in the stored procedure will perform itself on the database whenever the set of statements are being executed in an SAP HANA application.

Key Benefits of SQL Stored Procedures

Some advantages of SQL stored procedures that work in favor of SAP HANA are as follows:

Syntax of SQL Stored Procedure in SAP HANA

CREATE PROCEDURE <proc_name> [(<parameter_clause>)] [LANGUAGE <lang>]
[SQL SECURITY <mode>] [DEFAULT SCHEMA <default_schema_name>]
[READS SQL DATA [WITH RESULT VIEW <view_name>]] AS
{BEGIN [SEQUENTIAL EXECUTION]
<procedure_body>
END
| HEADER ONLY }

Syntax Elements of Stored Procedure

How to Create SQL Stored Procedures in SAP HANA?

Follow these easy steps to create a stored procedure in SAP HANA:

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

Step 1: Open the SAP HANA Modeler. Expand the Content folder.

Right-click on the package name > New and select Procedure

Step 2: Enter the details specific to the new procedure such as Name (for instance, DataFlair1), Description, Default Schema, Package, Run rights, Access Modes, Languages.

Click on Finish.

A script view pane will open where you write your SQL script for stored procedures. The general script is:

PROCEDURE “<procedure_name>” ( )
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER

-- DEFAULT SCHEMA <default_schema_name>
READS SQL DATA AS

BEGIN

/**************************************
Write your procedure logic

************************************/

END

Step 3: Add a SELECT statement between BEGIN and END.

Save the script by clicking on the (green tick icon) Save button.

Step 4: Click on the Execute button to execute the script.

Upon successful execution of the script, the new stored procedure can be seen under the Procedures folder of the Content node under your schema.

Summary

This concludes our tutorial on SQL stored procedures and its significance in SAP HANA. After completing this tutorial, you have learned all the uses of SQL in SAP HANA. We hope you are clear with all the concepts.

If you have any queries related to SQL stored procedures or SAP HANA, do leave your comments below. We will be happy to help.

Exit mobile version