You are on page 1of 7

12/22/2020 Table Functions in SAP HANA

Join now Sign in

Table Functions in SAP HANA


Surendra Kumar Reddy Koduru Follow
SAP BI/HANA & SQL (Analytics)/… 42 1 3

In this article I'm going explain how to create SAP HANA Calculation View using Table Function.
In my previous article SAP HANA Calculation View - SQL Script, I explained by using SQL Script
with SQL Scripted Calculation View, but in current article I'm going to use the same SQL code
using in "Table Function".
In SAP HANA, there are multiple ways to provide a solution for a given business requirement.
Choosing Method-1 or Method-2 or Method-n depends on various parameters/situations. It is
not like using Scripted Views are old method and using Table Functions are new method. In
below example, I used the same code (from my previous article), it is working in the below
Calculation view. But it is always good to choose the best method based on
requirements/situation.
We are getting new things from version to version in SAP HANA DB, because SAP is doing lot of
R&D and technology is evolving.
Lets start our journey with User-Defined Functions (UDF), and in this article I'm going to
explain/use Table User-Defined Functions (UDF).
In SQL, we have Scalar and Table User-Defined Functions (UDF), User Defined Function (UDF)
enables you to build complex logic into a single database object.
Scalar user-defined function (UDF) is a custom function that will returns only one scalar value as
output.
Table user-defined function (UDF) is a custom function that will returns only one Tabular value
as output.
Step 1: Create a table type which is required to display OUTPUT (it may be from one table or
from multiple tables).
In SAP HANA Calculation View - SQL Script, I used five tables, here also I'm going to use the
same five tables and same OUTPUT fields.
Use the below SQL Code and create a Table Type.

https://www.linkedin.com/pulse/table-functions-sap-hana-surendra-kumar-reddy-koduru 1/7
12/22/2020 Table Functions in SAP HANA

Join now Sign in

See the table type once the above code is executed successfully.

Step 2: Use SAP HANA Development Perspective, create a Work Space in Repositories and create
XS Project in Project Explorer and assign Work Space.

https://www.linkedin.com/pulse/table-functions-sap-hana-surendra-kumar-reddy-koduru 2/7
12/22/2020 Table Functions in SAP HANA

Join now Sign in

Then go to Repositories, Create a Repository Package, or if you have already then choose your
repository package and create new Table Function and give File name "GET_SALESORDERS_TF"

The below Function will creates with template (code).

Step 3: We need to do simple modifications to above code and keep our code here.

https://www.linkedin.com/pulse/table-functions-sap-hana-surendra-kumar-reddy-koduru 3/7
12/22/2020 Table Functions in SAP HANA

Join now Sign in

Activate.

https://www.linkedin.com/pulse/table-functions-sap-hana-surendra-kumar-reddy-koduru 4/7
12/22/2020 Table Functions in SAP HANA

Step 4: Create a Calculated View in SAP HANA Modeler Perspective and call/assign the above
Table Function. Once we add the Table Function, then it will show all fields which are available in Join now Sign in

Function (Table Type).

Add all fields in Projection-->Aggregation-->Semantics.

Save & Activate.


Step 5: Display Data.

https://www.linkedin.com/pulse/table-functions-sap-hana-surendra-kumar-reddy-koduru 5/7
12/22/2020 Table Functions in SAP HANA

Join now Sign in

Published By
Surendra Kumar Reddy Koduru Follow
SAP BI/HANA & SQL (Analytics)/Po…

Table Functions in SAP HANA

1 comment

Sign in to leave your comment

Rajib Chakraborty
2y
Solution Architect / Project Manager - RPA, AI, Cognitive Automation | DWH, Data Management &
Migrations | SAP HANA, BI/Analytics |

Nice document, Surendra.. thanks for sharing.


Like Reply

More from Surendra Kumar Reddy Koduru 8 articles

Data loads to SAP HANA AMDP in SAP HANA SAP HANA Ca


DB using SAP DS (Data… February 20, 2019 View - SQL Sc
October 29, 2019 January 27, 201

© 2020 About

https://www.linkedin.com/pulse/table-functions-sap-hana-surendra-kumar-reddy-koduru 6/7
12/22/2020 Table Functions in SAP HANA

Accessibility User Agreement


Join now Sign in
Privacy Policy Cookie Policy

Copyright Policy Brand Policy

Guest Controls Community Guidelines

Language

https://www.linkedin.com/pulse/table-functions-sap-hana-surendra-kumar-reddy-koduru 7/7

You might also like