Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

Table Functions in SAP HANA – step by step


guide
 March 4, 2019 (http://www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/)  webadmin
(http://www.sapspot.com/author/webadmin/)

SAP HANA Table Functions


Recently I spoke to multiple developers working on SAP HANA Native system for developing reports.
What really surprised me was the fact, that most of them are still using calculation views of a SQL
Script type instead of Table Functions. What is more, some of them were even not aware that these
type of views are deprecated and replaced by Table Functions. I also haven’t found any step by step
tutorial describing when to create Table Functions, how to do that, what are the benefits and how to
consume them in calculation views.

This inspired me to write the article about Table Functions and share my experience on that topic.

What are Table Functions?


Since SP11 calculation views of SQL Script type are deprecated. As an alternative SAP introduced
new development artifact called Table Function. HANA provides Migration tool, which enables
automatic conversion script-based Calculation View into Table Function.

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 1/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

Table functions are used whenever the graphical views are not sufficient i.e. for loops, executing
custom functions or complex queries.

What are the Pros and Cons of using Table Functions?


Pros:

SQL Script gives much more functionality and flexibility (more functions available, complex logic
can be implemented in easier way, SQL can be combined with Application Function Library –
AFL giving even more functions for complex analysis)

Cons:

Maintenance is much more difficult (preserving order and data types of output columns; data
preview for part of code is not so straightforward comparing to previewing nodes in graphical
views; when changing output – both Table Function and view on top of it needs to be adjusted;
etc.)
Multiple-value input parameters are not supported (there is no easy way of passing multiple
values into single input parameter to Table Function, however there is workaround for that)
By definition graphical views provide better performance thanks to HANA’s optimizer
No GUI available – SQL Script knowledge is necessary

Generally Table Functions should are used in case if the logic cannot be covered by graphical view or
the logic is too complex to model it graphically.

How to create Table Function?


Scenario: Business wants to display a report showing number of working days between
“ORDERDATE” and “SHIPPEDDATE“. To calculate it we need to use WORKDAYS_BETWEEN SQL
function, which is not available in graphical view. Additionally this function should display orders only
for specific period of time which will be provided by the user.

To start developing database objects, go to Development Perspective:

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 2/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

Go to Repositories tab:

Right click on destination package and select New -> Other

In wizard type Table Function, select it and click Next

Provide Table Function name and click Finish

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 3/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

Table function window will open.

Adjust the code to the requirements

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 4/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

I. [Optional] Provide input parameters including data types. This is needed when you want to
parametrize Table Function.

II. [Mandatory] Set TABLE as the output type.

III. [Optional] Provide default schema for the query. This is needed when you transport the function
between instances with different schemas i.e. in development system you are using “DEV” schema,
but on production all tables are placed in “PROD” schema. If you provide the default schema in the
definition of Table Function, then while transporting this schema will be automatically replaced with the
schema of target system (based on schema mapping). When applying default value for schema
mapping, in the query you should use table names without schemas i.e simply use “ORDERS” instead
of “DEV“.”ORDERS“.

IV. [Mandatory] Add RETURN phrase before the final select statement.

V. [Mandatory] Add select statement.

VI. [Optional] Apply input parameters in the WHERE clause. Add leading colons (“:”) when calling
each parameter.

VII. [Mandatory] Add semicolon (“;”) at the end of the statement.

VIII. [Mandatory] List all the output columns. Preserve the columns order, column names (case
sensitive) and their data types consistent with the select statement

After writing Table Function definition activate it and make sure that there is no error after activation.

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 5/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

Be aware that any of Data Definition (CREATE, ALTER, etc.) or Data Manipulation (INSERT, UPDATE
etc.) operators are not allowed in Table Functions.

How to query Table Functions?


Calling table Functions in SQL console is very easy. They are executed in the FROM clause. When
executing the function, provide whole name of the function. In brackets provide values for input
parameters. If there are no input parameters – leave the brackets empty ( they are always
mandatory!!! ).

How to consume Table Function in Calculation View?


Using Table Function as a source in Calculation View is also very simple. Create a new calculation
view, and when adding object for the projection, type name of the Table Function:

If Table Function is using input parameters you need to recreate them also in the view. Go to
Parameters/Variables tab, click on Input Parameter Manage Mapping and select Data sources.

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 6/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

Click Auto Map By Name button to automatically copy input parameters from the Table Functions to
the view.

Now when previewing data on the view, there will be pop up with input parameters. Once values are
inputted they will be passed directly to the table function and results will be displayed.

What are the limitations of Table Functions?


The main limitation of table function is that you can pass only single values for each input parameter,
which can be very annoying, because in most cases user wants to have possibility to pass multiple
values in selection criteria of his report.

There is a workaround for that limitation, which can help to fulfill requirement of passing multiple
values directly to the query.

 SAP HANA (http://www.sapspot.com/category/erp/sap-hana/)  SAP BW/4HANA


(http://www.sapspot.com/tag/sap-bw4hana/), sap hana (http://www.sapspot.com/tag/sap-hana/).  permalink

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 7/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

(http://www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/).

 SLT based HANA replication-FusionOps activity (http://www.sapspot.com/slt-based-hana-replication-


fusionops-activity/)

Mass Transports Import in SAP  (http://www.sapspot.com/mass-transports-import-in-sap/)

Leave a Reply
Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Post Comment

Search
Search... 

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 8/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

(http://bit.ly/erpprep)

Ads

POPULAR RECENT 

Basics of SAP HANA (http://www.sapspot.com/basics-sap-hana/)


Jan 9, 2017
hana/)
s-sap-
m/basic
spot.co
ww.sap
(http://w

Seamless Big Data tiering with HANA, Hadoop and Vora…with a little help from DLM – Part 1
-vorawit (http://www.sapspot.com/seamless-big-data-tiering-hana-hadoop-vorawith-little-help-dlm-part-
hadoop
hana-
tiering-
data-
big-
less-
m/seam
spot.co
ww.sap
(http://w
part-1/)
dlm-
help-
h-little-
1/)
Jun 24, 2016

Business Partner Setup in SAP S/4HANA (http://www.sapspot.com/business-partner-setup-in-sap-s-


4hana/)

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 9/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

Jul 2, 2018

4hana/)
s-
in-sap-
setup-
partner-
ess-
m/busin
spot.co
ww.sap
(http://w

Inter-company STO with SD Delivery, Billing & LIV (http://www.sapspot.com/inter-company-sto-


sd-delivery-billing-liv/)
liv/)
-billing-
delivery
sd-
y-sto-
compan
m/inter-
spot.co
ww.sap
(http://w Aug 19, 2017

Employee Central – SAP ERP HCM prepackaged Integration: how to change the standard field
mapping (http://www.sapspot.com/employee-central-sap-erp-hcm-prepackaged-integration-
-standar change-standard-field-mapping/)
change
on-
integrati
aged-
prepack
hcm-
erp-
sap-
central-
oyee-
m/empl
spot.co
ww.sap
(http://w
g/)
mappin
d-field-
Jan 22, 2018

Archives

 December 2020 (http://www.sapspot.com/2020/12/) (19)

 November 2020 (http://www.sapspot.com/2020/11/) (25)

 October 2020 (http://www.sapspot.com/2020/10/) (28)

 September 2020 (http://www.sapspot.com/2020/09/) (30)

 August 2020 (http://www.sapspot.com/2020/08/) (26)

 July 2020 (http://www.sapspot.com/2020/07/) (32)

 June 2020 (http://www.sapspot.com/2020/06/) (28)

 May 2020 (http://www.sapspot.com/2020/05/) (25)

 April 2020 (http://www.sapspot.com/2020/04/) (29)

 March 2020 (http://www.sapspot.com/2020/03/) (29)

 February 2020 (http://www.sapspot.com/2020/02/) (25)

 January 2020 (http://www.sapspot.com/2020/01/) (22)

 December 2019 (http://www.sapspot.com/2019/12/) (30)

 November 2019 (http://www.sapspot.com/2019/11/) (22)

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 10/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

 October 2019 (http://www.sapspot.com/2019/10/) (26)

 September 2019 (http://www.sapspot.com/2019/09/) (21)

 August 2019 (http://www.sapspot.com/2019/08/) (13)

 July 2019 (http://www.sapspot.com/2019/07/) (18)

 June 2019 (http://www.sapspot.com/2019/06/) (22)

 May 2019 (http://www.sapspot.com/2019/05/) (24)

 April 2019 (http://www.sapspot.com/2019/04/) (17)

 March 2019 (http://www.sapspot.com/2019/03/) (23)

 February 2019 (http://www.sapspot.com/2019/02/) (6)

 January 2019 (http://www.sapspot.com/2019/01/) (18)

 December 2018 (http://www.sapspot.com/2018/12/) (15)

 November 2018 (http://www.sapspot.com/2018/11/) (15)

 October 2018 (http://www.sapspot.com/2018/10/) (14)

 September 2018 (http://www.sapspot.com/2018/09/) (14)

 August 2018 (http://www.sapspot.com/2018/08/) (15)

 July 2018 (http://www.sapspot.com/2018/07/) (12)

 June 2018 (http://www.sapspot.com/2018/06/) (13)

 May 2018 (http://www.sapspot.com/2018/05/) (13)

 April 2018 (http://www.sapspot.com/2018/04/) (12)

 March 2018 (http://www.sapspot.com/2018/03/) (11)

 February 2018 (http://www.sapspot.com/2018/02/) (12)

 January 2018 (http://www.sapspot.com/2018/01/) (15)

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 11/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

 December 2017 (http://www.sapspot.com/2017/12/) (12)

 November 2017 (http://www.sapspot.com/2017/11/) (12)

 October 2017 (http://www.sapspot.com/2017/10/) (21)

 September 2017 (http://www.sapspot.com/2017/09/) (15)

 August 2017 (http://www.sapspot.com/2017/08/) (19)

 July 2017 (http://www.sapspot.com/2017/07/) (23)

 June 2017 (http://www.sapspot.com/2017/06/) (24)

 May 2017 (http://www.sapspot.com/2017/05/) (21)

 April 2017 (http://www.sapspot.com/2017/04/) (23)

 March 2017 (http://www.sapspot.com/2017/03/) (6)

 February 2017 (http://www.sapspot.com/2017/02/) (3)

 January 2017 (http://www.sapspot.com/2017/01/) (8)

 December 2016 (http://www.sapspot.com/2016/12/) (11)

 November 2016 (http://www.sapspot.com/2016/11/) (14)

 October 2016 (http://www.sapspot.com/2016/10/) (6)

 September 2016 (http://www.sapspot.com/2016/09/) (9)

 August 2016 (http://www.sapspot.com/2016/08/) (12)

 July 2016 (http://www.sapspot.com/2016/07/) (11)

 June 2016 (http://www.sapspot.com/2016/06/) (15)

 May 2016 (http://www.sapspot.com/2016/05/) (14)

 April 2016 (http://www.sapspot.com/2016/04/) (2)

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 12/13
12/22/2020 Table Functions in SAP HANA – step by step guide - SAPSPOT

Contact Us (http://www.sapspot.com/contact-us/) SAP Certification (http://www.sapspot.com/sap-certification/)

Copyright © 2018 SAPSPOT | Powered by Wordpress Theme by Colorlib (http://colorlib.com/wp/) Powered by WordPress
(http://wordpress.org/)

www.sapspot.com/table-functions-in-sap-hana-step-by-step-guide/ 13/13

You might also like