HANA Stored Procedures to Create Universe Derived … · HANA Stored Procedures to Create Universe Derived Tables ... Those stored procedures will provide the SQL ... HANA Stored
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Role of the Stored Procedures ........................................................................................................................ 3
Where to use the results of the Stored Procedures ........................................................................................ 3
Data Foundation example ............................................................................................................................... 4
2. The stored procedures definition ........................................................................................................... 7
Use the stored procedures ............................................................................................................................ 17
Related Content ................................................................................................................................................ 18
The stored procedures provided in this document analyze the HANA views and write data in the HANA table called “SL_DERIVED_TABLE”.
The stored procedure called “DERIVED_TABLE_ALL” analyzes all HANA views.
The stored procedure called “DERIVED_TABLE_SINGLE” analyzes the HANA view passed in parameter.
They are both writing the result in the same table
The table “SL_DERIVED_TABLE” has 2 columns:
CUBE_NAME
SQL_SCRIPT
The “CUBE_NAME” column contains the HANA view name as it has been deployed in _SYS_BIC schema like
"_SYS_BIC"."foodmart/SALES_2006”.
The “SQL_SCRIPT” column contains the SELECT statement that can be copied and paste in a derived table definition.
The derived table can be created in a Data Foundation designed with Information Design Tool.
The stored procedures will:
Detect the variables and input parameters,
Detect the attributes and measures
Create the appropriate SQL aggregation function for the measures
Generate the attribute caption and measure caption as column name
Generate the PLACEHOLDER statement for mandatory input parameters
Generate an @Prompt universe function as PLACEHOLDER value with the appropriate data type
Where to use the results of the Stored Procedures
The goal is to create a SQL statement that picks all columns of the HANA views by taking into account attributes and measures as well as input parameters. This SQL statement will be written as a text field in a HANA table.
The SQL statement can then be copied and pasted in a universe derived table definition. The derived table is a SQL script defined in the data foundation of a universe.
The universe is authored in Information Design Tool. Universes are part of the Semantic Layer and used by BI clients such as Web Intelligence, Crystal Reports, Dashboards or Explorer.
This will lower the TCO of creating a universe on top of a SAP HANA view and also take into account the HANA variables.
HANA Stored Procedures to Create Universe Derived Tables
The following SQL scripts detail the different stored procedures and the table where the results of the stored procedures will be written.
By default, the table and stored procedures will be created in the default catalog attached to the HANA user.
The following scripts can be used in the HANA Studio to define the necessary table and stored procedures.
Table “SL_DERIVED_TABLE”
(this table will host the SQL sentence to copy and paste into the universe derived table)
DROP TABLE SL_DERIVED_TABLE;
CREATE TABLE SL_DERIVED_TABLE(
CUBE_NAME VARCHAR(255),
SQL_SCRIPT VARCHAR(5000)
);
Stored Procedure “DERIVED_TABLE_ALL”
(this commands prepares HANA to host the stored procedure which analyzes all HANA views)
DROP PROCEDURE DERIVED_TABLE_ALL;
SQL columns with attributes caption and measures caption (this stored procedure will define the sentence for a universe derived table using the caption of both attributes and measures as column names)
CREATE PROCEDURE DERIVED_TABLE_ALL
LANGUAGE SQLSCRIPT AS
COLUMN_OBJECT VARCHAR(255) := '';
COLUMN_NAME VARCHAR(255) := '';
COLUMN_CAPTION VARCHAR(255) := '';
COLUMN_TYPE_D VARCHAR(255) := '';
MEASURE_AGGREGATOR_DESC VARCHAR(255) := '';
VIEW_TYPE VARCHAR(255) := '';
VARIABLE_NAME VARCHAR(255) := '';
DESCRIPTION VARCHAR(255) := '';
VAR_CUBE_NAME VARCHAR(255) := '';
SQL_SCRIPT VARCHAR(5000) := 'SELECT ';
GROUP_BY VARCHAR(5000) := ' GROUP BY ';
PLACEHOLDER VARCHAR(5000) := '';
FIRST_ROW INT := 1;
NB_ROW INT := 0;
CURSOR c_cubes FOR
SELECT
"COLUMN_OBJECT"
FROM "_SYS_BI"."BIMC_CUBES";
CURSOR c_variables (the_cube VARCHAR(255)) FOR
SELECT
"VARIABLE_NAME",
"DESCRIPTION",
"COLUMN_TYPE_D"
FROM "_SYS_BI"."BIMC_VARIABLE"
WHERE
(
HANA Stored Procedures to Create Universe Derived Tables
SQL columns with attributes name and measures name (this stored procedure will define the sentence for a universe derived table using the technical name of both attributes and measures as column names; it can be used as an alternative to the previous stored procedure)
(this commands prepares HANA to host the stored procedure which analyzes a single HANA views passed as a parameter)
DROP PROCEDURE DERIVED_TABLE_SINGLE;
SQL columns with attributes name and measures caption (this stored procedure will define the sentence for a universe derived table using the caption of both attributes and measures as column names)
CREATE PROCEDURE DERIVED_TABLE_SINGLE (IN cube_name VARCHAR(255))
SELECT COUNT(*) INTO nb_row FROM SL_DERIVED_TABLE WHERE CUBE_NAME =
:cube_name;
if :nb_row >= 1 then
DELETE FROM SL_DERIVED_TABLE WHERE CUBE_NAME = :cube_name;
end if;
INSERT INTO SL_DERIVED_TABLE VALUES (:cube_name, :sql_script);
END;
SQL columns with attributes name and measures name (this stored procedure will define the sentence for a universe derived table using the technical name of both attributes and measures as column names; it can be used as an alternative to the previous stored procedure)
CREATE PROCEDURE DERIVED_TABLE_SINGLE (IN cube_name VARCHAR(255))
SELECT COUNT(*) INTO nb_row FROM SL_DERIVED_TABLE WHERE CUBE_NAME =
:cube_name;
if :nb_row >= 1 then
DELETE FROM SL_DERIVED_TABLE WHERE CUBE_NAME = :cube_name;
end if;
INSERT INTO SL_DERIVED_TABLE VALUES (:cube_name, :sql_script);
END;
Use the stored procedures
The following commands can be executed in the HANA studio SQL editor or in connectivity SQL editor of the information design tool, when connected to HANA
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software compyounts of other software vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.
Java is a registered trademark of Oracle Corporation.
JavaScript is a registered trademark of Oracle Corporation, used under license for technology invented and implemented by Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentiyoud herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentiyoud herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.
All other product and service names mentiyoud are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.