30.11.2012 Views

hana_dev_en

hana_dev_en

hana_dev_en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SAP HANA Appliance Software SPS 05<br />

Docum<strong>en</strong>t Version: 1.0 - 2012-11-29<br />

SAP HANA Developer Guide<br />

PUBLIC


Table of Cont<strong>en</strong>ts<br />

1 Overview. ....................................................................8<br />

2 SAP HANA. ...................................................................9<br />

2.1 The SAP HANA In-Memory Database. ................................................ 9<br />

2.1.1 Columnar Data Storage. ...................................................9<br />

2.1.2 Parallel Processing. ......................................................10<br />

2.1.3 Simplifying Applications. ..................................................10<br />

2.2 SAP HANA Database Architecture. ..................................................11<br />

2.3 SAP HANA Ext<strong>en</strong>ded Application Services. ............................................12<br />

2.4 Refactoring SAP HANA Based Applications. ........................................... 15<br />

3 SAP HANA as a Developm<strong>en</strong>t Platform. ............................................16<br />

3.1 Developer Sc<strong>en</strong>arios. ........................................................... 16<br />

3.1.1 Sc<strong>en</strong>ario: Developing Native SAP HANA Applications. ............................. 17<br />

3.1.2 Sc<strong>en</strong>ario: Using Database Cli<strong>en</strong>t Interfaces. .................................... 18<br />

3.2 Developm<strong>en</strong>t Objects. ...........................................................19<br />

3.3 Repository. ...................................................................21<br />

3.4 SAP HANA Studio. .............................................................23<br />

3.4.1 Modeler Perspective. .................................................... 23<br />

3.4.2 SAP HANA Developm<strong>en</strong>t Perspective. ........................................25<br />

3.4.3 Debug Perspective. ..................................................... 30<br />

3.4.4 Administration Console Perspective. ......................................... 31<br />

3.5 Getting Started. ...............................................................32<br />

3.5.1 Adding a System. .......................................................33<br />

4 Setting up Your Application. .................................................... 34<br />

4.1 Setting up Delivery Units. ........................................................ 35<br />

4.1.1 Maintaining the Delivery-Unit V<strong>en</strong>dor ID. .......................................35<br />

4.1.2 SAP HANA Delivery Unit Naming Conv<strong>en</strong>tions. ..................................36<br />

4.1.3 Creating a Delivery Unit. ..................................................36<br />

4.2 Using SAP HANA Projects. ....................................................... 37<br />

4.2.1 SAP HANA Repository: Workspaces. .........................................38<br />

4.2.2 Creating a Repository Workspace. ...........................................39<br />

4.2.3 SAP HANA Studio Projects. ................................................39<br />

4.2.4 Creating a Project for SAP HANA XS. .........................................40<br />

4.2.5 Sharing a Project for SAP HANA XS. ......................................... 40<br />

4.2.6 Importing a Project in SAP HANA XS. .........................................41<br />

4.3 Maintaining Repository Packages. ..................................................42<br />

2<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Table of Cont<strong>en</strong>ts


4.3.1 SAP HANA Repository Packages and Namespaces. ...............................43<br />

4.3.2 Defining Repository Package Privileges. .......................................46<br />

4.3.3 Creating a Package. .....................................................46<br />

4.3.4 Defining a Package Hierarchy. ..............................................47<br />

4.4 Creating the Application Descriptors. ................................................49<br />

4.4.1 The SAP HANA XS Application Descriptor. .....................................49<br />

4.4.2 Create an Application Descriptor File. .........................................50<br />

4.4.3 The Application-Access File. ...............................................50<br />

4.4.4 Application-Access File Keyword Options. ..................................... 53<br />

4.4.5 Application-Access URL Rewrite Rules. ....................................... 56<br />

4.4.6 Enabling Access to SAP HANA XS Application Packages. ...........................57<br />

4.4.7 The Application-Privileges File. ............................................. 59<br />

4.4.8 Create an SAP HANA XS Application Privileges File. .............................. 60<br />

4.5 Tutorial: My First SAP HANA Application. .............................................62<br />

4.5.1 Op<strong>en</strong> the Developm<strong>en</strong>t Perspective. ......................................... 62<br />

4.5.2 Add a System. .........................................................63<br />

4.5.3 Add a Workspace. ...................................................... 66<br />

4.5.4 Add a Project. ......................................................... 67<br />

4.5.5 Share Your Project. ..................................................... 68<br />

4.5.6 Write Server-Side JavaScript. ..............................................70<br />

4.5.7 Retrieve Data. ......................................................... 72<br />

5 Setting up the Persist<strong>en</strong>ce Model. ................................................74<br />

5.1 Schema. .................................................................... 75<br />

5.2 Creating Schemas. .............................................................76<br />

5.3 Tables. ..................................................................... 76<br />

5.4 Creating Tables. ...............................................................77<br />

5.5 Sequ<strong>en</strong>ces. ..................................................................78<br />

5.6 Creating Sequ<strong>en</strong>ces. ............................................................79<br />

5.7 SQL Views. .................................................................. 80<br />

5.8 Creating SQL Views. ............................................................81<br />

5.9 Data Provisioning Using Table Import. ...............................................82<br />

5.9.1 Table-Import Model. .....................................................83<br />

5.9.2 Table-Import Data. ......................................................83<br />

5.9.3 Table-Import Ext<strong>en</strong>sions. ................................................. 84<br />

5.9.4 Table-Import Configuration-File Syntax. .......................................84<br />

5.10 Importing Data Using Table Import. .................................................85<br />

5.11 Using Imported Table Data in SAP HANA. .............................................87<br />

5.12 Using Imported Table Data in an SAP HANA XS Application. ................................88<br />

5.13 Ext<strong>en</strong>ding a Table Import. ........................................................89<br />

SAP HANA Developer Guide<br />

Table of Cont<strong>en</strong>ts<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 3


6 Setting Up the Analytic Model. ...................................................92<br />

6.1 Setting Up the Modeling Environm<strong>en</strong>t. ...............................................94<br />

6.1.1 Setting Modeler Prefer<strong>en</strong>ces. .............................................. 94<br />

6.1.2 Configuring the Import Server. ............................................. 95<br />

6.1.3 Importing Table Definitions. ............................................... 95<br />

6.1.4 Loading Data into Tables. ................................................. 97<br />

6.1.5 Copying Cont<strong>en</strong>t Delivered by SAP. ..........................................99<br />

6.1.6 Mapping the Authoring Schema to the Physical Schema. ..........................100<br />

6.1.7 G<strong>en</strong>erating Time Data. ...................................................102<br />

6.2 Creating Views. ...............................................................103<br />

6.2.1 Attributes and Measures. ................................................ 103<br />

6.2.2 Attribute Views. .......................................................104<br />

6.2.3 Creating Attribute Views. .................................................105<br />

6.2.4 Analytic Views. ........................................................109<br />

6.2.5 Creating Analytic Views. ..................................................110<br />

6.2.6 Calculation Views. ......................................................115<br />

6.2.7 Creating Calculation Views . ...............................................116<br />

6.2.8 Assigning Variables. .................................................... 123<br />

6.2.9 Creating Input Parameters. ...............................................125<br />

6.2.10 Creating Hierarchies. ....................................................127<br />

6.2.11 Using Curr<strong>en</strong>cy and Unit of Measure. ........................................130<br />

6.2.12 Activating Objects. .....................................................132<br />

6.3 Creating Decision Tables. ....................................................... 133<br />

6.3.1 Changing the Layout of a Decision Table. ..................................... 139<br />

6.3.2 Using Parameters in a Decision Table. ........................................139<br />

6.4 Managing Object Versions. ...................................................... 140<br />

6.4.1 Switching Ownership of Inactive Objects. .....................................140<br />

6.4.2 Toggling Versions of Cont<strong>en</strong>t Objects. ........................................141<br />

6.4.3 Viewing Version History of Cont<strong>en</strong>t Objects. ...................................142<br />

6.5 Working with Objects. ..........................................................142<br />

4<br />

6.5.1 Managing Layout. ......................................................142<br />

6.5.2 Filtering Packages and Objects. ............................................142<br />

6.5.3 Refactoring Objects. ....................................................143<br />

6.5.4 Validating Models . .....................................................144<br />

6.5.5 G<strong>en</strong>erating Object Docum<strong>en</strong>tation. ..........................................144<br />

6.5.6 Enabling Multilanguage Support for Objects. ...................................145<br />

6.5.7 Checking Model Refer<strong>en</strong>ces. .............................................. 145<br />

6.5.8 Viewing the Job Log. ....................................................146<br />

6.5.9 Maintaining Search Attributes. .............................................146<br />

6.5.10 Previewing Data of Cont<strong>en</strong>t Objects. .........................................146<br />

6.5.11 Functions used in Expressions. .............................................147<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Table of Cont<strong>en</strong>ts


6.5.12 Searching Tables, Models and Column Views. ..................................152<br />

6.5.13 Setting Keyboard Shortcuts. .............................................. 153<br />

6.5.14 Copying an Object. .....................................................154<br />

6.6 Importing BW Objects. ......................................................... 154<br />

7 Developing Procedures. ....................................................... 158<br />

7.1 Editing SQLScript. .............................................................159<br />

7.2 Debugging SQLScript. ..........................................................161<br />

7.3 Developing Procedures in the Modeler Editor. .........................................162<br />

8 Defining Web-based Data Access. ............................................... 164<br />

8.1 Data Access with OData in SAP HANA XS. ............................................164<br />

8.1.1 OData in SAP HANA XS. ................................................. 164<br />

8.1.2 OData Service Definitions. ................................................165<br />

8.1.3 OData URI Parameters, Query Options, and Features. ............................ 167<br />

8.1.4 OData Security Considerations. ............................................183<br />

8.1.5 Defining the Data an OData Service Exposes. ...................................183<br />

8.1.6 Creating an OData Service Definition. ........................................183<br />

8.1.7 OData Service Definition Language Syntax. ....................................184<br />

8.1.8 OData Service Definition: SQL-EDM Type Mapping. ..............................186<br />

8.1.9 OData Service-Definition Examples. .........................................188<br />

8.2 Data Access with XMLA in SAP HANA XS. ............................................201<br />

8.2.1 XML for Analysis (XMLA). ................................................201<br />

8.2.2 XMLA Service Definition. .................................................202<br />

8.2.3 XMLA Security Considerations. ............................................203<br />

8.2.4 Multidim<strong>en</strong>sional Expressions (MDX). ....................................... 203<br />

8.2.5 MDX Functions. .......................................................204<br />

8.2.6 MDX Ext<strong>en</strong>sions. ...................................................... 207<br />

8.2.7 Defining the Data an XMLA Service Exposes. ...................................210<br />

8.2.8 Creating an XMLA Service Definition. ........................................210<br />

9 Writing Server-Side JavaScript Applications. .......................................212<br />

9.1 Data Access with JavaScript in SAP HANA XS. .........................................212<br />

9.2 Writing JavaScript Code. ........................................................212<br />

9.2.1 Server-Side JavaScript in SAP HANA XS. ..................................... 212<br />

9.2.2 JavaScript Editor. ......................................................213<br />

9.2.3 Writing Server-Side JavaScript Applications. ...................................214<br />

9.3 Writing JavaScript Libraries. ..................................................... 215<br />

9.3.1 Server-Side JavaScript Libraries. ...........................................215<br />

9.3.2 Writing Server-Side JavaScript Libraries. ..................................... 215<br />

9.3.3 Importing Server-Side JavaScript Libraries. ....................................216<br />

9.4 Server-Side JavaScript APIs. .....................................................217<br />

SAP HANA Developer Guide<br />

Table of Cont<strong>en</strong>ts<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 5


9.5 The SQL Connection Configuration File. ............................................. 218<br />

9.6 Tracing JavaScript. ............................................................220<br />

9.6.1 Server-Side JavaScript Tracing. ............................................220<br />

9.6.2 Tracing Server-Side JavaScript Applications. ..................................220<br />

9.6.3 Viewing Server-Side JavaScript Application Trace Files. ...........................221<br />

9.7 Debugging JavaScript. ..........................................................221<br />

9.7.1 Op<strong>en</strong>ing a Port for JavaScript Debugging. .....................................223<br />

10 Building UIs With SAPUI5. ..................................................... 225<br />

10.1 Installing SAPUI5 Application Developm<strong>en</strong>t Tools. ......................................226<br />

10.2 Creating an SAPUI5 Application. .................................................. 226<br />

10.2.1 Local Testing of a SAPUI5 Application. .......................................228<br />

10.2.2 SAPUI5 Runtime Version Comparison. .......................................229<br />

10.3 Supporting Translation. ........................................................ 230<br />

11 Enabling Search. .............................................................231<br />

11.1 Creating Full Text Indexes. .......................................................231<br />

11.1.1 Full Text Index Types. ...................................................233<br />

11.1.2 Synchronization. ...................................................... 236<br />

11.1.3 Text Analysis. .........................................................238<br />

11.1.4 Dropping Full Text Indexes. ...............................................242<br />

11.1.5 Altering Full Text Index Parameters. .........................................242<br />

11.1.6 Full Text Index Parameters. ...............................................243<br />

11.2 Building SQL Search Queries. .................................................... 248<br />

11.2.1 Search Queries with CONTAINS. ...........................................248<br />

11.2.2 EXACT Search. ........................................................251<br />

11.2.3 LINGUISTIC Search. ....................................................252<br />

11.2.4 FUZZY Search. ........................................................252<br />

11.3 Building Search Apps. ..........................................................304<br />

11.3.1 Introduction to the UI Toolkit for Info Access. ..................................304<br />

11.3.2 Installing the Service and the Toolkit. ........................................305<br />

11.3.3 Getting to Know the Demo App. ............................................306<br />

11.3.4 Getting to Know the Demo HTML. .......................................... 307<br />

11.3.5 Preparing Your Source Data. ..............................................308<br />

11.3.6 Connecting Your Source Data. .............................................310<br />

11.3.7 Defining the Page Layout. .................................................311<br />

11.3.8 Configuring the Widgets. .................................................311<br />

11.3.9 Defining the Layout of Result Lists and Details. ................................. 315<br />

12 Setting Up Roles and Authorizations. .............................................316<br />

12.1 The Authorization Model. ........................................................316<br />

12.2 Auth<strong>en</strong>tication Overview. ........................................................317<br />

6<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Table of Cont<strong>en</strong>ts


12.3 Roles. ......................................................................317<br />

12.3.1 Roles. .............................................................. 318<br />

12.3.2 Roles as Repository Objects. ..............................................319<br />

12.3.3 Creating Roles in the Repository. ...........................................320<br />

12.4 Privileges. .................................................................. 325<br />

12.4.1 System Privileges. ..................................................... 325<br />

12.4.2 Object Privileges. ......................................................325<br />

12.4.3 Package Privileges. .....................................................326<br />

12.4.4 Analytic Privileges. .....................................................328<br />

12.4.5 Creating Analytic Privileges. .............................................. 337<br />

12.4.6 Granting Privileges to Users. .............................................. 341<br />

12.5 Application Access. ........................................................... 342<br />

13 Implem<strong>en</strong>ting Lifecycle Managem<strong>en</strong>t . ............................................344<br />

13.1 SAP HANA Delivery Units. .......................................................344<br />

13.2 The SAP HANA Delivery-Unit Lifecycle. ............................................. 344<br />

13.3 Exporting Delivery Units. ........................................................345<br />

13.4 Importing Delivery Units. ........................................................347<br />

13.5 Translating Delivery Units. .......................................................348<br />

13.5.1 SAP HANA Delivery-Unit Translation Details. .................................. 349<br />

13.5.2 Maintaining Translation Details. ............................................349<br />

14 Using Database Cli<strong>en</strong>t Interfaces. ................................................351<br />

14.1 Connecting via ODBC. ..........................................................351<br />

14.1.1 Using the User Store. ...................................................352<br />

14.1.2 Testing the ODBC Installation. .............................................353<br />

14.2 Connecting via JDBC. ..........................................................354<br />

14.2.1 Tracing JDBC Connections. ...............................................355<br />

14.2.2 Valid Java-to-SQL Conversions. ............................................357<br />

14.3 Connecting via ODBO. ..........................................................358<br />

14.3.1 Connecting with Microsoft Excel. ...........................................358<br />

14.3.2 Multidim<strong>en</strong>sional Expressions (MDX). ........................................361<br />

14.3.3 MDX Functions. .......................................................362<br />

14.3.4 MDX Ext<strong>en</strong>sions. ...................................................... 366<br />

15 SAP HANA Developer Refer<strong>en</strong>ces. ...............................................369<br />

SAP HANA Developer Guide<br />

Table of Cont<strong>en</strong>ts<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 7


1 Overview<br />

This guide pres<strong>en</strong>ts a <strong>dev</strong>eloper’s view of SAP HANA ® . It explains how to use the SAP HANA <strong>dev</strong>elopm<strong>en</strong>t tools to<br />

create compreh<strong>en</strong>sive analytical models and to build applications with SAP HANA's programmatic interfaces and<br />

integrated <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t, including to <strong>dev</strong>elop native code that runs inside SAP HANA.<br />

The guide is organized as follows:<br />

● SAP HANA [page 9] describes the capabilities of SAP HANA.<br />

● SAP HANA as a Developm<strong>en</strong>t Platform [page 16] describes the main <strong>dev</strong>eloper sc<strong>en</strong>arios, the <strong>dev</strong>elopm<strong>en</strong>t<br />

process and the <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t.<br />

● Setting up Your Application [page 34] describes how to get started <strong>dev</strong>eloping SAP HANA applications.<br />

Most of the remaining chapters explain how to <strong>dev</strong>elop various SAP HANA <strong>dev</strong>elopm<strong>en</strong>t objects.<br />

Audi<strong>en</strong>ce<br />

Note: Application <strong>dev</strong>elopm<strong>en</strong>t with SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) is<br />

curr<strong>en</strong>tly only available as an SAP-led project solution, for pre-approved customers and partners. This<br />

applies to server-side JavaScript programming, support for ODATA and XMLA, Web server features and<br />

the Web application <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t. For more information, see SAP Note 1779803.<br />

This guide is aimed at two <strong>dev</strong>eloper roles:<br />

● Modeler: This person, oft<strong>en</strong> a business/data analyst or database expert, is concerned with the definition of<br />

the model and schemas that will be used in SAP HANA, the specification and definition of tables, views,<br />

primary keys, indexes, partitions and other aspects of the layout and inter-relationship of the data in SAP<br />

HANA.<br />

The data modeler is also concerned with designing and defining authorization and access control, through the<br />

specification of privileges, roles and users.<br />

The modeler g<strong>en</strong>erally uses the Administration Console and Modeler perspectives and tools of the SAP HANA<br />

studio.<br />

● Application Programmer: The programmer is concerned with building SAP HANA applications, which could<br />

8<br />

take many forms but are designed based on the model-view-controller architecture. Programmers <strong>dev</strong>elop<br />

the code for:<br />

○ View, which could run inside a browser or on a mobile <strong>dev</strong>ice<br />

○ Controller, which typically runs in the context of an application server<br />

○ Model, which interacts closely with the data model, performs effici<strong>en</strong>t queries, and may be <strong>dev</strong>eloped to<br />

run within the SAP HANA data <strong>en</strong>gine, using embedded procedures or libraries<br />

The programmer g<strong>en</strong>erally uses the SAP HANA Developm<strong>en</strong>t perspective and tools of the SAP HANA studio.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Overview


2 SAP HANA<br />

SAP HANA is an in-memory data platform that is deployable as an appliance or in the cloud. At its core, it is an<br />

innovative in-memory relational database managem<strong>en</strong>t system that makes full use of the capabilities of curr<strong>en</strong>t<br />

hardware to increase application performance, to reduce cost of ownership, and to <strong>en</strong>able new sc<strong>en</strong>arios and<br />

applications that were not possible before.<br />

With SAP HANA, you have the opportunity to build applications that integrate the business control logic and the<br />

database layer with unpreced<strong>en</strong>ted performance. As a <strong>dev</strong>eloper, one of the key questions is how you can<br />

minimize data movem<strong>en</strong>ts. The more you can do directly on the data in memory next to the CPUs, the better the<br />

application will perform.<br />

2.1 The SAP HANA In-Memory Database<br />

SAP HANA was designed to run on modern, distributed computers built out of multi-core CPUs (multiple CPUs on<br />

one chip) with fast communication betwe<strong>en</strong> processor cores, and containing terabytes of main memory. With<br />

SAP HANA, all data is available in main memory, which completely avoids the performance p<strong>en</strong>alty of disk I/O.<br />

Either disk or solid-state drives are still required for perman<strong>en</strong>t persist<strong>en</strong>cy in the ev<strong>en</strong>t of a power failure or some<br />

other catastrophe. This does not slow down performance, however, because the required backup operations to<br />

disk can take place asynchronously as a background task.<br />

2.1.1 Columnar Data Storage<br />

A database table is conceptually a two-dim<strong>en</strong>sional data structure organized in rows and columns. Computer<br />

memory, in contrast, is organized as a linear structure. A table can be repres<strong>en</strong>ted in row-order or column-order.<br />

A row-ori<strong>en</strong>ted organization stores a table as a sequ<strong>en</strong>ce of records. Conversely, in column storage the <strong>en</strong>tries of<br />

a column are stored in contiguous memory locations. SAP HANA supports both, but is particularly optimized for<br />

column-order storage.<br />

Columnar data storage allows highly effici<strong>en</strong>t compression. Especially if a column is sorted, there will normally be<br />

repeated adjac<strong>en</strong>t values. SAP HANA employs highly effici<strong>en</strong>t compression methods, such as run-l<strong>en</strong>gth<br />

<strong>en</strong>coding, cluster coding and dictionary coding. With dictionary <strong>en</strong>coding, columns are stored as sequ<strong>en</strong>ces of bitcoded<br />

integers. That means that a check for equality can be executed on the integers (for example during scans<br />

or join operations). This is much faster than comparing, for example, string values.<br />

SAP HANA Developer Guide<br />

SAP HANA<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 9


Columnar storage, in many cases, eliminates the need for additional index structures. Storing data in columns is<br />

functionally similar to having a built-in index for each column. The column scanning speed of the in-memory<br />

column store and the compression mechanisms – especially dictionary compression – allow read operations with<br />

very high performance. In many cases it will not be required to have additional indexes. Eliminating additional<br />

indexes reduces complexity and eliminates effort for defining and maintaining metadata.<br />

2.1.2 Parallel Processing<br />

SAP HANA was designed from the ground up to perform its basic calculations (such as analytic joins, scans and<br />

aggregations) in parallel, oft<strong>en</strong> using hundreds of cores at the same time, fully utilizing the available computing<br />

resources of distributed systems.<br />

With columnar data, operations on single columns, such as searching or aggregations, can be implem<strong>en</strong>ted as<br />

loops over an array stored in contiguous memory locations. Such an operation has high spatial locality and can<br />

effici<strong>en</strong>tly be executed in the CPU cache. With row-ori<strong>en</strong>ted storage, the same operation would be much slower<br />

because data of the same column is distributed across memory and the CPU is slowed down by cache misses.<br />

Compressed data can be loaded into the CPU cache faster. This is because the limiting factor is the data transport<br />

betwe<strong>en</strong> memory and CPU cache, and so the performance gain will exceed the additional computing time needed<br />

for decompression.<br />

Column-based storage also allows execution of operations in parallel using multiple processor cores. In a column<br />

store, data is already vertically partitioned. This means that operations on differ<strong>en</strong>t columns can easily be<br />

processed in parallel. If multiple columns need to be searched or aggregated, each of these operations can be<br />

assigned to a differ<strong>en</strong>t processor core. In addition, operations on one column can be parallelized by partitioning<br />

the column into multiple sections that can be processed by differ<strong>en</strong>t processor cores.<br />

2.1.3 Simplifying Applications<br />

Traditional business applications oft<strong>en</strong> use materialized aggregates to increase performance. These aggregates<br />

are computed and stored either after each write operation on the aggregated data, or at scheduled times. Read<br />

operations read the materialized aggregates instead of computing them each time they are required.<br />

10<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA


With a scanning speed of several gigabytes per millisecond, SAP HANA makes it possible to calculate aggregates<br />

on large amounts of data on-the-fly with high performance. This eliminates the need for materialized aggregates<br />

in many cases, simplifying data models, and correspondingly the application logic. Furthermore, with on-the fly<br />

aggregation, the aggregate values are always up-to-date unlike materialized aggregates that may be updated only<br />

at scheduled times.<br />

2.2 SAP HANA Database Architecture<br />

A running SAP HANA system consists of multiple communicating processes (services). The following shows the<br />

main SAP HANA database services in a classical application context.<br />

Such traditional database applications use well-defined interfaces (for example, ODBC and JDBC) to<br />

communicate with the database managem<strong>en</strong>t system functioning as a data source, usually over a network<br />

connection. Oft<strong>en</strong> running in the context of an application server, these traditional applications use Structured<br />

Query Language (SQL) to manage and query the data stored in the database.<br />

The main SAP HANA database managem<strong>en</strong>t compon<strong>en</strong>t is known as the index server. The index server contains<br />

the actual data stores and the <strong>en</strong>gines for processing the data. The index server processes incoming SQL or MDX<br />

statem<strong>en</strong>ts in the context of auth<strong>en</strong>ticated sessions and transactions.<br />

SAP HANA Developer Guide<br />

SAP HANA<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 11


The SAP HANA database has its own scripting language named SQLScript. The motivation for SQLScript is to<br />

embed data-int<strong>en</strong>sive application logic into the database. Classical applications t<strong>en</strong>d to offload only very limited<br />

functionality into the database using SQL. This results in ext<strong>en</strong>sive copying of data from and to the database, and<br />

in programs that slowly iterate over huge data loops and are hard to optimize and parallelize. SQLScript is based<br />

on side-effect free functions that operate on tables using SQL queries for set processing, and is therefore<br />

parallelizable over multiple processors.<br />

In addition to SQLScript, SAP HANA supports a framework for the installation of specialized and optimized<br />

functional libraries, which are tightly integrated with differ<strong>en</strong>t data <strong>en</strong>gines of the index server. Two of these<br />

functional libraries are the SAP HANA Business Function Library (BFL) and the SAP HANA Predictive Analytics<br />

Library (PAL). BFL and PAL functions can be called directly from within SQLScript.<br />

SAP HANA also supports the <strong>dev</strong>elopm<strong>en</strong>t of programs writt<strong>en</strong> in the popular statistics language R.<br />

SQL and SQLScript are implem<strong>en</strong>ted using a common infrastructure of built-in data <strong>en</strong>gine functions that have<br />

access to various meta definitions, such as definitions of relational tables, columns, views, and indexes, and<br />

definitions of SQLScript procedures. This metadata is stored in one common catalog.<br />

The database persist<strong>en</strong>ce layer is responsible for durability and atomicity of transactions. It <strong>en</strong>sures that the<br />

database can be restored to the most rec<strong>en</strong>t committed state after a restart and that transactions are either<br />

completely executed or completely undone.<br />

The index server uses the preprocessor server for analyzing text data and extracting the information on which the<br />

text search capabilities are based. The name server owns the information about the topology of a SAP HANA<br />

system. In a distributed system, the name server knows where the compon<strong>en</strong>ts are running and which data is<br />

located on which server. The statistics server collects information about status, performance and resource<br />

consumption from the other servers in the system. Monitoring cli<strong>en</strong>ts, such as the SAP HANA studio, access the<br />

statistics server to get the status of various alert monitors. The statistics server also provides a history of<br />

measurem<strong>en</strong>t data for further analysis.<br />

Related Links<br />

SAP HANA SQLScript Refer<strong>en</strong>ce<br />

SAP HANA Business Function Library (BFL) Refer<strong>en</strong>ce<br />

SAP HANA Predictive Analysis Library (PAL) Refer<strong>en</strong>ce<br />

SAP HANA R Integration Guide<br />

2.3 SAP HANA Ext<strong>en</strong>ded Application Services<br />

Traditional database applications use interfaces such as ODBC and JDBC with SQL to manage and query their<br />

data. The following illustrates such applications using the common Model-View-Controller (MVC) <strong>dev</strong>elopm<strong>en</strong>t<br />

architecture.<br />

12<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA


SAP HANA greatly ext<strong>en</strong>ds the traditional database server role. SAP HANA functions as a compreh<strong>en</strong>sive<br />

platform for the <strong>dev</strong>elopm<strong>en</strong>t and execution of native data-int<strong>en</strong>sive applications that run effici<strong>en</strong>tly in SAP HANA,<br />

taking advantage of its in-memory architecture and parallel execution capabilities.<br />

By restructuring your application in this way, not only do you gain from the increased performance due to the<br />

integration with the data source, you can effectively eliminate the overhead of the middle-tier betwe<strong>en</strong> the userinterface<br />

(the view) and the data-int<strong>en</strong>sive control logic, as shown in the following figure.<br />

In support of this data-integrated application paradigm, SAP HANA Ext<strong>en</strong>ded Application Services provides a<br />

compreh<strong>en</strong>sive set of embedded services that provide <strong>en</strong>d-to-<strong>en</strong>d support for Web-based applications. This<br />

includes a lightweight web server, configurable OData support, server-side JS execution and, of course, full<br />

access to SQL and SQLScript.<br />

These SAP HANA Ext<strong>en</strong>ded Application Services are provided by the SAP HANA XS server, which provides<br />

lightweight application services that are fully integrated into SAP HANA. It allows cli<strong>en</strong>ts to access the SAP HANA<br />

system via HTTP. Controller applications can run completely natively on SAP HANA, without the need for an<br />

additional external application server.The following shows the SAP HANA XS server as part of the SAP HANA<br />

system.<br />

SAP HANA Developer Guide<br />

SAP HANA<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 13


The application services can be used to expose the database data model, with its tables, views and database<br />

procedures, to cli<strong>en</strong>ts. This can be done in a declarative way using OData services or by writing native applicationspecific<br />

code that runs in the SAP HANA context . Also, you can use SAP HANA XS to build dynamic HTML5 UI<br />

applications.<br />

In addition to exposing the data model, SAP HANA XS also hosts system services that are part of the SAP HANA<br />

system. The search service is an example of such a system application. No data is stored in the SAP HANA XS<br />

server itself. To read tables or views, to modify data or to execute SQLScript database procedures and<br />

calculations, it connects to the index server (or servers, in case of a distributed system).<br />

Related Links<br />

Note: Application <strong>dev</strong>elopm<strong>en</strong>t with SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) is<br />

curr<strong>en</strong>tly only available as an SAP-led project solution, for pre-approved customers and partners. This<br />

applies to server-side JavaScript programming, support for ODATA and XMLA, Web server features and<br />

the Web application <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t. For more information, see SAP Note 1779803.<br />

Building UIs With SAPUI5 [page 225]<br />

This section provides introductory information about UI <strong>dev</strong>elopm<strong>en</strong>t toolkit for HTML5.<br />

Enabling Search [page 231]<br />

With a SAP HANA database, your users will want to search tables and views much like they would wh<strong>en</strong><br />

searching for information on the Internet. In SAP HANA, you can either directly query data using SQL queries<br />

or you can build search apps using a UI toolkit.<br />

14<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA


2.4 Refactoring SAP HANA Based Applications<br />

The possibility to run application-specific code in SAP HANA raises the question: What kind of logic should run<br />

where? Clearly, data-int<strong>en</strong>sive and model-based calculations must be close to the data and, therefore, need to be<br />

executed in the index server, for instance, using SQLScript or the code of the specialized functional libraries.<br />

The pres<strong>en</strong>tation (view) logic runs on the cli<strong>en</strong>t – for example, as an HTML5 application in a Web browser or on a<br />

mobile <strong>dev</strong>ice.<br />

Native application-specific code, supported by SAP HANA Ext<strong>en</strong>ded Application Services, can be used to provide<br />

a thin layer betwe<strong>en</strong> the cli<strong>en</strong>ts on one side, and the views, tables and procedures in the index server on the other<br />

side. Typical applications contain, for example, control flow logic based on request parameters, invoke views and<br />

stored procedures in the index server, and transform the results to the response format expected by the cli<strong>en</strong>t.<br />

Such applications can also s<strong>en</strong>d emails and consume external HTTP-based services.<br />

The communication betwe<strong>en</strong> the SAP HANA XS server and index server is optimized for high performance.<br />

However, performance is not the only reason why the SAP HANA XS server was integrated into SAP HANA. It also<br />

leads to simplified administration and a better <strong>dev</strong>elopm<strong>en</strong>t experi<strong>en</strong>ce.<br />

The SAP HANA XS server completes SAP HANA to make it a compreh<strong>en</strong>sive <strong>dev</strong>elopm<strong>en</strong>t platform. With the SAP<br />

HANA XS server, <strong>dev</strong>elopers can write SAP HANA-based applications that cover all server-side aspects, such as<br />

tables and database views, database procedures, server-side control logic, integration with external systems, and<br />

provisioning of HTTP-based services. The integration of the SAP HANA XS server into the SAP HANA system also<br />

helps to reduce cost of ownership, as all servers are installed, operated and updated as one system.<br />

SAP HANA Developer Guide<br />

SAP HANA<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 15


3 SAP HANA as a Developm<strong>en</strong>t<br />

Platform<br />

To simplify and support the <strong>dev</strong>elopm<strong>en</strong>t of HANA Based applications, SAP HANA serves as the integrated<br />

<strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t (IDE) for <strong>dev</strong>eloping and delivering these SAP HANA applications.<br />

Built around the Eclipse-based SAP HANA studio the SAP HANA IDE supports integrated and collaborative<br />

<strong>dev</strong>elopm<strong>en</strong>t, debugging and deploym<strong>en</strong>t of applications that use native database procedures for data<br />

processing, server-side JavaScript for control and an HTML5 SDK for the <strong>dev</strong>elopm<strong>en</strong>t of user interface<br />

repres<strong>en</strong>tation.<br />

The design-time <strong>en</strong>vironm<strong>en</strong>t's c<strong>en</strong>tral compon<strong>en</strong>t is the SAP HANA repository, which stores and manages all<br />

design-time objects. The following figure illustrates the principle of co-<strong>dev</strong>elopm<strong>en</strong>t with SAP HANA.<br />

Using the HANA studio on your workstation, you design and create <strong>dev</strong>elopm<strong>en</strong>t objects such as data models or<br />

server-side code files, and th<strong>en</strong> store, manage and share them with other <strong>dev</strong>elopers, by interacting with the SAP<br />

HANA repository. The repository <strong>en</strong>ables teams to work together on a set of <strong>dev</strong>elopm<strong>en</strong>t objects, and ultimately<br />

turn them into runtime objects which can be used by cli<strong>en</strong>ts or other applications. The repository provides the<br />

basis for concepts like namespaces (through packages), transport and delivery support.<br />

3.1 Developer Sc<strong>en</strong>arios<br />

The possibility to run application specific code in SAP HANA creates several possibilities for <strong>dev</strong>eloping SAP<br />

HANA based applications, repres<strong>en</strong>ting various integration sc<strong>en</strong>arios, and corresponding <strong>dev</strong>elopm<strong>en</strong>t<br />

processes.<br />

Broadly, we distinguish SAP HANA based applications into two broad categories:<br />

● Web-based sc<strong>en</strong>arios that take full advantage of the SAP HANA Ext<strong>en</strong>ded Application Services. In these<br />

sc<strong>en</strong>arios, cli<strong>en</strong>ts access SAP HANA data using standard OData or XMLA interfaces, or directly use a Webbased<br />

GUI that was <strong>dev</strong>eloped using the SAPGUI5 toolkit, and that uses custom-<strong>dev</strong>eloped server-side<br />

JavaScript, as well as native SQLScript procedures.<br />

● Traditional cli<strong>en</strong>t-based sc<strong>en</strong>arios, where an external application accesses the SAP HANA data model (tables,<br />

analytic views, etc.) via cli<strong>en</strong>t interfaces such as ODBC, ODBO and JDBC, and only uses SQL and native<br />

SQLScript procedures.<br />

16<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform


In either case, as a <strong>dev</strong>eloper you need to understand the SAP HANA <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t, which <strong>en</strong>ables<br />

you to design and <strong>dev</strong>elop your data and analytical models, and your other HANA-based <strong>dev</strong>elopm<strong>en</strong>t objects in<br />

the form of portable and deployable delivery units.<br />

Common activities include:<br />

Table 1: Common Activities<br />

Activity More Information<br />

Setting up your <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t. Setting up Your Application [page 34]<br />

Setting up your schema and tables. Setting up the Persist<strong>en</strong>ce Model [page 74]<br />

Setting up views of your data. Setting Up the Analytic Model [page 92]<br />

Developing procedures for data-int<strong>en</strong>sive logic. Developing Procedures [page 158]<br />

Setting up roles and authorizations. i031349596025517.ditamap<br />

Managing the delivery of your application. SAP HANA Delivery Units [page 344]<br />

For these activites, you will want to keep handy the following refer<strong>en</strong>ces:<br />

● SAP HANA SQL Refer<strong>en</strong>ce, to help you writing SQL statem<strong>en</strong>ts within procedures and from your server-side<br />

JavaScript.<br />

● SAP HANA SQLScript Refer<strong>en</strong>ce, to help you if you are writing procedures.<br />

The next two sections describes the main sc<strong>en</strong>arios and what activities you may need to perform for them.<br />

3.1.1 Sc<strong>en</strong>ario: Developing Native SAP HANA Applications<br />

Here, you want to create a Web-based sc<strong>en</strong>ario that takes full advantage of SAP HANA Ext<strong>en</strong>ded Application<br />

Services. In this sc<strong>en</strong>ario, cli<strong>en</strong>ts access SAP HANA data using standard OData or XMLA interfaces, or directly use<br />

a Web-based GUI that was <strong>dev</strong>eloped using the SAPGUI5 toolkit, and that uses custom-<strong>dev</strong>eloped server-side<br />

JavaScript, as well as native SQLScript procedures.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 17


For this sc<strong>en</strong>ario, you may need to perform the following activities:<br />

Table 2: Developing Native SAP HANA Applications<br />

Activity More Information<br />

Develop server-side JavaScript for control logic. Writing Server-Side JavaScript Applications [page<br />

Define OData data interfaces. Data Access with OData in SAP HANA XS [page 164]<br />

Define XMLA data interfaces Data Access with XMLA in SAP HANA XS [page 201]<br />

How to build HTML pages with SAPUI5. Building UIs With SAPUI5 [page 225]<br />

You will also want to keep handy the following refer<strong>en</strong>ces:<br />

● SAP HANA SQL Refer<strong>en</strong>ce, to help you write SQL statem<strong>en</strong>ts within procedures and from your server-side<br />

JavaScript.<br />

● SAP HANA XS JavaScript Refer<strong>en</strong>ce, to help you use the SAP HANA XS JavaScript API.<br />

212]<br />

For a list of all refer<strong>en</strong>ces, see SAP HANA Developer Refer<strong>en</strong>ces [page 369].<br />

3.1.2 Sc<strong>en</strong>ario: Using Database Cli<strong>en</strong>t Interfaces<br />

Here, you want to build an application outside of SAP HANA, for example, within SAP NetWeaver, that accesses<br />

the SAP HANA data model (for example, tables and analytic views) via cli<strong>en</strong>t interfaces such as ODBC, ODBO and<br />

JDBC, and only uses SQL and native SQLScript procedures.<br />

18<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform


For this sc<strong>en</strong>ario, you may need to perform the following activities:<br />

Table 3: Using Database Cli<strong>en</strong>t Interfaces<br />

Activity More Information<br />

Installing and using the SAP HANA cli<strong>en</strong>t interfaces Using Database Cli<strong>en</strong>t Interfaces [page 351]<br />

Developing procedures for data-int<strong>en</strong>sive logic. Developing Procedures [page 158]<br />

You will also want to keep handy several refer<strong>en</strong>ces:<br />

● SAP HANA SQL Refer<strong>en</strong>ce, to help you write SQL statem<strong>en</strong>ts.<br />

For information on MDX in SAP HANA, see MDX Functions [page 204].<br />

● SAP HANA SQLScript Refer<strong>en</strong>ce, to help you if you are writing procedures.<br />

For a list of all refer<strong>en</strong>ces, see SAP HANA Developer Refer<strong>en</strong>ces [page 369].<br />

3.2 Developm<strong>en</strong>t Objects<br />

The design-time building blocks of your SAP HANA applications are called <strong>dev</strong>elopm<strong>en</strong>t objects. Some of these<br />

<strong>dev</strong>elopm<strong>en</strong>t objects, such as projects and packages, are concepts that help you structure your application.<br />

Others, like schemas, table definitions, analytical and attribute views, help you organize the structure of your data.<br />

Procedures and server-side JavaScript code are the backbone of the SAP HANA application. Other types of<br />

<strong>dev</strong>elopm<strong>en</strong>t objects help you control the access to runtime objects.<br />

Understanding the differ<strong>en</strong>t <strong>dev</strong>elopm<strong>en</strong>t objects and their use is one of the main objectives of this guide.<br />

The following are the building blocks for an SAP HANA application, showing the file ext<strong>en</strong>sion and where to get<br />

information for building it:<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 19


Table 4: Application Building Blocks<br />

Object Description File Ext<strong>en</strong>sion More Information<br />

Structure<br />

Project An Eclipse project for <strong>dev</strong>eloping your<br />

application or part of an application.<br />

The .project file can be stored in the SAP<br />

HANA repository.<br />

Package A container in the repository for<br />

<strong>dev</strong>elopm<strong>en</strong>t objects.<br />

Modeling Data<br />

Schema A database schema for organizing database<br />

objects.<br />

.project SAP HANA Studio Projects<br />

Packages are<br />

repres<strong>en</strong>ted by<br />

folders.<br />

[page 39]<br />

Maintaining Repository<br />

Packages [page 42]<br />

.hdbschema Schema [page 75]<br />

Table A database table. .hdbtable Tables [page 76]<br />

SQL View A virtual table based on a SQL query. .hdbview SQL Views [page 80]<br />

Attribute,<br />

Analytic and<br />

Calculation<br />

View<br />

A view created with modeling tools and<br />

designed to model a business use case.<br />

Decision Table A database table used to define business<br />

rules, for example, for validating data.<br />

Analytic<br />

Privilege<br />

A set of rules that restricts users to seeing<br />

only a subset of data in a table or view.<br />

Sequ<strong>en</strong>ce A set of unique numbers, for example, for<br />

use as primary keys for a specific table.<br />

Procedure A database function for performing<br />

complex and data-int<strong>en</strong>sive business logic<br />

that cannot be performed with standard<br />

SQL.<br />

Web Access<br />

Application<br />

Descriptor<br />

Application<br />

Access File<br />

Application<br />

Privilege<br />

20<br />

A file in a repository package that defines a<br />

root folder of a native SAP HANA<br />

application. All files in that package are<br />

available to be called via URL.<br />

A file that defines permissions for a native<br />

SAP HANA application, that is, permissions<br />

for accessing and running objects in the<br />

package.<br />

A file that defines a privilege related to an<br />

SAP HANA Ext<strong>en</strong>ded Application Services<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

Created with the<br />

Navigator view.<br />

Setting Up the Analytic<br />

Model [page 92]<br />

Creating Decision Tables<br />

[page 133]<br />

Creating Analytic Privileges<br />

[page 337]<br />

.hdbsequ<strong>en</strong>ce Sequ<strong>en</strong>ces [page 78]<br />

.procedure Developing Procedures<br />

[page 158]<br />

.xsapp Creating the Application<br />

Descriptors [page 49]<br />

.xsaccess Enabling Access to SAP<br />

HANA XS Application<br />

Packages [page 57]<br />

.xsprivileges The Application-Privileges<br />

File [page 59]<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform


Object Description File Ext<strong>en</strong>sion More Information<br />

Server-Side<br />

JavaScript<br />

Code<br />

Server-Side<br />

JavaScript<br />

Library<br />

OData<br />

Descriptor<br />

XMLA<br />

Descriptor<br />

SQL Connection<br />

Configuration<br />

Other<br />

application, for example, the right to start or<br />

administer the application.<br />

JavaScript code that can run in SAP HANA<br />

Ext<strong>en</strong>ded Application Services and that can<br />

be accessed via URL.<br />

JavaScript code that can run in SAP HANA<br />

Ext<strong>en</strong>ded Application Services but cannot<br />

be accessed via URL. The code can be<br />

imported into an .xsjs code file.<br />

A file that defines an OData service that<br />

exposes SAP HANA data.<br />

A file that defines an XMLA service that<br />

exposes SAP HANA data<br />

A file that <strong>en</strong>ables execution of SQL<br />

statem<strong>en</strong>ts from inside server-side<br />

JavaScript code with cred<strong>en</strong>tials that are<br />

differ<strong>en</strong>t than those of the requesting user.<br />

.xsjs Writing Server-Side<br />

JavaScript Applications<br />

[page 214]<br />

.xsjslib<br />

.xsodata Data Access with OData in<br />

SAP HANA XS [page 164]<br />

.xsxmla Data Access with XMLA in<br />

SAP HANA XS [page 201]<br />

.xssqlcc The SQL Connection<br />

Configuration File [page<br />

218]<br />

Role A file that defines an SAP HANA role. .hdbrole Creating Roles in the<br />

Repository [page 320]<br />

Search Rule Set A file that defines a set of rules for use with<br />

fuzzy searches. The rules help decide what<br />

is a valid match in a search.<br />

Resource<br />

Bundle<br />

3.3 Repository<br />

A file for defining translatable UI texts for an<br />

application.<br />

.searchruleset Search Rules [page 297]<br />

.hdbtextbundle Creating an SAPUI5<br />

Application [page 226]<br />

The SAP HANA repository is the design-time storage system for <strong>dev</strong>elopm<strong>en</strong>t objects and is built into SAP HANA.<br />

The repository is the source control for all your <strong>dev</strong>elopm<strong>en</strong>t work on SAP HANA. You can add objects to the<br />

repository, update the objects, publish the objects, and compile these design-time objects into runtime objects.<br />

The repository supports the following:<br />

● Version Control<br />

● Sharing of objects betwe<strong>en</strong> multiple <strong>dev</strong>elopers<br />

● Transport<br />

The repository manages all <strong>dev</strong>elopm<strong>en</strong>t objects. You can browse the repository for a specific system with the<br />

SAP HANA Repositories view.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 21


Packages<br />

Within the repository, <strong>dev</strong>elopm<strong>en</strong>t objects are managed as files within packages. Packages <strong>en</strong>able you to:<br />

● Create namespaces, so you can uniquely id<strong>en</strong>tify <strong>dev</strong>elopm<strong>en</strong>t objects.<br />

● Group objects that logically belong together.<br />

● Provide containers for your objects so you can easily insert relevant objects into delivery units and transport<br />

them.<br />

● Assign permissions at the package level.<br />

You might create a top-level package for your company, and th<strong>en</strong> a subpackage for each project, and th<strong>en</strong><br />

subpackages for parts of your project, for example, a subpackage for your HTML files, another for server-side<br />

JavaScript files, and so forth.<br />

Workspaces<br />

Wh<strong>en</strong> working with <strong>dev</strong>elopm<strong>en</strong>t objects, you need to retrieve them from the repository, work on them on your<br />

workstation, and th<strong>en</strong> return them to the repository. To make this simpler, the SAP HANA studio <strong>en</strong>ables you to<br />

create a repository workspace, which establishes a link betwe<strong>en</strong> two locations:<br />

● The repository of the SAP HANA system where you wish to maintain the <strong>dev</strong>elopm<strong>en</strong>t object files of your<br />

projects (in the form of a package hierarchy).<br />

● A directory/folder on your workstation where you checkout these project files while you are working on them.<br />

Working with Objects<br />

Wh<strong>en</strong> creating <strong>dev</strong>elopm<strong>en</strong>t objects, the following is the workflow:<br />

1. Create a project.<br />

2. Share the project to associate it with a workspace, and thus a specific SAP HANA system. Shared projects,<br />

once they are activated, are available for import by other members of the application-<strong>dev</strong>elopm<strong>en</strong>t team.<br />

3. Create a new object file within the project, and save it to your workstation. Dep<strong>en</strong>ding on the ext<strong>en</strong>sion of the<br />

file you create, you may use a dedicated editor for that type of object, for example, a JavaScript editor<br />

for .xsjs files.<br />

4. Commit the file.<br />

22<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform


Committing the file saves it in the repository, but the object is inactive and cannot be run, and only you can<br />

see it.<br />

5. Activate the file.<br />

Activating a file does the following:<br />

○ Publishes the file so others can see it.<br />

○ Adds the previously active version of the file to the history. The repository maintains a history of changes<br />

to the file.<br />

○ Validates the file and compiles it or exposes it as a runtime object.<br />

The design-time object is now active.<br />

Related Links<br />

Setting up Your Application [page 34]<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), the design-time artifacts that make up your<br />

application are stored in the repository like files in a file system. You first choose a root folder for your<br />

application-<strong>dev</strong>elopm<strong>en</strong>t activities, and within this folder you create additional subfolders to organize the<br />

applications and the application cont<strong>en</strong>t according to your own requirem<strong>en</strong>ts.<br />

3.4 SAP HANA Studio<br />

The SAP HANA studio is an Eclipse-based <strong>dev</strong>elopm<strong>en</strong>t and administration tool for working with SAP HANA,<br />

including creating projects, creating <strong>dev</strong>elopm<strong>en</strong>t objects, and deploying them to SAP HANA. As a <strong>dev</strong>eloper, you<br />

may want to also perform some administrative tasks, such as configuring and monitoring the system.<br />

There are several key Eclipse perspectives that you will use while <strong>dev</strong>eloping:<br />

● Modeler: Used for creating various types of views and analytical privileges.<br />

● SAP HANA Developm<strong>en</strong>t: Used for programming applications, that is, creating <strong>dev</strong>elopm<strong>en</strong>t objects that<br />

access or update the data models, such as server-side JavaScript or HTML files.<br />

● Debug: Used to debug code, such as server-side JavaScript or SQLScript.<br />

● Administration: Used to monitor the system and change settings.<br />

To op<strong>en</strong> a perspective, go to Window Op<strong>en</strong> Perspective , or select on the toolbar.<br />

3.4.1 Modeler Perspective<br />

The Modeler perspective is used to define your analytic model by creating various types of views.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 23


The perspective contains the following main areas:<br />

● Navigator View: A view of the database objects, that is, those objects you create from the Modeler<br />

perspective.<br />

● Quick Launch Area: A collection of shortcuts for performing the most common modeling tasks. If you close<br />

the Quick Launch tab, you can reop<strong>en</strong> it by selecting Help Quick Launch .<br />

Navigator View<br />

The Navigator view shows a view of the database objects in SAP HANA, both those that have be<strong>en</strong> activated and<br />

those objects you created and have not activated yet.<br />

The view is divided into the following main sections:<br />

24<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform


● Security: Contains the roles and users defined for this system.<br />

● Catalog: Contains the database objects that have be<strong>en</strong> activated. The objects are divided into schemas, which<br />

is a way to organize activated database objects.<br />

● Cont<strong>en</strong>t: Contains design-time database objects, both those that have be<strong>en</strong> activated and those not activated.<br />

If you want to see other <strong>dev</strong>elopm<strong>en</strong>t objects, use the SAP HANA Repositories view.<br />

Related Links<br />

SAP HANA Repositories View [page 26]<br />

3.4.2 SAP HANA Developm<strong>en</strong>t Perspective<br />

The SAP HANA Developm<strong>en</strong>t perspective is where you will do most of your programming work, creating projects,<br />

associating them to SAP HANA systems, creating <strong>dev</strong>elopm<strong>en</strong>t objects, and deploying them.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 25


The perspective contains the following main areas:<br />

● Developm<strong>en</strong>t Objects: Several views for browsing your <strong>dev</strong>elopm<strong>en</strong>t objects: the objects on your workstation,<br />

and the objects in the repository of the SAP HANA system you are working with.<br />

● Editors: Specialized editors for working with differ<strong>en</strong>t types of <strong>dev</strong>elopm<strong>en</strong>t objects.<br />

SAP HANA Repositories View<br />

The SAP HANA Repositories view <strong>en</strong>ables you to browse the repository of a specific SAP HANA system, viewing<br />

the package hierarchy and to download files to your workstation.<br />

26<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform


The view ess<strong>en</strong>tially is a list of repository workspaces that you have created for <strong>dev</strong>eloping on various systems.<br />

G<strong>en</strong>erally, you create a workspace, check out files from the repository, and th<strong>en</strong> do most of your <strong>dev</strong>elopm<strong>en</strong>t<br />

work in the Project Explorer.<br />

If you are creating a project from scratch, you do not need anything from this view, except to see the hierarchy of<br />

the repository. You create the project in the Project Explorer.<br />

Project Explorer View<br />

The Project Explorer is the standard Project Explorer view in Eclipse, which shows you the <strong>dev</strong>elopm<strong>en</strong>t files<br />

located on your workstation.<br />

Here you can create files, edit files, and deploy them to the repository.<br />

Working with the Repository<br />

To work with the repository, you need to either:<br />

● Share your project with the repository via a workspace. Sharing a project associates it with a SAP HANA<br />

system, so that files within the project can be added to the repository on that system.<br />

● Check out an existing package in the repository from a workspace. This creates copies on your workstation of<br />

the package, its subpackages and their objects.<br />

Team M<strong>en</strong>u<br />

You can interact with the repository by right-clicking on a file or project (in the Project Explorer view) or package<br />

(in the SAP HANA Repositories view), and selecting an option from the Team m<strong>en</strong>u.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 27


You can perform the following on a file, folder or project in the Project Explorer view, that is, <strong>dev</strong>elopm<strong>en</strong>t objects<br />

that you are working on and located on your workstation:<br />

Table 5: Repository Actions in Project Explorer (project, folder, or file)<br />

Action Description<br />

Commit<br />

Saves the object to the repository.<br />

The object (or changes to the object) are only visible to you. There is no versioning of<br />

committed objects; the repository stores only the latest committed changes.<br />

Activate Makes the <strong>dev</strong>elopm<strong>en</strong>t object active, and does the following:<br />

28<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

● Publishes the object so it is visible to others.<br />

● Compiles the object into runtime objects.<br />

● Deploys the runtime object.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform


Action Description<br />

● Creates a new version of the design-time object.<br />

Check Simulates activation of the object in order to check if the object is valid and can be<br />

activated.<br />

Checkout Retrieves the latest version of the object from the repository.<br />

Revert Removes all your committed changes (inactive object) with the latest version of the object<br />

Share/Unshare<br />

(project only)<br />

that was activated.<br />

Associates a project with a specific SAP HANA system, so that files within the project can<br />

be added and updated on the repository on that system. For more information, see Using<br />

SAP HANA Projects [page 37].<br />

The following options are available for files only.<br />

Show Local History Shows a history of all versions of your object saved on your workstation. This is the Eclipse<br />

Show History<br />

local history feature.<br />

Shows a history of all the versions of the object that were activated in the repository.<br />

Curr<strong>en</strong>tly, you can only view a list of versions.<br />

You can perform the following on a package and file in the SAP HANA Repositories view:<br />

Table 6: Repository Actions in SAP HANA Repositories (package or file)<br />

Action Description<br />

Checkout (package<br />

only)<br />

Checkout and<br />

Import Projects<br />

(package only)<br />

Retrieves the latest version of the objects from the repository in this package and its<br />

subpackages.<br />

Retrieves the latest version of the objects from the repository in this package, and imports<br />

a project into the SAP HANA studio. For more information, see Using SAP HANA Projects<br />

[page 37].<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 29


Action Description<br />

Show History (file<br />

only)<br />

Status of Developm<strong>en</strong>t Objects<br />

Shows a history of all the versions of the object that were activated in the repository.<br />

Each object displayed in your project within the Project Explorer view is shown with an icon that indicates its<br />

status.<br />

Table 7: Status of Developm<strong>en</strong>t Objects<br />

Icon Description<br />

The file is not committed. You made a change to the file and saved it to your workstation, but have<br />

not yet committed the changes to the repository.<br />

The file is committed.<br />

The file is activated.<br />

3.4.3 Debug Perspective<br />

The Debug perspective in the SAP HANA studio is the standard Eclipse Debug perspective, <strong>en</strong>abling you to start<br />

debug sessions, create breakpoints and watch variables.<br />

In the SAP HANA studio, the debug tools have be<strong>en</strong> <strong>en</strong>hanced to let you also debug SAP HANA code, both serverside<br />

JavaScript (.xsjs files) and SQLScript code (.procedure files). The following shows the tools available in<br />

the Debug perspective and how it is organized:<br />

30<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform


● Debug Session: The debug sessions that have be<strong>en</strong> started<br />

● Watch: Breakpoints and variables to watch<br />

● Code: Code files that you have op<strong>en</strong>ed<br />

Related Links<br />

Debugging JavaScript [page 221]<br />

SAP HANA studio <strong>en</strong>ables you to debug XS JavaScript files, including setting breakpoints and inspecting<br />

variables.<br />

Debugging SQLScript [page 161]<br />

The SAP HANA SQLScript debugger allows you to debug and analyze procedures. In a debug session, your<br />

procedures will be executed in a serial mode, not in parallel (not-optimized). This allows you to test the<br />

correctness of the procedure logic and is not for evaluating the performance.<br />

3.4.4 Administration Console Perspective<br />

The Administration Console perspective <strong>en</strong>ables you to configure the SAP HANA server so that you can do your<br />

<strong>dev</strong>elopm<strong>en</strong>t work. For example, wh<strong>en</strong> debugging, the debug port must be op<strong>en</strong>ed and debugging <strong>en</strong>abled, which<br />

is done by setting configuration parameters within the administration console.<br />

The Administration Console perspective displays the Navigator view, for adding or selecting systems, and the<br />

administration console, where you can monitor and configure the system. Configuration parameters can viewed<br />

and changed from the Configuration tab.<br />

Note: You may need additional permissions to work with the administration console.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 31


If the console is closed, you can op<strong>en</strong> it by clicking the Administration icon in the Navigator view.<br />

3.5 Getting Started<br />

Before starting <strong>dev</strong>elopm<strong>en</strong>t work in the SAP HANA studio, make sure to have the following:<br />

● An installation of the SAP HANA studio on your workstation.<br />

● A live SAP HANA system to which to connect.<br />

● A user on the SAP HANA server that has at least the following roles or their equival<strong>en</strong>t:<br />

32<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform


○ MODELING<br />

○ CONTENT_ADMIN<br />

3.5.1 Adding a System<br />

To <strong>dev</strong>elop applications, you must first make a connection from your SAP HANA studio to an SAP HANA system.<br />

1. In the Navigator view, right-click anywhere in the view and select Add System.<br />

2. In the System window, <strong>en</strong>ter the host name, instance number, and a description for the SAP HANA system<br />

you want to add.<br />

3. Select Next.<br />

4. Enter a user name and password, and select Finish.<br />

The Navigator view includes a new top-level node for the system. You can now create a repository workspace for<br />

this system so you can start to <strong>dev</strong>elop objects to run in it.<br />

Related Links<br />

Setting up Your Application [page 34]<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), the design-time artifacts that make up your<br />

application are stored in the repository like files in a file system. You first choose a root folder for your<br />

application-<strong>dev</strong>elopm<strong>en</strong>t activities, and within this folder you create additional subfolders to organize the<br />

applications and the application cont<strong>en</strong>t according to your own requirem<strong>en</strong>ts.<br />

SAP HANA Developer Guide<br />

SAP HANA as a Developm<strong>en</strong>t Platform<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 33


4 Setting up Your Application<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), the design-time artifacts that make up your<br />

application are stored in the repository like files in a file system. You first choose a root folder for your application<strong>dev</strong>elopm<strong>en</strong>t<br />

activities, and within this folder you create additional subfolders to organize the applications and the<br />

application cont<strong>en</strong>t according to your own requirem<strong>en</strong>ts.<br />

Note: Application <strong>dev</strong>elopm<strong>en</strong>t with SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) is<br />

curr<strong>en</strong>tly only available as an SAP-led project solution, for pre-approved customers and partners. This<br />

applies to server-side JavaScript programming, support for ODATA and XMLA, Web server features and<br />

the Web application <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t. For more information, see SAP Note 1779803.<br />

As part of the application-<strong>dev</strong>elopm<strong>en</strong>t process, you typically need to perform the tasks described in the following<br />

list. Each of the tasks in more detail is described in its own section:<br />

1. Set up delivery units.<br />

To create and manage delivery units, you must set the id<strong>en</strong>tity of the v<strong>en</strong>dor with whom the delivery units are<br />

associated. To avoid conflicts with applications from SAP or other providers, we recomm<strong>en</strong>d that you name<br />

the root application-<strong>dev</strong>elopm<strong>en</strong>t folder for your company using the DNS name of your company. For<br />

example, you could use the name acme.com.hr.newHires for the root folder for a new application<br />

managing new hires in a company called acme.<br />

2. Set up SAP HANA projects.<br />

In SAP HANA, projects <strong>en</strong>able you to group together all the artifacts you need for a specific part of the<br />

application-<strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t. To start the application-<strong>dev</strong>elopm<strong>en</strong>t work flow, you first create a local<br />

workspace in the SAP HANA Developm<strong>en</strong>t perspective, which creates a directory structure to store files on<br />

your PC; the workspace you create <strong>en</strong>ables you to synchronize changes in local files with changes in the<br />

repository. Th<strong>en</strong> you can use the SAP HANA studio to create a project to manage the <strong>dev</strong>elopm<strong>en</strong>t activities<br />

for the new application.<br />

3. Maintain repository packages.<br />

To perform the high-level tasks that typically occur during the process of maintaining repository packages,<br />

you need to be familiar with the concepts of packages and package hierarchies, which you use to manage the<br />

artifacts in your applications.<br />

4. Maintain application descriptors.<br />

34<br />

The framework defined by the application descriptors includes the root point in the package hierarchy where<br />

cont<strong>en</strong>t is to be served to cli<strong>en</strong>t requests. The framework also defines if the application is permitted to expose<br />

data to cli<strong>en</strong>t requests, what kind of access to the data is allowed, and what if any privileges are required to<br />

perform actions on packages and package cont<strong>en</strong>t.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


4.1 Setting up Delivery Units<br />

A delivery unit is a collection of packages that are to be transported together. You assign all the packages<br />

belonging to your application to the same delivery unit to <strong>en</strong>sure that they are transported consist<strong>en</strong>tly together<br />

within your system landscape. Each delivery unit has a unique id<strong>en</strong>tity.<br />

The id<strong>en</strong>tity of a delivery unit consists of two parts: a v<strong>en</strong>dor name and a delivery-unit name. The combined ID<br />

<strong>en</strong>sures that delivery units from differ<strong>en</strong>t v<strong>en</strong>dors are easy to distinguish and follows a pattern that SAP uses for<br />

all kinds of software compon<strong>en</strong>ts.<br />

To create and manage delivery units you first need to maintain the id<strong>en</strong>tity of the v<strong>en</strong>dor, with whom the delivery<br />

units are associated, and in whose namespace the packages that make up the delivery unit are stored. As part of<br />

the v<strong>en</strong>dor ID maint<strong>en</strong>ance process, you must perform the following tasks:<br />

1. Understand delivery units<br />

You must be familiar with the conv<strong>en</strong>tions that exist for delivery-unit names and understand the phases of the<br />

delivery-unit lifecycle.<br />

2. Maintain details of the v<strong>en</strong>dor ID associated with a delivery unit.<br />

Delivery units are located in the namespace associated with the v<strong>en</strong>dor who creates them and who manages<br />

the delivery-unit's lifecycle.<br />

3. Create a delivery unit.<br />

Related Links<br />

Maintaining the Delivery-Unit V<strong>en</strong>dor ID [page 35]<br />

In SAP HANA, the v<strong>en</strong>dor ID is used primarily to define the id<strong>en</strong>tity of the company <strong>dev</strong>eloping a software<br />

compon<strong>en</strong>t that they plan to ship for use with SAP HANA. If you want to create a delivery unit, it is a<br />

prerequisite to maintain a v<strong>en</strong>dor ID in your system.<br />

Creating a Delivery Unit [page 36]<br />

A delivery unit is a group of transportable objects used for cont<strong>en</strong>t delivery. You can use a delivery unit to<br />

transport the design-time objects that are stored in the SAP HANA repository betwe<strong>en</strong> two systems, for<br />

example, from a <strong>dev</strong>elopm<strong>en</strong>t system to a consolidation system.<br />

4.1.1 Maintaining the Delivery-Unit V<strong>en</strong>dor ID<br />

In SAP HANA, the v<strong>en</strong>dor ID is used primarily to define the id<strong>en</strong>tity of the company <strong>dev</strong>eloping a software<br />

compon<strong>en</strong>t that they plan to ship for use with SAP HANA. If you want to create a delivery unit, it is a prerequisite<br />

to maintain a v<strong>en</strong>dor ID in your system.<br />

Before creating your first own delivery unit you must set the id<strong>en</strong>tity of the v<strong>en</strong>dor in the <strong>dev</strong>elopm<strong>en</strong>t system's<br />

configuration. To maintain details of the delivery-unit v<strong>en</strong>dor ID, perform the following steps:<br />

1. Start the SAP HANA studio.<br />

2. Switch to the Administration Console perspective.<br />

In the SAP HANA studio Navigator view choose Administration . Alternatively, use the m<strong>en</strong>u path: Window ><br />

Op<strong>en</strong> Perspective > Administration Console .<br />

3. Display configuration details for the SAP HANA instance; choose the Configuration tab page.<br />

4. Maintain details of the v<strong>en</strong>dor ID.<br />

In the Configuration tab page, perform the following steps:<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 35


a) Locate indexserver.ini in the list of configuration files displayed in the Name column.<br />

b) Expand the indexserver.ini <strong>en</strong>try.<br />

c) Expand the repository <strong>en</strong>try.<br />

d) Edit the cont<strong>en</strong>t_v<strong>en</strong>dor parameter.<br />

e) Double-click cont<strong>en</strong>t_v<strong>en</strong>dor and <strong>en</strong>ter the name of your v<strong>en</strong>dor. Note that guidelines and conv<strong>en</strong>tions<br />

exist for v<strong>en</strong>dor names.<br />

f) Save your changes.<br />

Note: We recomm<strong>en</strong>d that you use your DNS name to set the v<strong>en</strong>dor ID, for example, acme.com.<br />

4.1.2 SAP HANA Delivery Unit Naming Conv<strong>en</strong>tions<br />

In SAP HANA, conv<strong>en</strong>tions and guidelines exist for the naming of delivery units (DU). The delivery unit is the<br />

vehicle that lifecycle managem<strong>en</strong>t (LCM) uses to ship one or more software compon<strong>en</strong>ts from SAP (or a partner)<br />

to a customer. The DU is also the container you use to transport application cont<strong>en</strong>t in your system landscape.<br />

If you are creating a delivery unit, you must adhere to the following naming conv<strong>en</strong>tions<br />

● The name of a delivery unit must contain only capital letters (A-Z), digits (0-9), and underscores (_)<br />

● You cannot use an underscore (_) as the first character of a delivery-unit name.<br />

Note: The naming conv<strong>en</strong>tions for packages in a delivery unit differ from the naming conv<strong>en</strong>tions that<br />

apply to the delivery unit itself. For example, the maximum l<strong>en</strong>gth of a package name is not restricted to<br />

30 characters; it must be less than 190 characters (including the namespace hierarchy).<br />

4.1.3 Creating a Delivery Unit<br />

A delivery unit is a group of transportable objects used for cont<strong>en</strong>t delivery. You can use a delivery unit to<br />

transport the design-time objects that are stored in the SAP HANA repository betwe<strong>en</strong> two systems, for example,<br />

from a <strong>dev</strong>elopm<strong>en</strong>t system to a consolidation system.<br />

In the SAP HANA studio, you can create a delivery unit in the Quick Launch view of the Modeler perspective :<br />

Note: You cannot create a delivery unit unless you have already defined the delivery unit's v<strong>en</strong>dor ID; the<br />

v<strong>en</strong>dor ID defines the namespace in which the new delivery unit resides.<br />

To create a new delivery unit, perform the following steps:<br />

1. In the SAP HANA studio, start the Modeler perspective.<br />

2. In the Setup scre<strong>en</strong> area of the Quick Launch tab, choose Delivery Units....<br />

3. Create a new delivery unit.<br />

In the Delivery Units dialog, choose Create...<br />

4. Maintain delivery unit details.<br />

36<br />

a) Enter a name for the new delivery unit.<br />

The delivery unit Name is mandatory.<br />

b) Fill in the other information as required:<br />

Note the following points wh<strong>en</strong> <strong>en</strong>tering information:<br />

○ The name of the V<strong>en</strong>dor is set to the v<strong>en</strong>dor ID that is specified in the system configuration, for<br />

example, acme.com.<br />

○ The Responsible text box <strong>en</strong>ables you to specify the name of the person responsible for managing the<br />

delivery unit.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


Related Links<br />

○ In the text boxes Version, Support Package Version, and Patch Version <strong>en</strong>ter integer values only; the<br />

combined values define the version of the delivery unit that is curr<strong>en</strong>tly being <strong>dev</strong>eloped. For<br />

example, <strong>en</strong>ter Version = 1, Support Package Version = 3, and Patch Version = 17 to specify that the<br />

curr<strong>en</strong>t version of your delivery unit is 1.3.17. The version number is transported to other systems<br />

with every DU transport.<br />

Note: The numbers you <strong>en</strong>ter here refer to the application compon<strong>en</strong>t that you are<br />

<strong>dev</strong>eloping; the numbers do not refer to the patch or service-pack level deployed on the SAP<br />

HANA server.<br />

○ The PPMS ID is the product ID used by the SAP Product and Production Managem<strong>en</strong>t System<br />

(PPMS).<br />

Note: Customers and partners should leave the PPMS ID text box empty.<br />

Maintaining the Delivery-Unit V<strong>en</strong>dor ID [page 35]<br />

In SAP HANA, the v<strong>en</strong>dor ID is used primarily to define the id<strong>en</strong>tity of the company <strong>dev</strong>eloping a software<br />

compon<strong>en</strong>t that they plan to ship for use with SAP HANA. If you want to create a delivery unit, it is a<br />

prerequisite to maintain a v<strong>en</strong>dor ID in your system.<br />

SAP HANA Delivery Unit Naming Conv<strong>en</strong>tions [page 36]<br />

In SAP HANA, conv<strong>en</strong>tions and guidelines exist for the naming of delivery units (DU). The delivery unit is the<br />

vehicle that lifecycle managem<strong>en</strong>t (LCM) uses to ship one or more software compon<strong>en</strong>ts from SAP (or a<br />

partner) to a customer. The DU is also the container you use to transport application cont<strong>en</strong>t in your system<br />

landscape.<br />

4.2 Using SAP HANA Projects<br />

Projects group together all the artifacts you need for a specific part of the application-<strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t.<br />

Before you can start the application-<strong>dev</strong>elopm<strong>en</strong>t workflow, you must create a project, which you use to group<br />

together all your application-related artifacts. However, before you create a project, you must create a repository<br />

workspace, which <strong>en</strong>ables you to synchronize changes in local files with changes in the repository. As part of the<br />

project-creation process, you perform the following tasks:<br />

1. Create a <strong>dev</strong>elopm<strong>en</strong>t workspace.<br />

The workspace is the link betwe<strong>en</strong> the SAP HANA repository and your local filesystem, where you work on<br />

project-related objects.<br />

2. Create a project.<br />

Create a new project for a particular application or package; you can use the project to collect in a conv<strong>en</strong>i<strong>en</strong>t<br />

place all your application-related artifacts.<br />

3. Share a project.<br />

Sharing a project <strong>en</strong>ables you to <strong>en</strong>sure that changes you make to project-related files are visible to other<br />

team members and applications. Shared projects are available for import by other members of the<br />

application-<strong>dev</strong>elopm<strong>en</strong>t team.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 37


4. Import a project.<br />

Import a project (and its associated artifacts) that has be<strong>en</strong> shared by another member of the application<strong>dev</strong>elopm<strong>en</strong>t<br />

team.<br />

Related Links<br />

Create a Developm<strong>en</strong>t Workspace [page 39]<br />

A workspace is a local directory that you map to all (or part) of a package hierarchy in the SAP HANA<br />

repository. Wh<strong>en</strong> you check out a package from the repository, SAP HANA copies the cont<strong>en</strong>ts of the package<br />

hierarchy to your workspace, where you can work on the files..<br />

Create a New Project [page 40]<br />

Before you can start the application-<strong>dev</strong>elopm<strong>en</strong>t workflow, you must create a project, which you use to group<br />

all your application-related artifacts.<br />

Share a Project [page 40]<br />

Before you can start working on files associated with a new project, you must share the project; sharing a<br />

project <strong>en</strong>ables you to track and synchronize local changes with the repository.<br />

Import a Project [page 41]<br />

Before you can start the application-<strong>dev</strong>elopm<strong>en</strong>t workflow, you must either create a new project and share it<br />

(with the repository), or import a shared project from the repository into your workspace. Importing a project<br />

<strong>en</strong>ables you to track and synchronize local changes with the colleagues working on the objects in the imported<br />

project.<br />

4.2.1 SAP HANA Repository: Workspaces<br />

The place where you work on project-related objects is called a repository workspace. A workspace is an<br />

<strong>en</strong>vironm<strong>en</strong>t that maps a local directory to all (or part) of a package hierarchy in the SAP HANA repository.<br />

In SAP HANA studio, the repository tools <strong>en</strong>able you to view and browse the <strong>en</strong>tire hierarchy of design-time<br />

objects stored in the repository. However, wh<strong>en</strong> you checkout a package from the repository, SAP HANA copies<br />

the cont<strong>en</strong>ts of the package hierarchy to your workspace, where you can work on the files in your local file system.<br />

Note: Before you can create a workspace you must maintain connection information in the SAP HANA<br />

database user store.<br />

To start <strong>dev</strong>elopm<strong>en</strong>t work with SAP HANA studio, for example, to checkout the cont<strong>en</strong>ts of a package, you must<br />

create a repository workspace. The workspace contains a system folder with metadata and package folders for<br />

the repository cont<strong>en</strong>t. The file-system folders and their subfolders reflect the package hierarchy in the<br />

repository; the repository cli<strong>en</strong>t <strong>en</strong>sures that changes are synchronized. You can use SAP HANA studio to<br />

perform the following workspace-related actions in the repository:<br />

● Checkout folders and files from the repository<br />

● Commit changes to the repository<br />

● Activate the committed changes<br />

● Revert inactive changes to the previously saved version<br />

The commit operation detects all changes in packages that you configure SAP HANA studio tool to track and<br />

writes the detected changes back to the repository. The repository cli<strong>en</strong>t tools also support synchronization with<br />

changes on the server, including conflict detection and merging of change. All workspace-related repository<br />

actions are available as context-s<strong>en</strong>sitive m<strong>en</strong>u options in SAP HANA studio. For example, if you right click a<br />

repository object at the top of the package hierarchy in the Project Explorer in SAP HANA studio, you can commit<br />

and activate all changed objects within the selected hierarchy.<br />

38<br />

Note: If you create a new project using SAP HANA studio, you can assign the new project to an existing<br />

workspace.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


4.2.2 Creating a Repository Workspace<br />

A workspace is a local directory that you map to all (or part) of a package hierarchy in the SAP HANA repository.<br />

Wh<strong>en</strong> you check out a package from the repository, SAP HANA copies the cont<strong>en</strong>ts of the package hierarchy to<br />

your workspace, where you can work on the files..<br />

Before you can start work on the <strong>dev</strong>elopm<strong>en</strong>t of the application, you need to set up a workspace, where you store<br />

checked-out copies of your application’s source-code files.<br />

To create a new workspace in the SAP HANA studio, perform the following steps:<br />

1. Op<strong>en</strong> the SAP HANA studio.<br />

2. Op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective.<br />

3. Choose the SAP HANA Repositories view.<br />

4. Choose Create Workspace…<br />

The Create Workspace… button is located in the top right-hand corner of the SAP HANA Repositories view.<br />

5. Specify the workspace details. In the Create New Repository Workspace dialog, <strong>en</strong>ter the following<br />

information and choose Finish:<br />

a) Specify the SAP HANA system, for which you want to create a new workspace.<br />

b) Enter a workspace name, for example the name of the SAP HANA system where the repository is located.<br />

To avoid the pot<strong>en</strong>tial for confusion, it is recomm<strong>en</strong>ded to associate one workspace with one repository.<br />

c) Specify where the workspace root directory should be located on your local file system, for example: C:<br />

\users\username\workspaces<br />

The new workspace is displayed in the SAP HANA Repositories view.<br />

Note: Although the packages and objects in the chos<strong>en</strong> repository are visible in the SAP HANA<br />

Repositories view, you cannot op<strong>en</strong> or work on the objects here. To work on objects, you must create<br />

a project and use the Project Explorer view.<br />

4.2.3 SAP HANA Studio Projects<br />

Before you can start the application-<strong>dev</strong>elopm<strong>en</strong>t workflow, you must create a project, which you use to group all<br />

your application-related artifacts.<br />

Projects group together all the artifacts you need for a specific part of the application-<strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t.<br />

A basic project contains folders and files. More advanced projects are used for builds, version managem<strong>en</strong>t,<br />

sharing, and the organization and maint<strong>en</strong>ance of resources.<br />

Projects <strong>en</strong>able multiple people to work on the same files at the same time. By committing project-related files to<br />

the repository and activating them, you <strong>en</strong>able team members to see the latest changes.<br />

You can share and unshare projects. Sharing a project associates it with a particular package in the repository<br />

linked to a particular workspace. The act of sharing the project sets up a link betwe<strong>en</strong> the workspace and the<br />

repository and <strong>en</strong>ables you to track and synchronize local changes with the versions of the objects stored in the<br />

repository. Wh<strong>en</strong> a project is shared, it becomes available to other people with authorization to access to the<br />

repository, for example, colleagues in an application-<strong>dev</strong>elopm<strong>en</strong>t team. Team members can import a shared<br />

project and see and work on the same files as the creator of the project.<br />

Note: Always unshare a project before deleting it.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 39


In the SAP HANA studio you can create a project at any package level, which <strong>en</strong>ables a fine level of control of the<br />

artifacts that may (or may not) be exposed by sharing the project.<br />

4.2.4 Creating a Project for SAP HANA XS<br />

Before you can start the application-<strong>dev</strong>elopm<strong>en</strong>t workflow, you must create a project, which you use to group all<br />

your application-related artifacts.<br />

Projects group together all the artifacts you need for a specific part of your application-<strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t.<br />

Dep<strong>en</strong>ding on the type of project you are working on, the project can include build tools, too. A basic project<br />

contains folders and files. More advanced projects are used for builds, version managem<strong>en</strong>t, sharing, and the<br />

organization and maint<strong>en</strong>ance of resources.<br />

To create a new project in the SAP HANA studio, perform the following steps:<br />

1. Op<strong>en</strong> the SAP HANA studio.<br />

2. Op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective.<br />

3. Choose the Project Explorer view.<br />

4. Right-click the white space in the Project Explorer view and choose New > Project… in the popup m<strong>en</strong>u.<br />

The type of project you create determines the details you have to provide in the New Project dialog that<br />

appears.<br />

a) Enter a project name that describes what the project is about, for example: XS_JavaScript, XS_OData<br />

or XS_SAPUI5.<br />

b) Click Finish to create the new project.<br />

The new project is displayed in the Project Explorer view.<br />

Note: The cont<strong>en</strong>ts of the project dep<strong>en</strong>d on the type of project you create. For example, a g<strong>en</strong>eral<br />

project is empty immediately after creation; a JavaScript project contains all the resource files<br />

associated with a JavaScript project, such as libraries and build-<strong>en</strong>vironm<strong>en</strong>t artifacts.<br />

4.2.5 Sharing a Project for SAP HANA XS<br />

Before you can start working on files associated with a new project, you must share the project; sharing a project<br />

<strong>en</strong>ables you to track and synchronize local changes with the repository.<br />

Wh<strong>en</strong> you share a project, you set up a connection to the SAP HANA repository associated with a particular SAP<br />

HANA instance. Sharing the project <strong>en</strong>ables you to <strong>en</strong>sure that changes you make to project-related files are<br />

visible to other team members and applications. Other <strong>dev</strong>elopers can import a shared project and work on the<br />

same files.<br />

Note: Use the Project Explorer view in the SAP HANA studio to check if a project is shared. In addition to<br />

the project name, a shared project displays the SAP HANA system ID of the repository where the shared<br />

artifacts are located, a SAP HANA user name, and the path to the repository package to which the shared<br />

project is assigned, for example. "XSJS_myproject [SID (dbusername,<br />

'sap.<strong>hana</strong>.xs.app1')].<br />

To share a project in the SAP HANA studio, perform the following steps:<br />

1. Op<strong>en</strong> the SAP HANA studio<br />

2. Op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective.<br />

40<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


3. Op<strong>en</strong> the Project Explorer view.<br />

4. Share the project<br />

Right-click the project you want to share and choose Team > Share Project… in the pop-up m<strong>en</strong>u.<br />

5. Select the repository type.<br />

The Share Project dialog displays a list of all available repository types; choose SAP HANA Repository and<br />

choose Next.<br />

6. Select the repository workspace where the project should be located.<br />

7. Specify the package that you want to associate the shared project with.<br />

The Share Project dialog displays the suggested location for the shared project in the New Project location<br />

scre<strong>en</strong> area. The default location is the name of the workspace with the name of the project you want to<br />

share. Choose Browse... to locate the package you want to associate the shared project with. The selected<br />

package is displayed in the Path to package text box.<br />

Note: The Keep project folder option app<strong>en</strong>ds the name of the project you are sharing to the name of<br />

the workspace in which you are sharing the project and creates a new package with the name of the<br />

shared project under the workspace location displayed. Use this option only if you want to create<br />

multiple projects for a selected package, for example, if you are creating a root project in your root<br />

application package.<br />

8. Click Finish to complete the project-sharing procedure.<br />

9. Add new files as required<br />

At this point you can start adding project-specific files to the shared project. These artifacts can th<strong>en</strong> be<br />

committed to the repository, where they reside as inactive objects until they are activated, for example, using<br />

the Team Activate option in the context-s<strong>en</strong>sitive m<strong>en</strong>us available in the Project Navigator view.<br />

Note: The Project Explorer view decorates the file icons to indicate the curr<strong>en</strong>t state of the repository<br />

files, for example: local (not yet committed), committed (inactive), and active (available for use by<br />

others).<br />

10. Make the project available for import, for example, so that others can join it and make changes to project<br />

cont<strong>en</strong>t.<br />

The project-sharing procedure creates some artifacts (for example, the .project file) that must be<br />

committed to the repository and activated so that other team members can import the project more easily<br />

into their workspace. The .project file is used in several dialogs to populate the list of available projects.<br />

Related Links<br />

Note: Use the SAP HANA Repositories view to import projects (and checkout project cont<strong>en</strong>t).<br />

Importing a Project in SAP HANA XS [page 41]<br />

Before you can start the application-<strong>dev</strong>elopm<strong>en</strong>t workflow, you must either create a new project and share it<br />

(with the repository), or import a shared project from the repository into your workspace. Importing a project<br />

<strong>en</strong>ables you to track and synchronize local changes with the colleagues working on the objects in the imported<br />

project.<br />

4.2.6 Importing a Project in SAP HANA XS<br />

Before you can start the application-<strong>dev</strong>elopm<strong>en</strong>t workflow, you must either create a new project and share it<br />

(with the repository), or import a shared project from the repository into your workspace. Importing a project<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 41


<strong>en</strong>ables you to track and synchronize local changes with the colleagues working on the objects in the imported<br />

project.<br />

To import an existing project from the repository into your workspace, perform the following steps.<br />

1. Op<strong>en</strong> the SAP HANA studio<br />

2. Op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective.<br />

3. Choose the HANA Repositories view.<br />

4. Right-click the package where the project you want to import is located and choose Checkout and Import<br />

Projects... in the popup m<strong>en</strong>u.<br />

Projects can be assigned to a package at any level of the package hierarchy. If you know where the project is<br />

located, browse to the package first before choosing the Checkout and Import Projects... option. This reduces<br />

the amount of files to checkout and download to your local file system.<br />

Note: The exist<strong>en</strong>ce of a .project file in a package id<strong>en</strong>tifies the package as being associated with a<br />

project.<br />

The SAP HANA studio checks out the cont<strong>en</strong>t of the selected package and displays any projects it finds in the<br />

Projects scre<strong>en</strong> area.<br />

5. Select the projects to import.<br />

If multiple projects are available for import, select the projects you want to import.<br />

6. Choose Finish to import the selected projects.<br />

You can add the imported project to your Working Sets.<br />

Note: A working set is a concept similar to favorites in a Web browser, which contain the objects you<br />

work on most frequ<strong>en</strong>tly.<br />

4.3 Maintaining Repository Packages<br />

All cont<strong>en</strong>t delivered as part of the application you <strong>dev</strong>elop for SAP HANA is stored in packages in the SAP HANA<br />

repository. The packages are arranged in a hierarchy that you define to help make the process of maintaining the<br />

packages transpar<strong>en</strong>t and logical.<br />

To perform the high-level tasks that typically occur during the process of maintaining repository packages, you<br />

need to be familiar with the concepts of packages and package hierarchy that create and maintain the artifacts for<br />

your applications. You also need to know about the privileges the application <strong>dev</strong>elopers will need to have access<br />

to (and perform operations on) the packages.<br />

Note: You can also create and delete packages in the Project Explorer, for example, by creating or deleting<br />

folders in shared projects and committing and activating these changes. However, to maintain advanced<br />

package properties (for example, privileges, compon<strong>en</strong>t, the package maintainer, and so on) you must<br />

use the Modeling perspective in the SAP HANA studio..<br />

As part of the process of maintaining your application packages, you typically perform the following tasks:<br />

42<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


1. Create a package<br />

Packages are necessary to group logically distinct artifacts together in one object location that is easy to<br />

transport.<br />

2. Define the package hierarchy<br />

The package hierarchy is ess<strong>en</strong>tial for ease of maint<strong>en</strong>ance as well as the configuration of access to packages<br />

and the privileges that are required to perform actions on the packages.<br />

3. Define package privileges<br />

You can set package authorizations for a specific user or for a role. Authorizations that are assigned to a<br />

repository package are implicitly assigned to all sub-packages, too.<br />

Related Links<br />

Creating a package [page 46]<br />

In SAP HANA, a package contains a selection of repository objects. You assemble a collection of packages into<br />

a delivery unit, which you can use to transport the repository objects betwe<strong>en</strong> SAP HANA systems.<br />

Defining the package hierarchy [page 47]<br />

Packages belonging to an application-<strong>dev</strong>elopm<strong>en</strong>t delivery unit (DU) should be organized in a clear<br />

hierarchical structure under a single root package repres<strong>en</strong>ting the v<strong>en</strong>dor, for example, acme.<br />

Defining package privileges [page 46]<br />

In the SAP HANA repository, you can set package authorizations for a specific user or for a role.<br />

Authorizations that are assigned to a repository package are implicitly assigned to all sub-packages, too. You<br />

can also specify if the assigned user authorizations can be passed on to other users.<br />

4.3.1 SAP HANA Repository Packages and Namespaces<br />

In SAP HANA, a package typically consists of a collection of repository objects, which can be transported betwe<strong>en</strong><br />

systems. Multiple packages can be combined in a delivery unit (DU).<br />

A SAP HANA package specifies a namespace in which the repository objects exist. Every repository object is<br />

assigned to a package, and each package must be assigned to a specific delivery unit. In the repository, each<br />

object is uniquely id<strong>en</strong>tified by a combination of the following information:<br />

● Package name<br />

● Object name<br />

● Object type<br />

Note: Multiple objects of the same type can have the same object name if they belong to differ<strong>en</strong>t<br />

packages.<br />

Before you start the package <strong>dev</strong>elopm<strong>en</strong>t process, consider the following important points:<br />

● Package hierarchy<br />

Each v<strong>en</strong>dor uses a dedicated namespace, and the package hierarchy you create <strong>en</strong>ables you to store the<br />

various elem<strong>en</strong>ts of an application in a logical order that is easy to navigate.<br />

● Package type<br />

Packages can be structural or non-structural; some packages contain cont<strong>en</strong>t; other packages contain only<br />

other (sub)packages.<br />

● Package naming conv<strong>en</strong>tions<br />

There are recomm<strong>en</strong>dations and restrictions regarding package names, for example, the name's maximum<br />

l<strong>en</strong>gth and what if any characters must not be used.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 43


Package Hierarchy<br />

You can create a package hierarchy, for example, by establishing a par<strong>en</strong>t-child type relationship betwe<strong>en</strong><br />

packages. The assignm<strong>en</strong>t of packages to delivery units is indep<strong>en</strong>d<strong>en</strong>t of the package hierarchy; packages in a<br />

par<strong>en</strong>t-child relationship can belong to differ<strong>en</strong>t delivery units. SAP recomm<strong>en</strong>ds that you assign to one specific<br />

delivery unit all packages that are part of a particular project or project area.<br />

The package hierarchy for a new project typically includes sub-packages, for example, to isolate the data model<br />

from the business logic. Although there are no package interfaces to <strong>en</strong>force visibility of objects across packages,<br />

this separation of logical layers of <strong>dev</strong>elopm<strong>en</strong>t is still a recomm<strong>en</strong>ded best practice.<br />

Note: You can only assign one project per package; this is important to remember if you have a mixture of<br />

design-time objects that need to be used in multiple projects, for example: server-side JavaScript (XSJS),<br />

SAPUI5, and a g<strong>en</strong>eral project (for procedures).<br />

The following simple example shows a package structure containing tutorials for the use of a new application:<br />

sap<br />

\<br />

<strong>hana</strong><br />

\<br />

app1<br />

\<br />

code<br />

demos<br />

docs<br />

\<br />

tutorials<br />

manuals<br />

help<br />

All cont<strong>en</strong>t delivered by SAP should be in a sub-package of "sap". Partners and customers should choose their<br />

own root package to reflect their own name (for example, the domain name associated with the company) and<br />

must not create packages or objects under the "sap" root structural package. This rules <strong>en</strong>sures that customer or<br />

partner created cont<strong>en</strong>t will not be overwritt<strong>en</strong> by an SAP update or patch.<br />

Note: SAP reserves the right to deliver without notification changes in packages and models below the<br />

"sap" root structural package.<br />

There are no system mechanisms for <strong>en</strong>forcing the package hierarchy. The "sap" root structural package is not<br />

automatically protected. However, by default you cannot change the cont<strong>en</strong>t of packages that did not originate in<br />

the system. In addition, an authorization concept exists, which <strong>en</strong>ables you to control who can change what inside<br />

packages.<br />

Package Types<br />

SAP HANA Application Services provide or allow the following package types:<br />

● Structural<br />

44<br />

Package only contains sub-packages; it cannot contain repository objects.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


● Non-Structural<br />

Package contains both repository objects and subpackages.<br />

The following packages are delivered by default with the repository:<br />

● sap<br />

Transportable package reserved for cont<strong>en</strong>t delivered by SAP. Partners and customers must not use the sap<br />

package; they must create and use their own root package to avoid conflicts with software delivered by SAP,<br />

for example wh<strong>en</strong> SAP updates or overwrites the sap package structure during an update or patch process.<br />

● system-local<br />

Non-transportable, structural packages (and subpackages). Cont<strong>en</strong>t in this package (and any subpackages)<br />

is considered system local and cannot be transported. This is similar to the concept of the $tmp <strong>dev</strong>elopm<strong>en</strong>t<br />

class in SAP NetWeaver ABAP.<br />

● system-local.g<strong>en</strong>erated<br />

Transportable, structural packages for g<strong>en</strong>erated cont<strong>en</strong>t, that is; cont<strong>en</strong>t not created by manual user<br />

interaction<br />

● system-local.private<br />

Transportable, structural sub-packages containing objects that belong to individual users and are named<br />

after these users (and are exclusively reserved for these users). For example, system-<br />

local.private.<br />

Package Naming Conv<strong>en</strong>tions<br />

The following rules apply to package names:<br />

● Permitted characters<br />

Lower/upper case letters (aA-zZ), digits (0-9), hyph<strong>en</strong>s (-), and dots (.) are permitted in package names.<br />

Dots in a package name define a logical hierarchy. For example, "a.b.c" specifies a package "a" that contains<br />

sub-package "b", which in turn contains sub-package "c".<br />

● Forbidd<strong>en</strong> characters<br />

A package name must not start with either a dot (.) or a hyph<strong>en</strong> (-) and cannot contain two or more<br />

consecutive dots (..).<br />

● Package name l<strong>en</strong>gth<br />

The maximum permitted l<strong>en</strong>gth of a package name is 190 characters. To avoid problems, we recomm<strong>en</strong>d you<br />

restrict the l<strong>en</strong>gth of package names to well under the 190-character limit.<br />

● Package namespace l<strong>en</strong>gth<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 45


The name of the complete package namespace hierarchy (for example, "aa.bb.cc.zz" including dots) must not<br />

be more than 190 characters long. To avoid problems, we recomm<strong>en</strong>d you restrict the l<strong>en</strong>gth of the package<br />

namespace to well under the 190-character limit.<br />

4.3.2 Defining Repository Package Privileges<br />

In the SAP HANA repository, you can set package authorizations for a specific user or for a role. Authorizations<br />

that are assigned to a repository package are implicitly assigned to all sub-packages, too. You can also specify if<br />

the assigned user authorizations can be passed on to other users.<br />

To set user (or role) authorizations for repository packages, perform the following steps:<br />

1. In the SAP HANA studio, op<strong>en</strong> the Navigator view of the Modeler perspective.<br />

2. In the Navigator view, expand the Security Roles/Users node for the system hosting the repository that<br />

contains the packages you want to grant access to.<br />

You can also define roles via source files; roles defined in this way can be assigned to a delivery unit and<br />

transported to other systems.<br />

3. Double click the user (or role) to whom you want to assign authorizations.<br />

4. Op<strong>en</strong> the Package Privileges tab page.<br />

5. Choose [+] to add one or more packages. Press and hold the Ctrl key to select multiple packages.<br />

6. In the Select Repository Package dialog, use all or part of the package name to locate the repository package<br />

that you want to authorize access to.<br />

7. Select one or more repository packages that you want to authorize access to; the selected packages appear<br />

in the Package Privileges tab page.<br />

8. Select the packages to which you want authorize access and, in the Privileges for scre<strong>en</strong> page, check the<br />

required privileges, for example:<br />

a) REPO.READ<br />

Read access to the selected package and design-time objects (both native and imported)<br />

b) REPO.EDIT_NATIVE_OBJECTS<br />

Authorization to modify design-time objects in packages originating in the system the user is working in<br />

c) REPO.ACTIVATE_NATIVE_OBJECTS<br />

Authorization to activate/reactivate design-time objects in packages originating in the system the user is<br />

working in<br />

d) REPO.MAINTAIN_NATIVE_PACKAGES<br />

Authorization to update or delete native packages, or create sub-packages of packages originating in the<br />

system in which the user is working<br />

4.3.3 Creating a Package<br />

In SAP HANA, a package contains a selection of repository objects. You assemble a collection of packages into a<br />

delivery unit, which you can use to transport the repository objects betwe<strong>en</strong> SAP HANA systems.<br />

You can use packages to manage the various elem<strong>en</strong>ts of your application <strong>dev</strong>elopm<strong>en</strong>t project. To create a<br />

project, perform the following steps:<br />

1. In the SAP HANA studio, start the Modeler perspective.<br />

2. In the New scre<strong>en</strong> area of the Quick Launch tab page, choose Package and choose Create....<br />

3. Maintain the package details.<br />

46<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


In the New Package dialog, <strong>en</strong>ter information in the following fields:<br />

a) Enter a name for the new package.<br />

The package Name is mandatory.<br />

b) Fill in the other optional information as required:<br />

Related Links<br />

Use the Delivery Unit drop-down list to assign the new package to a delivery unit.<br />

Choose Translation if you int<strong>en</strong>d to have the package cont<strong>en</strong>t localized. You must maintain the translation<br />

details.<br />

SAP HANA Delivery-Unit Translation Details [page 349]<br />

The SAP HANA repository includes features for translating package-related metadata texts. If you plan to<br />

translate the cont<strong>en</strong>ts of the new delivery unit you create, you must maintain translation details.<br />

4.3.4 Defining a Package Hierarchy<br />

Packages belonging to an application-<strong>dev</strong>elopm<strong>en</strong>t delivery unit (DU) should be organized in a clear hierarchical<br />

structure under a single root package repres<strong>en</strong>ting the v<strong>en</strong>dor, for example, acme.<br />

The package hierarchy for a new project might include sub-packages, for example, to isolate the data model from<br />

the business logic. Although there are no package interfaces to <strong>en</strong>force visibility of objects across packages, this<br />

separation of logical layers of <strong>dev</strong>elopm<strong>en</strong>t is still a recomm<strong>en</strong>ded best practice.<br />

Note: You can only assign one project per package; this is important to remember if you have a mixture of<br />

design-time objects that need to be used in multiple projects, for example: server-side JavaScript (XSJS),<br />

SAPUI5, and a g<strong>en</strong>eral project (for procedures).<br />

The following simple example shows a package structure containing tutorials for the use of a new application:<br />

acme<br />

\<br />

<strong>hana</strong><br />

\<br />

app1<br />

\<br />

docs<br />

\<br />

tutorials<br />

● Package hierarchy<br />

Each v<strong>en</strong>dor uses a dedicated namespace, for example, acme.<br />

● Package type<br />

Note: Do not use the namespace sap to build your application hierarchy. The namespace sap is<br />

reserved for use by SAP; packages created in the sap namespace are overwritt<strong>en</strong> by system updates.<br />

Some packages contain cont<strong>en</strong>t; other packages contain only other (sub)packages. Packages can also<br />

contain both objects and (sub)packages.<br />

● Package naming conv<strong>en</strong>tions<br />

There are recomm<strong>en</strong>dations and restrictions regarding package names.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 47


To set up a package hierarchy in the SAP HANA repository, perform the following steps:<br />

1. Create a new root package.<br />

Op<strong>en</strong> the Modeler perspective and perform the following steps:<br />

a) Choose New > Package .<br />

b) Choose Create...<br />

2. Maintain the package details.<br />

In the Create Package dialog, perform the following steps:<br />

a) Enter the name of the package (mandatory).<br />

Guidelines and conv<strong>en</strong>tions apply to package names.<br />

b) Enter a package description (optional).<br />

c) Specify the delivery unit that the package is assigned to.<br />

You can add additional packages to a delivery unit at a later point in time, too.<br />

d) Specify a language for the package cont<strong>en</strong>t.<br />

e) Assign responsibility of the package to a specific user (optional).<br />

By default, the responsible user for a new package is the database user connected to the SAP HANA<br />

repository in the curr<strong>en</strong>t SAP HANA studio session.<br />

f) Maintain translation details.<br />

If you plan to have the cont<strong>en</strong>t translated, you need to maintain the translation details; this is covered in<br />

another topic.<br />

3. Create a new subpackage.<br />

In the Navigator view of the Modeler perspective, perform the following steps:<br />

a) Right-click the package to which you want to add a new subpackage.<br />

b) In the pop-up m<strong>en</strong>u, choose New > Package...<br />

4. Maintain the subpackage details.<br />

In the Create Package dialog, perform the following steps:<br />

a) Enter the name of the subpackage (mandatory).<br />

Guidelines and conv<strong>en</strong>tions apply to package names.<br />

b) Enter a description for the new subpackage (optional).<br />

c) Specify the delivery unit that the subpackage is assigned to.<br />

You can add additional packages to a delivery unit at a later point in time, too.<br />

d) Specify a language for the subpackage cont<strong>en</strong>t.<br />

e) Assign responsibility of the subpackage to a specific user (optional).<br />

By default, the responsible user for a new package is the database user connected to the SAP HANA<br />

repository in the curr<strong>en</strong>t SAP HANA studio session.<br />

f) Maintain translation details.<br />

Related Links<br />

If you plan to have the cont<strong>en</strong>t translated, you need to maintain the translation details; this is covered in<br />

another topic.<br />

SAP HANA Delivery Unit Naming Conv<strong>en</strong>tions [page 36]<br />

In SAP HANA, conv<strong>en</strong>tions and guidelines exist for the naming of delivery units (DU). The delivery unit is the<br />

vehicle that lifecycle managem<strong>en</strong>t (LCM) uses to ship one or more software compon<strong>en</strong>ts from SAP (or a<br />

partner) to a customer. The DU is also the container you use to transport application cont<strong>en</strong>t in your system<br />

landscape.<br />

48<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


Maintaining Translation Details [page 349]<br />

Translation details provide a brief overview of the type and curr<strong>en</strong>t status of the text objects to be translated,<br />

for example, by specifying the technical area of the new delivery unit and indicating the curr<strong>en</strong>t status of<br />

translation texts.<br />

4.4 Creating the Application Descriptors<br />

Wh<strong>en</strong> you <strong>dev</strong>elop and deploy applications in the context of SAP HANA Ext<strong>en</strong>ded Application Services (SAP<br />

HANA XS), you must define the application descriptors, which describe the framework in which the application<br />

runs. The framework defined by the application descriptors includes the root point in the package hierarchy where<br />

cont<strong>en</strong>t is to be served to cli<strong>en</strong>t requests, whether the application is permitted to expose data to cli<strong>en</strong>t requests,<br />

what kind of access to the data is allowed, and what if any privileges are required to perform actions on packages<br />

and package cont<strong>en</strong>t.<br />

To perform the high-level tasks that make up the process of defining the application descriptors, you must be<br />

familiar with the concept of the application descriptor, the application-access file, and if required, the application-<br />

privileges file. Maintaining the application descriptors involves the following tasks:<br />

1. Creating the application descriptor file.<br />

The package that contains the application descriptor file becomes the root path of the resources exposed to<br />

cli<strong>en</strong>t requests by the application you <strong>dev</strong>elop.<br />

2. Creating the application-access file.<br />

The application-access file <strong>en</strong>ables you to specify who or what is authorized to access the cont<strong>en</strong>t exposed by<br />

the application package and what cont<strong>en</strong>t they are allowed to see.<br />

3. Creating the application-privileges file. (Optional)<br />

The application-privileges file can be used to define the authorization privileges required for access to an<br />

application, for example, to start the application or to perform administrative actions on an application.<br />

Related Links<br />

Create an application descriptor [page 50]<br />

Each application that you want to <strong>dev</strong>elop and deploy on SAP HANA Ext<strong>en</strong>ded Application Services (SAP<br />

HANA XS) must have an application-descriptor file. The application descriptor is the core file that you use to<br />

describe an application's framework within SAP HANA XS.<br />

Create an application-access file [page 57]<br />

The application-access file <strong>en</strong>ables you to specify who or what is authorized to access the cont<strong>en</strong>t exposed by<br />

the application package and what cont<strong>en</strong>t they are allowed to see.<br />

Create an application-privileges file [page 60]<br />

The application-privileges (.xssprivileges) file can be used to grant authorization levels for an application,<br />

for example, to start the application or perform administrative actions on an application.<br />

4.4.1 The SAP HANA XS Application Descriptor<br />

Each application that you want to <strong>dev</strong>elop and deploy on SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA<br />

XS) must have an application descriptor file. The application descriptor is the core file that you use to describe an<br />

application's framework within SAP HANA XS.<br />

The package that contains the application descriptor file becomes the root path of the resources exposed to cli<strong>en</strong>t<br />

requests by the application you <strong>dev</strong>elop.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 49


Note: The application-descriptor file has no cont<strong>en</strong>ts and no name; it only has the file ext<strong>en</strong>sion “xsapp”,<br />

for example, .xsapp. For backward compatibility, cont<strong>en</strong>t is allowed in the .xsapp file but ignored.<br />

The application descriptor file performs the following operations:<br />

● Determines the called application<br />

The application root is determined by the package containing the .xsapp file. If the package sap.test<br />

contains the file .xsapp, the application will be available under the URL http://:/<br />

sap.test/.<br />

4.4.2 Create an Application Descriptor File<br />

Each application that you want to <strong>dev</strong>elop and deploy on SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA<br />

XS) must have an application-descriptor file. The application descriptor is the core file that you use to describe an<br />

application's framework within SAP HANA XS.<br />

The package that contains the application-descriptor file becomes the root path of the resources exposed by the<br />

application you <strong>dev</strong>elop.<br />

1. Create a root package for your application, for example, helloxsjs.<br />

2. Create an application descriptor for your application and place it in the root package you created in the<br />

previous step.<br />

The application descriptor is the core file that you use to describe an application's availability within SAP<br />

HANA Ext<strong>en</strong>ded Application Services. The application-descriptor file has no cont<strong>en</strong>ts and no name; it only has<br />

the file ext<strong>en</strong>sion .xsapp..<br />

Note: For backward compatibility, cont<strong>en</strong>t is allowed in the .xsapp file but ignored.<br />

3. Save and activate your changes and additions.<br />

4.4.3 The Application-Access File<br />

SAP HANA XS <strong>en</strong>ables you to define access to each individual application package that you want to <strong>dev</strong>elop and<br />

deploy.<br />

The application-access file <strong>en</strong>ables you to specify who or what is authorized to access the cont<strong>en</strong>t exposed by a<br />

SAP HANA XS application package and what cont<strong>en</strong>t they are allowed to see. For example, you use the<br />

application-access file to specify if auth<strong>en</strong>tication is to be used to check access to package cont<strong>en</strong>t and whether if<br />

rules are in place for the exposure of target and source URLs.<br />

The application-access file does not have a name; it only has the file ext<strong>en</strong>sion .xsaccess. The cont<strong>en</strong>t of<br />

the .xsaccess file is formatted according to JSON rules and is associated with the package it belongs to as well<br />

as any subpackages lower in the package hierarchy. Multiple .xsaccess files are allowed, but only at differ<strong>en</strong>t<br />

levels in the package hierarchy. This <strong>en</strong>ables you to specify differ<strong>en</strong>t application-access rules for individual<br />

packages and subpackages in the package hierarchy.<br />

Note: You cannot place two .xsaccess files in the same package. Furthermore, the rules specified in<br />

a .xsaccess file that is associated with a subpackage take preced<strong>en</strong>ce over any rules specified in<br />

a .xsaccess file associated with any par<strong>en</strong>t package higher up the package hierarchy.<br />

The application-access file performs the following operations:<br />

● Data exposure<br />

50<br />

Use the exposed keyword to specify if package cont<strong>en</strong>t is to be exposed to cli<strong>en</strong>t requests via HTTP.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


Note: Exposed package cont<strong>en</strong>t can include design-time objects, for example, tables and views.<br />

● Auth<strong>en</strong>tication rules<br />

Use the auth<strong>en</strong>tication keyword to <strong>en</strong>able authorization for the requests in URLs either at the application level<br />

or for single packages in an application. The following auth<strong>en</strong>tication methods are supported:<br />

○ SAP logon tickets<br />

SAP logon tickets <strong>en</strong>able single sign-on across SAP boundaries; SAP logon tickets can also be used as<br />

auth<strong>en</strong>tication for access to third-party applications.<br />

○ Form-based auth<strong>en</strong>tication<br />

Redirect the logon request to a form to fill in, for example, on a Web page.<br />

○ Basic (user name and password)<br />

Log on with a recognized user name and password<br />

The auth<strong>en</strong>tication methods can also be writt<strong>en</strong> as an array, for example, to allow applications to support<br />

multiple auth<strong>en</strong>tication methods. The order of the auth<strong>en</strong>tication methods in the array should proceed from<br />

strongest to weakest, for example:<br />

1. SAP logon ticket<br />

2. Form-based<br />

3. Basic auth<strong>en</strong>tication<br />

● Application authorization<br />

Use the authorization keyword in the .xsaccess file to specify which authorization level is required by a user<br />

for access to a particular application package. The authorization levels you can choose from are defined in<br />

the .xsprivileges file, for example, "execute" for basic privileges, or "admin" for administrative privileges<br />

on the specified package.<br />

● URL rewrite rules<br />

Use the rewrite_rules keyword in the .xsaccess file to hide internal URL path details from external users,<br />

cli<strong>en</strong>ts, and search <strong>en</strong>gines. It is not possible to define global rewrite rules; the rules you define apply to the<br />

specified local application only. Rules are specified as a source-target pair where the source is writt<strong>en</strong> in the<br />

JavaScript regex syntax, and the target is a simple string where refer<strong>en</strong>ces to the groups found can be<br />

inserted using $groupnumber.<br />

● Connection security<br />

Use the force_ssl keyword in the .xsaccess file to <strong>en</strong>force the use of secure HTTP (SSL/HTTPS) for cli<strong>en</strong>t<br />

connections. Browser requests that do not use SSL/HTTPS are refused and the 403 Forbidd<strong>en</strong> page is<br />

displayed. Note that if you set the force_ssl option, th<strong>en</strong> you must <strong>en</strong>sure that the SAP Web Dispatcher is<br />

configured to accept and manage HTTPS requests. For more information about configuring the SAP Web<br />

Dispatcher to use HTTPS/SSL see the SAP HANA Administration Guide.<br />

Note:<br />

● Entity Tags<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

If the SAP Webdispatcher s<strong>en</strong>ds the header “x-sap-webdisp-ap” with the HTTPS port, the request is<br />

redirected to a HTTPS page, for example: http://..:80/test -> https://..:433/test.<br />

Otherwise, a 403 error is displayed.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 51


You can allow or prev<strong>en</strong>t the g<strong>en</strong>eration of <strong>en</strong>tity tags (etags) for static Web cont<strong>en</strong>t using the <strong>en</strong>able_etags<br />

keyword in the .xsaccess file. Etags are used to improve caching performance, for example, so that the<br />

same data is not res<strong>en</strong>t if no change has occurred since the last request.<br />

● MIME Mapping<br />

MIME means Multipurpose Internet Mail Ext<strong>en</strong>sions. You can use the mime_mapping keyword in<br />

the .xsaccess file to define the way in which to map certain file suffixes to required MIME types:<br />

"mime_mapping": [ {"ext<strong>en</strong>sion":"jpg", "mimetype":"image/jpeg"} ]<br />

The Application-Access (.xsaccess) File<br />

The following example, shows the composition and structure of the SAP HANA XS application access<br />

(.xsaccess) file. In this file, data is available to cli<strong>en</strong>t requests. The auth<strong>en</strong>tication methods specified are<br />

SAP logon ticket and th<strong>en</strong>, as a fall-back option if the logon with the SAP logon ticket fails, a logon with a<br />

user name and password. Allowing a fall-back log-on mechanism is useful if the requesting cli<strong>en</strong>t has<br />

problems handling the SAP logon ticket mechanism.<br />

{<br />

$3"<br />

}<br />

Related Links<br />

"exposed" : true, // Expose data via http<br />

"auth<strong>en</strong>tication" : // Auth<strong>en</strong>tication method<br />

[<br />

{<br />

"method": "LogonTicket",<br />

},<br />

{<br />

"method" : "Basic"<br />

},<br />

],<br />

"authorization": // Grant package privileges<br />

[<br />

"sap.xse.test::Execute",<br />

"sap.xse.test::Admin"<br />

]<br />

"rewrite_rules" : // URL rewriting rules<br />

[<br />

{<br />

"source": "/<strong>en</strong>tries/(\\d+)/(\\d+)/(\\d+)/",<br />

"target": "/logic/<strong>en</strong>tries.xsjs?year=$1&month=$2&day=<br />

}<br />

],<br />

"mime_mapping" : // Map file-suffix to MIME type<br />

[<br />

{<br />

"ext<strong>en</strong>sion":"jpg", "mimetype":"image/jpeg"<br />

}<br />

],<br />

"force_ssl" : true, // Refuse request if not SSL<br />

"<strong>en</strong>able_etags":false // Prev<strong>en</strong>t etag g<strong>en</strong>eration<br />

http://help.sap.com/<strong>hana</strong>/<strong>hana</strong>_admin_<strong>en</strong>.pdf<br />

52<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


Application-Access File Keyword Options [page 53]<br />

The application-access (.xsaccess) file <strong>en</strong>ables you to specify whether or not to expose package cont<strong>en</strong>t,<br />

which auth<strong>en</strong>tication method is used to grant access, and what cont<strong>en</strong>t is visible.<br />

4.4.4 Application-Access File Keyword Options<br />

The application-access (.xsaccess) file <strong>en</strong>ables you to specify whether or not to expose package cont<strong>en</strong>t, which<br />

auth<strong>en</strong>tication method is used to grant access, and what cont<strong>en</strong>t is visible.<br />

The Application Access (.xsaccess) File<br />

The following example shows all possible keyword combinations in the SAP HANA XS application-access<br />

(.xsaccess) file.<br />

}<br />

{<br />

exposed<br />

{<br />

Note: In the form shown below, the .xsaccess file is not a working model; it is used to illustrate all<br />

possible options.<br />

"exposed" : true,<br />

"auth<strong>en</strong>tication" : // null = no auth required,<br />

[<br />

{<br />

"method": "LogonTicket",<br />

},<br />

{<br />

"method" : "Basic"<br />

},<br />

{<br />

"method": "Form",<br />

}<br />

],<br />

"authorization":<br />

[<br />

"sap.xse.test::Execute",<br />

"sap.xse.test::Admin"<br />

]<br />

"rewrite_rules" :<br />

[{<br />

"source" : "...",<br />

"target" : "..."<br />

}],<br />

"mime_mapping" :<br />

[<br />

{<br />

"ext<strong>en</strong>sion":"jpg", "mimetype":"image/jpeg"<br />

}<br />

],<br />

"force_ssl" : true,<br />

"<strong>en</strong>able_etags":false<br />

"exposed" : true,<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 53


}<br />

The exposed keyword <strong>en</strong>ables you define if cont<strong>en</strong>t in a package (and its subpackages) is to be made available by<br />

HTTP to cli<strong>en</strong>t requests. Values are Boolean true or false. If no value is set for exposed, the default setting (false)<br />

applies.<br />

auth<strong>en</strong>tication<br />

}<br />

{<br />

"auth<strong>en</strong>tication" :<br />

[<br />

{<br />

"method": "LogonTicket",<br />

},<br />

{<br />

"method" : "Basic",<br />

},<br />

{<br />

"method": "Form",<br />

}<br />

],<br />

The auth<strong>en</strong>tication keyword <strong>en</strong>ables you to define the auth<strong>en</strong>tication method to use for Browser requests either<br />

at the application level or for single packages in an application. SAP HANA Ext<strong>en</strong>ded Application Services support<br />

the following logon auth<strong>en</strong>tication mechanisms:<br />

Note: You can specify multiple auth<strong>en</strong>tication methods in the application-access file.<br />

● Basic auth<strong>en</strong>tication<br />

Logon with a recognized database user name and password.<br />

● SAP logon ticket<br />

SAP logon tickets <strong>en</strong>able single sign-on across SAP boundaries; SAP logon tickets can be also be used as<br />

auth<strong>en</strong>tication for access to third-party applications.<br />

● Form-based auth<strong>en</strong>tication<br />

Redirect the logon request to a form to fill in, for example, a Web page.<br />

If you use the auth<strong>en</strong>tication in the .xsaccess file, you must specify the auth<strong>en</strong>tication method to apply, for<br />

example, basic or SAP logon ticket. If you use the auth<strong>en</strong>tication keyword in the application-access file, but do not<br />

set an auth<strong>en</strong>tication method, your .xsaccess file is a valid JSON file but is not a semantically valid .xsaccess<br />

file and will return a parsing validation error . If you do not set the auth<strong>en</strong>tication keyword, your application applies<br />

the default basic auth<strong>en</strong>tication method (user name and password) to <strong>en</strong>able access to data.<br />

54<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


Note: You can disable auth<strong>en</strong>tication checks with the null options, as follows: {"auth<strong>en</strong>tication" :<br />

null}.<br />

authorization<br />

{<br />

}<br />

"authorization":<br />

[<br />

"sap.xse.test::Execute",<br />

"sap.xse.test::Admin"<br />

]<br />

The authorization keyword in the .xsaccess file <strong>en</strong>ables you to specify which authorization level is required for<br />

access to a particular application package, for example, execute or admin on the package sap.xse.text.<br />

Note: The authorization levels you can choose from are defined in the .xsprivileges file for the<br />

package, for example, "execute" for basic privileges, or "admin" for administrative privileges on the<br />

specified package. If you use the authorization keyword in the .xsaccess file, for example, to require<br />

“execute” privileges for a specific application package, you must create a .xsprivileges file for the<br />

same application package (or a par<strong>en</strong>t package higher up the hierarchy, in which you define the “execute”<br />

privilege level declared in the .xsaccess file.<br />

rewrite_rules<br />

}<br />

{<br />

"rewrite_rules" :<br />

[{<br />

"source" : "...",<br />

"target" : "..."<br />

}]<br />

The rewrite_rules keyword <strong>en</strong>ables you hide the details of internal URL paths from external users, cli<strong>en</strong>ts, and<br />

search <strong>en</strong>gines. Any rules specified affect the local application where the .xsaccess file resides (and any<br />

subpackage, assuming the subpackages do not have their own .xsaccess files); it is not possible to define global<br />

rewrite rules. URL rewrite rules are specified as a source-target pair where the source is writt<strong>en</strong> in the JavaScript<br />

regex syntax and the target is a simple string where refer<strong>en</strong>ces to found groups can be inserted using<br />

$groupnumber.<br />

mime_mapping<br />

{<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

"mime_mapping" :<br />

[<br />

{<br />

"ext<strong>en</strong>sion":"jpg", "mimetype":"image/jpeg"<br />

}<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 55


}<br />

]<br />

The mime_mapping keyword <strong>en</strong>ables you to define how to map certain file suffixes to required MIME types. For<br />

example, you can map files with the .jpg file ext<strong>en</strong>sion to the MIME type image/jpeg.<br />

force_ssl<br />

}<br />

{<br />

"force_ssl" : true,<br />

The force_ssl keyword <strong>en</strong>ables you to refuse Browser requests that do not use secure HTTP (SSL/HTTPS) for<br />

cli<strong>en</strong>t connections. If no value is set for exposed, the default setting (false) applies and non-secured connections<br />

(HTTP) are allowed.<br />

<strong>en</strong>able_etags<br />

}<br />

{<br />

"<strong>en</strong>able_etags" : true,<br />

You can allow or prev<strong>en</strong>t the g<strong>en</strong>eration of <strong>en</strong>tity tags (etags) for static Web cont<strong>en</strong>t using the <strong>en</strong>able_etags<br />

keyword. If no value is set, the default setting (true) applies, in which case etags are g<strong>en</strong>erated. Etags are used to<br />

improve caching performance, for example, so that the same data is not res<strong>en</strong>t from the server if no change has<br />

occurred since the last time a request for the same data was made.<br />

4.4.5 Application-Access URL Rewrite Rules<br />

Rewriting URLs <strong>en</strong>ables you to hide internal URL path details from external users, cli<strong>en</strong>ts, and search <strong>en</strong>gines. You<br />

define URL rewrite rules in the application-access file (.xsaccess) for each application or for an application<br />

hierarchy (an application package and its subpackages).<br />

The rewrite rules you define in the .xsaccess file apply only to the local application to which the .xsaccess file<br />

belongs; it is not possible to define global rules to rewrite URLs. Rules are specified as a source-target pair where<br />

the source is writt<strong>en</strong> in the JavaScript regex syntax, and the target is a simple string where refer<strong>en</strong>ces to found<br />

groups can be inserted using $groupnumber.<br />

The following examples show how to use a simple set of rewrite rules to hide internal URLs from requesting cli<strong>en</strong>ts<br />

and users.<br />

The first example illustrates the package structure that exists in the repository for a giv<strong>en</strong> application; the<br />

structure includes the base package apptest, the subpackages subpackage1 and subpackage2, and several<br />

other subpackages:<br />

56<br />

sap---apptest<br />

|---logic<br />

| |---users.xsjs<br />

| |---posts.xsjs<br />

|---posts<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


| |---2011...<br />

|---subpackage1<br />

| |---image.jpg<br />

|---subpackage2<br />

| |---subsubpackage<br />

| | |---secret.txt<br />

| |---script.xsjs<br />

|---subpackage3<br />

| |---internal.file<br />

|---users<br />

| |---123...<br />

|---.xsapp<br />

|---.xsaccess<br />

|---index.html<br />

The application-access file for the package apptest (and its subpackages) includes the following rules for<br />

rewriting URLs used in cli<strong>en</strong>t requests:<br />

{<br />

}<br />

"rewrite_rules": [<br />

{<br />

"source": "/users/(\\d+)/",<br />

"target": "/logic/users.xsjs?id=$1"<br />

},<br />

{<br />

"source": "/posts/(\\d+)/(\\d+)/(\\d+)/",<br />

"target": "/logic/posts.xsjs?year=$1&month=$2&day=$3"<br />

}<br />

]<br />

Assuming we have the package structure and URL rewrite rules illustrated in the previous examples, the following<br />

valid URLs would be exposed; bold URLs require auth<strong>en</strong>tication:<br />

/sap/apptest/<br />

/sap/apptest/index.html<br />

/sap/apptest/logic/users.xsjs<br />

/sap/apptest/logic/posts.xsjs<br />

The rewriting of the following URLs would be allowed:<br />

/sap/apptest/users/123/ ==> /sap/appTest/logic/users.xsjs?id=123<br />

/sap/apptest/posts/2011/10/12/ ==> /sap/appTest/logic/posts.xsjs?<br />

year=2011&month=10&day=12<br />

4.4.6 Enabling Access to SAP HANA XS Application<br />

Packages<br />

The application-access file <strong>en</strong>ables you to specify who or what is authorized to access the cont<strong>en</strong>t exposed by the<br />

application package and what cont<strong>en</strong>t they are allowed to see.<br />

You can use a set of keywords in the application-access file .xsaccess to specify if auth<strong>en</strong>tication is required to<br />

<strong>en</strong>able access to package cont<strong>en</strong>t, which data is exposed, and if rewrite rules are in place to hide target and<br />

source URLs, for example, from users and search <strong>en</strong>gines. You can also specify what, if any, level of authorization<br />

is required for the package and whether SSL is mandatory for cli<strong>en</strong>t connections.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 57


1. Create the application access file.<br />

The application-access file must be a JSON-compliant file with the file suffix .xsaccess. Note that the<br />

application-access file does not have a name before the dot (.); it only has the suffix .xsaccess.<br />

Create a file called .xsaccess and place it in the package containing the application to which you want to<br />

<strong>en</strong>able accesss. A basic .xsaccess file must, as the very least, contain a set of curly brackets, for example,<br />

{}. Note that the .xsaccess file uses keyword-value pairs to set access rules; if a mandatory keyword-value<br />

pair is not set, th<strong>en</strong> the default value is assumed.<br />

2. Enable application access to data.<br />

You use the expose keyword to <strong>en</strong>able or disable access to cont<strong>en</strong>t at a package or subpackage level.<br />

{<br />

}<br />

"exposed" : true<br />

3. Define the application auth<strong>en</strong>tication method.<br />

You use the auth<strong>en</strong>tication keyword to define how to manage the auth<strong>en</strong>tication process for requests to<br />

access package cont<strong>en</strong>t, for example, SAP logon ticket, form-based logon, or a basic user name and<br />

password .<br />

{<br />

}<br />

"auth<strong>en</strong>tication" :<br />

[<br />

{ "method" : "Basic" }<br />

]<br />

4. Specify the application privileges.<br />

Use the authorization keyword in the .xsaccess file to specify which authorization level is required by a user<br />

for access to a particular application package. The authorization levels you can choose from are defined in<br />

the .xsprivileges file, for example, "execute" for basic privileges or "admin" for administrative privileges<br />

on the specified package.<br />

{<br />

}<br />

"authorization":<br />

[<br />

"sap.xse.test::Execute",<br />

"sap.xse.test::Admin"<br />

]<br />

5. Specify the cli<strong>en</strong>t connection security.<br />

You use the force_ssl keyword to <strong>en</strong>force the use of secure HTTP (SSL/HTTPS) for cli<strong>en</strong>t connections.<br />

Browser requests that do not use SSL/HTTPS are refused and the 403 Forbidd<strong>en</strong> page is displayed.<br />

{<br />

}<br />

Note: You need to <strong>en</strong>sure the SAP Web Dispatcher is configured to accept and process HTTPS<br />

requests.<br />

"force_ssl" : true<br />

6. Define the MIME mapping to be used for specific file ext<strong>en</strong>sions. (Optional)<br />

58<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


You use the mime_mapping keyword to map specific file ext<strong>en</strong>sions (for example, .jpg or .png) to a<br />

particular Multipurpose Internet Mail Ext<strong>en</strong>sions (MIME) type.<br />

{<br />

}<br />

"mime_mapping" :<br />

[<br />

{<br />

"ext<strong>en</strong>sion":"jpg",<br />

"mimetype":"image/jpeg"<br />

}<br />

]<br />

7. Prev<strong>en</strong>t the g<strong>en</strong>eration of <strong>en</strong>tity tags. (Optional)<br />

You use the <strong>en</strong>able_etags keyword to prev<strong>en</strong>t the g<strong>en</strong>eration of <strong>en</strong>tity tags (etags) for static Web cont<strong>en</strong>t.<br />

{<br />

}<br />

"<strong>en</strong>able_etags":false<br />

8. Specify which, if any, URLs must be rewritt<strong>en</strong>. (Optional)<br />

You use the rewrite_rules keyword to hide details of internal URL paths from external users, cli<strong>en</strong>ts, and<br />

search <strong>en</strong>gines.<br />

{<br />

}<br />

"rewrite_rules" :<br />

[<br />

{<br />

"source" : "...",<br />

"target" : "..."<br />

}<br />

]<br />

9. Save the .xsaccess file and place it in the package with which you want to associate the rules you have<br />

defined.<br />

10. Commit the file to the repository and activate it.<br />

In the Project Navigator view, right click the object you want to activate and choose Team > Activate in<br />

the popup m<strong>en</strong>u.<br />

Related Links<br />

Application-Access File Keyword Options [page 53]<br />

The application-access (.xsaccess) file <strong>en</strong>ables you to specify whether or not to expose package cont<strong>en</strong>t,<br />

which auth<strong>en</strong>tication method is used to grant access, and what cont<strong>en</strong>t is visible.<br />

4.4.7 The Application-Privileges File<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), the application-privileges (.xssprivileges) file<br />

can be used to create or define the authorization privileges required for access to an SAP HANA XS application,<br />

for example, to start the application or to perform administrative actions on an application. These privileges can<br />

be checked by an application at runtime.<br />

The application-privileges file has only the file ext<strong>en</strong>sion .xsprivileges; it does not have a name and is<br />

formatted according to JSON rules. Multiple .xsprivileges files are allowed, but only at differ<strong>en</strong>t levels in the<br />

package hierarchy; you cannot place two .xsprivileges files in the same application package. The package<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 59


privileges defined in a .xsprivileges file are bound to the package to which the .xsprivileges file belongs<br />

and can only be used in this package and its subpackages.<br />

Inside the .xsprivileges file, a privilege is defined by specifying an <strong>en</strong>try name with an optional description.<br />

This <strong>en</strong>try name is th<strong>en</strong> automatically prefixed with the package name to form the unique privilege name, for<br />

example, sap.<strong>hana</strong>::Execute.<br />

As an application privilege is created during activation of an .xsprivileges file, the only user who has the<br />

privilege by default is the _SYS_REPO user. To grant or revoke the privilege to (or from) other users you must use<br />

the GRANT_APPLICATION_PRIVILEGE or REVOKE_APPLICATION_PRIVILEGE procedure in the _SYS_REPO<br />

schema.<br />

Note: The .xsprivileges file lists the authorization levels that are available for access to an application<br />

package; the .xsaccess file defines which authorization level is assigned to which application package.<br />

The SAP HANA XS Application-Privileges File<br />

The following example shows the composition and structure of a basic SAP HANA XS application-<br />

privileges file.<br />

{<br />

"privileges" :<br />

[<br />

{ "name" : "Execute", "description" : "Basic execution<br />

privilege" },<br />

{ "name" : "Admin", "description" : "Administration<br />

privilege" },<br />

]<br />

}<br />

In the example above, if the application-privileges file is located in the application package<br />

sap.<strong>hana</strong>.xse, th<strong>en</strong> the following privileges are created:<br />

● sap.<strong>hana</strong>.xse::Execute<br />

● sap.<strong>hana</strong>.xse::Admin<br />

Note: The privileges defined apply to the package where the .xsprivileges file is located as well<br />

as any packages further down the package hierarchy unless an additional .xsprivileges file is<br />

pres<strong>en</strong>t, for example, in a subpackage. The privileges do not apply to packages that are not in the<br />

specified package path, for example, sap.<strong>hana</strong>.app1.<br />

For the example above, the following Grant procedure would be used:<br />

call<br />

"_SYS_REPO"."GRANT_APPLICATION_PRIVILEGE"('"sap.<strong>hana</strong>.xse::Execute"',<br />

'')<br />

4.4.8 Create an SAP HANA XS Application Privileges File<br />

The application-privileges (.xssprivileges) file can be used to grant authorization levels for an application, for<br />

example, to start the application or perform administrative actions on an application.<br />

60<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


1. If you have not already done so, create a root package for your new application, for example,<br />

MyApplication.<br />

2. If you have not already done so, create an application descriptor for your new application and place it in the<br />

root package you created in the previous step.<br />

The application descriptor is the core file that you use to describe an application's availability within SAP<br />

HANA Ext<strong>en</strong>ded Application Services. The application-descriptor file has no cont<strong>en</strong>ts and no name; it only has<br />

the file ext<strong>en</strong>sion .xsapp.<br />

Note: For backward compatibility, cont<strong>en</strong>t is allowed in the .xsapp file but ignored.<br />

3. If you have not already done so, create an application-access file for your new application and place it in the<br />

package to which you want to grant access.<br />

The application-access file does not have a name; it only has the file ext<strong>en</strong>sion .xsaccess. The cont<strong>en</strong>ts of<br />

the .xsaccess file must be formatted according to JavaScript Object Notation (JSON) rules and associated<br />

with the package it belongs to. The rules defined in the .xsaccess file apply to the package it resides in as<br />

well as any subpackages lower in the package hierarchy.<br />

Note:<br />

Use the authorization keyword in the .xsaccess file to specify which authorization level is to be<br />

granted to a particular application package. The authorization levels you can choose from are defined<br />

in the application-privileges file (.xsprivileges), for example, "execute" for basic privileges, or<br />

"admin" for administrative privileges on the specified package.<br />

4. Create the application-privileges file.<br />

The application-privileges file does not have a name; it only has the file ext<strong>en</strong>sion .xsprivileges. The<br />

cont<strong>en</strong>ts of the .xsprivileges file must be formatted according to JavaScript Object Notation (JSON)<br />

rules. Multiple .xsprivileges files are allowed, but only at differ<strong>en</strong>t levels in the package hierarchy; you<br />

cannot place two .privileges files in the same application package. The privileges defined in<br />

a .xsprivileges file are bound to the package to which the file belongs and can only be applied to this<br />

package and its subpackages.<br />

5. Define the application privileges.<br />

Inside the .xsprivileges file, a privilege is defined for an application package by specifying an <strong>en</strong>try name<br />

with an optional description. This <strong>en</strong>try name is th<strong>en</strong> automatically prefixed with the package name to form<br />

the unique privilege name, for example, sap.<strong>hana</strong>::Execute. The unique privilege name can be used in<br />

multiple .xsprivileges files in differ<strong>en</strong>t packages, since they are all differ<strong>en</strong>t privileges.<br />

Note: The .xsprivileges file lists the authorization levels available for granting to an application<br />

package; the .xsaccess file defines which authorization level is assigned to which application<br />

package.<br />

{<br />

"privileges" :<br />

[<br />

{ "name" : "Execute", "description" : "Basic execution<br />

privilege" },<br />

{ "name" : "Admin", "description" : "Adminstration<br />

privilege" },<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 61


}<br />

]<br />

6. Save and activate your changes and additions.<br />

4.5 Tutorial: My First SAP HANA Application<br />

This tutorial shows you how SAP HANA <strong>dev</strong>elopm<strong>en</strong>t is done in the SAP HANA studio, including setting up a<br />

project, and <strong>dev</strong>eloping a simple JavaScript file to extract data from the database.<br />

Though extremely simple, the tutorial shows the <strong>dev</strong>elopm<strong>en</strong>t process for programming all types of applications.<br />

The project creates server-side JavaScript code that retrieves data by executing SQL in the database, and th<strong>en</strong><br />

returns the data to the cli<strong>en</strong>t, which in this case is a browser. The project can be viewed as adhering to the model-<br />

view-controller architecture:<br />

● Model: You have (dummy) data in the database, which we can extract via SQL.<br />

● Controller: You have JavaScript code that controls the extraction of the data and delivers it to the view.<br />

● View: You have a simple browser that calls the JavaScript code and simply displays the data.<br />

4.5.1 Op<strong>en</strong> the Developm<strong>en</strong>t Perspective<br />

Before you do anything, you have to start the SAP HANA studio and op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t<br />

perspective.<br />

1. Op<strong>en</strong> the SAP HANA studio. The first scre<strong>en</strong> you see is the Welcome scre<strong>en</strong>, with quick links to the main SAP<br />

HANA perspectives and to the docum<strong>en</strong>tation.<br />

62<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


2. Select Op<strong>en</strong> Developm<strong>en</strong>t.<br />

The default SAP HANA Developm<strong>en</strong>t perspective contains three views on the left for navigating SAP HANA<br />

and the repository, which holds the objects that you will create. In addition, the editor area is on the right,<br />

where you will build your objects.<br />

Related Links<br />

SAP HANA Developm<strong>en</strong>t Perspective [page 25]<br />

4.5.2 Add a System<br />

You need to add a connection to the <strong>dev</strong>elopm<strong>en</strong>t SAP HANA system you will be working with.<br />

1. In the Navigator view, right-click anywhere in the view and select Add System.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 63


2. Enter the following fields for the SAP HANA system:<br />

64<br />

○ Server name<br />

○ Instance number on that server<br />

○ A display name for this system. Wh<strong>en</strong> you start working with a lot of systems, you will want to have a way<br />

to label the systems in the SAP HANA studio. Enter Developm<strong>en</strong>t System.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


3. Select Next.<br />

4. Enter a user name and password for the connection, and select Finish.<br />

After adding the system, you will see the system in the Navigator view.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 65


4.5.3 Add a Workspace<br />

After you add a system, you need to specify where on your workstation you will be saving <strong>dev</strong>elopm<strong>en</strong>t files while<br />

working with this system.<br />

1. In the SAP HANA Repositories view, click in the upper-right of the view.<br />

2. Provide the following:<br />

○ SAP HANA system, which is the same system you just created.<br />

○ Workspace name, which can be anything you like. For this tutorial, <strong>en</strong>ter DevWS.<br />

A folder with this name is created below the workspace root.<br />

○ Workspace root, which can be anywhere on your workstation. For this tutorial, create a folder at C:<br />

3. Click Finish.<br />

66<br />

\SAPHANAworkspaces and make this the root.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


In the SAP HANA Repositories view, you will see your workspace, which <strong>en</strong>ables you to browse the repository of<br />

the system tied to this workspace. You will see the repository's packages, displayed as folders.<br />

At the same time, a folder will be added to your file system to hold all your <strong>dev</strong>elopm<strong>en</strong>t files.<br />

4.5.4 Add a Project<br />

Now that you've set up your <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t for your SAP HANA system, you can add an Eclipse<br />

project to contain all the <strong>dev</strong>elopm<strong>en</strong>t objects you want to create.<br />

There are a variety of project types for differ<strong>en</strong>t types of <strong>dev</strong>elopm<strong>en</strong>t objects. G<strong>en</strong>erally, these projects types<br />

import necessary libraries for working with specific types of <strong>dev</strong>elopm<strong>en</strong>t objects. Here, you will create an XS<br />

Project.<br />

1. From the m<strong>en</strong>u, select File New Project .<br />

2. Under SAP HANA Developm<strong>en</strong>t, select XS Project, and select Next.<br />

3. Enter the following for the project:<br />

○ Name: Enter mycompany.myorg.testing.<br />

Since Eclipse project names must be unique within the same Eclipse workspace, a good conv<strong>en</strong>tion is to<br />

use the fully qualified package name as the project name.<br />

○ Project Location: You can keep this as the default Eclipse workspace.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 67


4. Select Finish.<br />

Now, in the Project Explorer view, you have a project that is ready to be shared, that is, associated with your<br />

workspace.<br />

4.5.5 Share Your Project<br />

After creating a project, you must associate it with a workspace, which <strong>en</strong>ables the project files to be saved to the<br />

repository of your <strong>dev</strong>elopm<strong>en</strong>t SAP HANA system.<br />

1. In the Project Explorer view, right-click on the project, and select Team Share Project .<br />

68<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


Since you only have one workspace, the wizard selects it for you. If you had several workspaces, you would<br />

choose with which one you wanted to share your project.<br />

The dialog also shows the Curr<strong>en</strong>t project location (the curr<strong>en</strong>t location of your project, in the Eclipse<br />

workspace), and the New project location (where your project will be copied so it can be associated with the<br />

repository workspace).<br />

Also, since Add project folder as subpackage is checked, subpackages will be created based on the name of<br />

your project.<br />

2. Click Finish.<br />

Now your project appears in the Project Explorer view associated with your workspace.<br />

The .project file is shown with an asterisk , which indicates that the file has changed but has yet to be<br />

committed, or saved, to the repository.<br />

3. Right-click on the project, and select Team Commit . This adds your project and its files to the<br />

repository, though only you can see them. The .project file is now displayed with a diamond, , indicating<br />

that the latest version on your workstation has be<strong>en</strong> committed.<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 69


In addition, the SAP HANA Repositories view shows that a new hierarchy of packages has be<strong>en</strong> created based<br />

on the name of your project, mycompany.myorg.testing.<br />

4.5.6 Write Server-Side JavaScript<br />

Now let's write some code. As a first step, to make sure everything is working OK, you will simply output Hello,<br />

World!.<br />

You will have to create three files:<br />

● .xsjs: This contains your code.<br />

● .xsapp: This indicates that everything in your package can be exposed via HTTP. You still need to explicitly<br />

expose the cont<strong>en</strong>t and assign access controls.<br />

● .xsaccess: Exposes your cont<strong>en</strong>t, meaning it can be accessed via HTTP, and assigned access controls.<br />

1. Right-click your project, and select New Other .<br />

2. Select SAP HANA Developm<strong>en</strong>t XS JavaScript Source File .<br />

3. In File name, call your JavaScript file MyFirstSourceFile.xsjs, and select Finish.<br />

The file, which is blank, op<strong>en</strong>s in the JavaScript editor.<br />

4. In the MyFirstSourceFile.xsjs file, <strong>en</strong>ter the following code:<br />

$.response.cont<strong>en</strong>tType = "text/html";<br />

$.response.setBody( "Hello, World !");<br />

This uses the SAP HANA XS JavaScript API's response object to write out HTML. By typing $. you have<br />

access to the API's objects.<br />

5. Add a blank file called .xsapp (no name, just a file ext<strong>en</strong>sion) by right-clicking to the root of your project.<br />

70<br />

More on this later.<br />

To add a file, right-click the project and select New File , <strong>en</strong>ter a file name, and select Finish.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


6. Add a file called .xsaccess (no name, just a file ext<strong>en</strong>sion), and copy the following code:<br />

{<br />

}<br />

"exposed" : true,<br />

"auth<strong>en</strong>tication" :<br />

[<br />

{ "method" : "Basic" }<br />

]<br />

This code exposes the cont<strong>en</strong>ts via HTTP, and requires you to log in with your SAP HANA cred<strong>en</strong>tials to<br />

access the file.<br />

7. Right-click on the project, and select Team Commit . This adds your four new files<br />

(.xsjs, .xsapp, .xsaccess and .project) to the repository, though only you can see the files and no one<br />

can run them.<br />

8. Right-click on the project, and select Team Activate . This publishes your work and you can now test it.<br />

To access your JavaScript code, op<strong>en</strong> a browser and <strong>en</strong>ter the URL:<br />

http://myServer:8000/mycompany/myorg/testing/MyFirstSourceFile.xsjs<br />

Note:<br />

● Change the server name to your server.<br />

● The port is 80 plus two digits for your instance. If your instance is 00, th<strong>en</strong> the port is 8000.<br />

You should get the following:<br />

SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 71


After logging in with your SAP HANA user name and password, you should get the following:<br />

4.5.7 Retrieve Data<br />

To make things more interesting, let's make a call to the database via the JavaScript and th<strong>en</strong> display the results.<br />

You will be using the SQL statem<strong>en</strong>t:<br />

select * from DUMMY<br />

This is test SQL to check connectivity, and returns one row with one field called DUMMY, whose value is X.<br />

1. In MyFirstSourceFile.xsjs, delete or comm<strong>en</strong>t out all your existing code.<br />

2. Add the following code:<br />

$.response.cont<strong>en</strong>tType = "text/html";<br />

var output = "Hello, World !";<br />

var conn = $.db.getConnection();<br />

var pstmt = conn.prepareStatem<strong>en</strong>t( "select * from DUMMY" );<br />

var rs = pstmt.executeQuery();<br />

if (!rs.next()) {<br />

$.response.setBody( "Failed to retrieve data" );<br />

$.response.status = $.net.http.INTERNAL_SERVER_ERROR;<br />

} else {<br />

output = output + "This is the response from my SQL: " +<br />

rs.getString(1);<br />

}<br />

rs.close();<br />

pstmt.close();<br />

conn.close();<br />

$.response.setBody(output);<br />

3. Save the file.<br />

4. Commit the file by right-clicking the file and selecting Team Commit .<br />

5. Activate the file by right-clicking the file and selecting Team Activate .<br />

In your browser, refresh the page. You should get the following:<br />

72<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up Your Application


SAP HANA Developer Guide<br />

Setting up Your Application<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 73


5 Setting up the Persist<strong>en</strong>ce Model<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), the persist<strong>en</strong>ce model defines the schema, tables,<br />

and views that specify what data to make accessible and how. The persist<strong>en</strong>ce model is mapped to the<br />

consumption model that is exposed to cli<strong>en</strong>t applications and users, so that data can be analyzed and displayed.<br />

SAP HANA XS <strong>en</strong>ables you to create database schema, tables, views, and sequ<strong>en</strong>ces as design-time files in the<br />

repository. Repository files can be read by applications that you <strong>dev</strong>elop.<br />

Note: All repository files including your view definition can be transported (along with tables, schema, and<br />

sequ<strong>en</strong>ces) to other SAP HANA systems, for example, in a delivery unit. A delivery unit is the medium SAP<br />

HANA provides to <strong>en</strong>able you to assemble all your application-related repository artifacts together into an<br />

archive that can be easily exported to other systems.<br />

You can also set up data-provisioning rules and save them as design-time objects so that they can be included in<br />

the delivery unit that you transport betwe<strong>en</strong> systems.<br />

As part of the process of setting up the basic persist<strong>en</strong>ce model for SAP HANA XS, you perform the following<br />

tasks:<br />

● Create a schema.<br />

Define a design-time schema and maintain the schema definition in the repository. The transportable schema<br />

has the file ext<strong>en</strong>sion .hdbschema, for example, MYSCHEMA.hdbschema<br />

● Create a table.<br />

Define a design-time table and maintain the table definition in the repository. The transportable table has the<br />

file ext<strong>en</strong>sion .hdbtable, for example, MYTABLE.hdbtable<br />

● Create a view.<br />

Define a design-time view and maintain the view definition in the repository. The transportable view has the<br />

file ext<strong>en</strong>sion .hdbview, for example, MYVIEW.hdbview<br />

● Create a sequ<strong>en</strong>ce.<br />

Define a design-time sequ<strong>en</strong>ce and maintain the sequ<strong>en</strong>ce definition in the repository. The transportable<br />

sequ<strong>en</strong>ce has the file ext<strong>en</strong>sion .hdbsequ<strong>en</strong>ce, for example, MYSEQUENCE.hdbsequ<strong>en</strong>ce<br />

● Import table cont<strong>en</strong>t<br />

74<br />

Define data-provisioning rules that <strong>en</strong>able you to import data from comma-separated values (CSV) files into<br />

SAP HANA tables using the SAP HANA XS table-import feature. The complete configuration can be included<br />

in a delivery unit and transported betwe<strong>en</strong> SAP HANA systems.<br />

Note: On activation of a repository file, the file suffix, for example, .hdbview, .hdbschema,<br />

or .hdbtable, is used to determine which runtime plugin to call during the activation process. The plugin<br />

reads the repository file selected for activation, for example, a table, sees the object descriptions in the<br />

file, and creates the appropriate runtime object.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model


5.1 Schema<br />

Relational databases contain a catalog that describes the various elem<strong>en</strong>ts in the system. The catalog divides the<br />

database into sub-databases known as schema. A database schema <strong>en</strong>ables you to logically group together<br />

objects such as tables, views, and stored procedures. Without a defined schema, you cannot write to the catalog.<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) <strong>en</strong>ables you to create a database schema as a<br />

transportable design-time file in the repository. Repository files can be read by applications that you <strong>dev</strong>elop.<br />

If your application refers to the repository (design-time) version of a schema rather than the runtime version in<br />

the catalog, for example, by using the explicit path to the repository file (with suffix), any changes to the<br />

repository version of the file are visible as soon as they are committed to the repository. There is no need to wait<br />

for the repository to activate a runtime version of the schema.<br />

If you want to define a transportable schema using the design-time hdbschema specifications, use the<br />

configuration schema illustrated in the following example:<br />

string schema_name<br />

The following example shows the cont<strong>en</strong>ts of a valid transportable schema-definition file for a schema called<br />

MYSCHEMA:<br />

schema_name=”MYSCHEMA”;<br />

The schema is stored in the repository with the schema name MYSCHEMA as the file name and the<br />

suffix .hdbschema, for example, MYSCHEMA.hdbschema.<br />

Schema Activation<br />

If you want to create a schema definition as a design-time object, you must create the schema as a flat file. You<br />

save the file containing the schema definition with the suffix .hdbschema in the appropriate package for your<br />

application in the SAP HANA repository. You can activate the design-time objects at any point in time.<br />

Note: On activation of a repository file, the file suffix, for example, .hdbschema, is used to determine<br />

which runtime plugin to call during the activation process. The plug-in reads the repository file selected for<br />

activation, parses the object descriptions in the file, and creates the appropriate runtime objects.<br />

If you activate a schema-definition object in SAP HANA, the activation process checks if a schema with the same<br />

name already exists in the SAP HANA repository. If a schema with the specified name does not exist, the<br />

repository creates a schema with the specified name and makes _SYS_REPO the owner of the new schema.<br />

Note: The schema cannot be dropped ev<strong>en</strong> if the deletion of a schema object is activated.<br />

If you define a schema in SAP HANA XS, note the following important points regarding the schema name:<br />

● Name mapping<br />

The schema name must be id<strong>en</strong>tical to the name of the corresponding repository object.<br />

● Naming conv<strong>en</strong>tions<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 75


The schema name must adhere to the SAP HANA rules for database id<strong>en</strong>tifiers.<br />

● Name usage<br />

The Data Definition Language (DDL) r<strong>en</strong>dered by the repository contains the schema name as a delimited<br />

id<strong>en</strong>tifier.<br />

5.2 Creating Schemas<br />

A schema defines the container that holds database objects such as tables, views, and stored procedures.<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) <strong>en</strong>ables you to create a database schema as a design-<br />

time file in the repository.<br />

To create a schema definition file in the repository, perform the following steps:<br />

1. Start the SAP HANA studio.<br />

2. Op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective.<br />

3. Op<strong>en</strong> the Project Explorer view.<br />

4. Create the schema definition file.<br />

Browse to the folder in your project workspace where you want to create the new schema-definition file and<br />

perform the following tasks:<br />

a) Right-click the folder where you want to save the schema-definition file and choose New in the contexts<strong>en</strong>sitive<br />

popup m<strong>en</strong>u.<br />

b) Enter the name of the schema in the File Name box and add the file suffix .hdbschema, for example,<br />

MYSCHEMA.hdbschema.<br />

c) Choose Finish to save the new schema in the repository.<br />

5. Define the schema name.<br />

To edit the schema file, in the Project Explorer view double-click the schema file you created in the previous<br />

step, for example, MYSCHEMA.hdbschema, and add the schema-definition code to the file:<br />

Note: The following code example is provided for illustration purposes only.<br />

schema_name=”MYSCHEMA”<br />

6. Save the schema file.<br />

7. Commit the changes to the repository.<br />

a) Locate and right-click the new schema file in the Project Explorer view.<br />

b) In the context-s<strong>en</strong>sitive pop-up m<strong>en</strong>u, choose Team Commit .<br />

5.3 Tables<br />

In the SAP HANA database, as in other relational databases, a table is a set of data elem<strong>en</strong>ts that are organized<br />

using columns and rows. A database table has a specified number of columns, defined at the time of table<br />

76<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model


creation, but can have any number of rows. Database tables also typically have meta-data associated with them;<br />

the meta-data might include constraints on the table or on the values within particular columns.<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) <strong>en</strong>ables you to create a database table as a designtime<br />

file in the repository. All repository files including your table definition can be transported to other SAP HANA<br />

systems, for example, in a delivery unit.<br />

Note: A delivery unit is the medium SAP HANA provides to <strong>en</strong>able you to assemble all your applicationrelated<br />

repository artifacts together into an archive that can be easily exported to other systems.<br />

If your application is configured to use the design-time version of a database table in the repository rather than<br />

the runtime version in the catalog, any changes to the repository version of the table are visible as soon as they<br />

are committed to the repository. There is no need to wait for the repository to activate a runtime version of the<br />

table.<br />

The following code illustrates a simple example of a design-time table definition:<br />

table.schemaName = "MYSCHEMA";<br />

table.tableType = COLUMNSTORE;<br />

table.columns = [<br />

{name = "Col1"; sqlType = VARCHAR; nullable = false; l<strong>en</strong>gth = 20;<br />

comm<strong>en</strong>t = "dummy comm<strong>en</strong>t";},<br />

{name = "Col2"; sqlType = INTEGER; nullable = false;},<br />

{name = "Col3"; sqlType = NVARCHAR; nullable = true; l<strong>en</strong>gth = 20;<br />

defaultValue = "Defaultvalue";},<br />

{name = "Col4"; sqlType = DECIMAL; nullable = false; precision = 2;<br />

scale = 3;}];<br />

table.indexes = [<br />

{name = "MYINDEX1"; unique = true; indexColumns = ["Col2"];},<br />

{name = "MYINDEX2"; unique = true; indexColumns = ["Col1", "Col4"];}];<br />

table.primaryKey.pkcolumns = ["Col1", "Col2"];<br />

If you want to create a database table as a repository file, you must create the table as a flat file and save the file<br />

containing the table dim<strong>en</strong>sions with the suffix .hdbtable, for example, MYTABLE.hdbtable. The new file is<br />

located in the package hierarchy you establish in the SAP HANA repository. You can activate the repository files at<br />

any point in time.<br />

Note: On activation of a repository file, the file suffix, for example, .hdbtable, is used to determine which<br />

runtime plugin to call during the activation process. The plugin reads the repository file selected for<br />

activation, in this case a table, parses the object descriptions in the file, and creates the appropriate<br />

runtime objects.<br />

5.4 Creating Tables<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) <strong>en</strong>ables you to create a database table as a designtime<br />

file in the repository.<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) <strong>en</strong>ables you to create a database table as a design-<br />

time file in the repository<br />

To create a table file in the repository, perform the following steps:<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 77


1. Start the SAP HANA studio.<br />

2. Op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective.<br />

3. Op<strong>en</strong> the Project Explorer view.<br />

4. Create the table file.<br />

Browse to the folder in your project workspace where you want to create the new table file and perform the<br />

following tasks:<br />

a) Right-click the folder where you want to save the table file and choose New in the context-s<strong>en</strong>sitive popup<br />

m<strong>en</strong>u.<br />

b) Enter the name of the table in the File Name box and add the file suffix .hdbtable, for example,<br />

MYTABLE.hdbtable.<br />

c) Choose Finish to save the new table in the repository.<br />

5. Define the table.<br />

To edit the table file, in the Project Explorer view double-click the table file you created in the previous step, for<br />

example, MYTABLE.hdbtable, and add the table-definition code to the file:<br />

Note: The following code example is provided for illustration purposes only.<br />

table.schemaName = "MYSCHEMA";<br />

table.tableType = COLUMNSTORE;<br />

table.columns = [<br />

{name = "Col1"; sqlType = VARCHAR; nullable = false; l<strong>en</strong>gth = 20;<br />

comm<strong>en</strong>t = "dummy comm<strong>en</strong>t";},<br />

{name = "Col2"; sqlType = INTEGER; nullable = false;},<br />

{name = "Col3"; sqlType = NVARCHAR; nullable = true; l<strong>en</strong>gth = 20;<br />

defaultValue = "Defaultvalue";},<br />

{name = "Col4"; sqlType = DECIMAL; nullable = false; precision = 2;<br />

scale = 3;}];<br />

table.indexes = [<br />

{name = "MYINDEX1"; unique = true; indexColumns = ["Col2"];},<br />

{name = "MYINDEX2"; unique = true; indexColumns = ["Col1",<br />

"Col4"];}];<br />

table.primaryKey.pkcolumns = ["Col1", "Col2"];<br />

6. Save the table file.<br />

7. Commit the changes to the repository.<br />

a) Locate and right-click the new table file in the Project Explorer view.<br />

b) In the context-s<strong>en</strong>sitive pop-up m<strong>en</strong>u, choose Team Commit .<br />

5.5 Sequ<strong>en</strong>ces<br />

A sequ<strong>en</strong>ce is a database object that g<strong>en</strong>erates a serial list of unique numbers. You can use sequ<strong>en</strong>ce definitions<br />

in mappings to g<strong>en</strong>erate unique numbers while transforming and moving data to your target system.<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) <strong>en</strong>ables you to create a database sequ<strong>en</strong>ce as a<br />

transportable design-time file in the repository. Repository files can be read by applications that you <strong>dev</strong>elop.<br />

You can use database sequ<strong>en</strong>ces to perform the following operations:<br />

78<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model


● G<strong>en</strong>erate unique, primary key values<br />

● Coordinate keys across multiple rows or tables<br />

If you want to define a transportable sequ<strong>en</strong>ce using the design-time sequ<strong>en</strong>ce specifications, use the<br />

configuration schema illustrated in the following example.<br />

string schema;<br />

int32 increm<strong>en</strong>t_by(default=1);<br />

int32 start_with(default=-1);<br />

optional int32 maxvalue;<br />

bool nomaxvalue(default=false);<br />

optional int32 minvalue;<br />

bool nominvalue(default=false);<br />

optional bool cycles;<br />

optional string reset_by;<br />

bool public(default=false);<br />

optional string dep<strong>en</strong>ds_on_table;<br />

optional string dep<strong>en</strong>ds_on_view;<br />

The following example shows the cont<strong>en</strong>ts of a valid sequ<strong>en</strong>ce-definition file for a sequ<strong>en</strong>ce called MYSEQUENCE.<br />

schema= "TEST_DUMMY";<br />

start_with= 10;<br />

maxvalue= 30;<br />

nomaxvalue=false;<br />

minvalue= 1;<br />

nominvalue=true;<br />

cycles= false;<br />

reset_by= "SELECT \"Col2\" FROM \"TEST_DUMMY\".<br />

\"com.sap.test.tables::MY_TABLE\" WHERE \"Col2\"='12'";<br />

dep<strong>en</strong>ds_on_table= "com.sap.test.tables::MY_TABLE";<br />

The sequ<strong>en</strong>ce is stored in the repository with the suffix hdbsequ<strong>en</strong>ce, for example, MYSEQUENCE.hdbsequ<strong>en</strong>ce.<br />

If you activate a sequ<strong>en</strong>ce-definition object in SAP HANA XS, the activation process checks if a sequ<strong>en</strong>ce with the<br />

same name already exists in the SAP HANA repository. If a sequ<strong>en</strong>ce with the specified name does not exist, the<br />

repository creates a sequ<strong>en</strong>ce with the specified name and makes _SYS_REPO the owner of the new sequ<strong>en</strong>ce.<br />

Note: The sequ<strong>en</strong>ce cannot be dropped ev<strong>en</strong> if the deletion of a sequ<strong>en</strong>ce object is activated.<br />

5.6 Creating Sequ<strong>en</strong>ces<br />

A database sequ<strong>en</strong>ce g<strong>en</strong>erates a serial list of unique numbers that you can use while transforming and moving<br />

data to betwe<strong>en</strong> systems.<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) <strong>en</strong>ables you to create a database sequ<strong>en</strong>ce as a<br />

design-time file in the repository.<br />

To create a sequ<strong>en</strong>ce definition file in the repository, perform the following steps:<br />

1. Start the SAP HANA studio.<br />

2. Op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 79


3. Op<strong>en</strong> the Project Explorer view.<br />

4. Create the sequ<strong>en</strong>ce-definition file.<br />

Browse to the folder in your project workspace where you want to create the new sequ<strong>en</strong>ce-definition file and<br />

perform the following tasks:<br />

a) Right-click the folder where you want to save the sequ<strong>en</strong>ce-definition file and choose New in the contexts<strong>en</strong>sitive<br />

popup m<strong>en</strong>u.<br />

b) Enter the name of the sequ<strong>en</strong>ce in the File Name box and add the file suffix .hdbsequ<strong>en</strong>ce, for example,<br />

MYSEQUENCE.hdbsequ<strong>en</strong>ce.<br />

c) Choose Finish to save the new sequ<strong>en</strong>ce in the repository.<br />

5. Define the sequ<strong>en</strong>ce properties.<br />

To edit the sequ<strong>en</strong>ce file, in the Project Explorer view double-click the sequ<strong>en</strong>ce file you created in the<br />

previous step, for example, MYSEQUENCE.hdbsequ<strong>en</strong>ce, and add the sequ<strong>en</strong>ce code to the file:<br />

schema= "TEST_DUMMY";<br />

start_with= 10;<br />

maxvalue= 30;<br />

nomaxvalue=false;<br />

minvalue= 1;<br />

nominvalue=true;<br />

cycles= false;<br />

reset_by= "SELECT \"Col2\" FROM \"TEST_DUMMY\".<br />

\"com.sap.test.tables::MY_TABLE\" WHERE \"Col2\"='12'";<br />

dep<strong>en</strong>ds_on_table= "com.sap.test.tables::MY_TABLE";<br />

6. Save the sequ<strong>en</strong>ce file.<br />

7. Commit the changes to the repository.<br />

a) Locate and right-click the new sequ<strong>en</strong>ce file in the Project Explorer view.<br />

b) In the context-s<strong>en</strong>sitive pop-up m<strong>en</strong>u, choose Team Commit .<br />

5.7 SQL Views<br />

In SQL, a view is a virtual table based on the dynamic results returned in response to an SQL statem<strong>en</strong>t. Every<br />

time a user queries an SQL view, the database uses the view's SQL statem<strong>en</strong>t to recreate the data specified in the<br />

SQL view. The data displayed in an SQL view can be extracted from one or more database tables.<br />

An SQL view contains rows and columns, just like a real database table; the fields in an SQL view are fields from<br />

one or more real tables in the database. You can add SQL functions, for example, WHERE or JOIN statem<strong>en</strong>ts, to a<br />

view and pres<strong>en</strong>t the resulting data as if it were coming from one, single table.<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) <strong>en</strong>ables you to create a database view as a design-time<br />

file in the repository. Repository files can be read by applications that you <strong>dev</strong>elop. In addition, all repository files<br />

including your view definition can be transported to other SAP HANA systems, for example, in a delivery unit.<br />

If your application refers to the design-time version of a view from the repository rather than the runtime version<br />

in the catalog, for example, by using the explicit path to the repository file (with suffix), any changes to the<br />

repository version of the file are visible as soon as they are committed to the repository. There is no need to wait<br />

for the repository to activate a runtime version of the view.<br />

80<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model


To define a transportable view using the design-time view specifications, use the configuration schema illustrated<br />

in the following example:<br />

string schema;<br />

string query;<br />

bool public(default=true);<br />

optional list dep<strong>en</strong>ds_on_table;<br />

optional list dep<strong>en</strong>ds_on_view;<br />

The following example shows the cont<strong>en</strong>ts of a valid transportable view-definition file for a view called MYVIEW:<br />

schema="TEST_DUMMY";<br />

query="SELECT * FROM \"TEST_DUMMY\".\"com.sap.test.tables::<br />

02_HDB_DEPARTMENT_VIEW\"";<br />

dep<strong>en</strong>ds_on_view=["com.sap.test.tables::02_HDB_DEPARTMENT_VIEW"];<br />

If you want to create a view definition as a design-time object, you must create the view as a flat file and save the<br />

file containing the view definition with the suffix .hdbview, for example, MYVIEW.hdbview in the appropriate<br />

package in the package hierarchy established for your application in the SAP HANA repository. You can activate<br />

the design-time object at any point in time.<br />

Note: On activation of a repository file, the file suffix, for example, .hdbview, is used to determine which<br />

runtime plugin to call during the activation process. The plug-in reads the repository file selected for<br />

activation, parses the object descriptions in the file, and creates the appropriate runtime objects.<br />

5.8 Creating SQL Views<br />

A view is a virtual table based on the dynamic results returned in response to an SQL statem<strong>en</strong>t. SAP HANA<br />

Ext<strong>en</strong>ded Application Services (SAP HANA XS) <strong>en</strong>ables you to create a database view as a design-time file in the<br />

repository.<br />

To create a view-definition file in the repository, perform the following steps:<br />

1. Start the SAP HANA studio.<br />

2. Op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective.<br />

3. Op<strong>en</strong> the Project Explorer view.<br />

4. Create the view-definition file.<br />

Browse to the folder in your project workspace where you want to create the new view-definition file and<br />

perform the following tasks:<br />

a) Right-click the folder where you want to save the view-definition file and choose New in the contexts<strong>en</strong>sitive<br />

popup m<strong>en</strong>u.<br />

b) Enter the name of the view-definition file in the File Name box and add the file suffix .hdbview, for<br />

example, MYVIEW.hdbview.<br />

c) Choose Finish to save the new view-definition file in the repository.<br />

5. Define the view.<br />

To edit the view-definition file, in the Project Explorer view double-click the view-definition file you created in<br />

the previous step, for example, MYVIEW.hdbview, and add the view-definition code to the file:<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 81


Note: The following code example is provided for illustration purposes only.<br />

schema="TEST_DUMMY";<br />

query="SELECT * FROM \"TEST_DUMMY\".\"com.sap.test.tables::<br />

02_HDB_DEPARTMENT_VIEW\"";<br />

dep<strong>en</strong>ds_on_view=["com.sap.test.tables::02_HDB_DEPARTMENT_VIEW"];<br />

6. Save the view-definition file.<br />

7. Commit the changes to the repository.<br />

a) Locate and right-click the new view-definition file in the Project Explorer view.<br />

b) In the context-s<strong>en</strong>sitive pop-up m<strong>en</strong>u, choose Team Commit .<br />

5.9 Data Provisioning Using Table Import<br />

You can import data from comma-separated values (CSV) into the SAP HANA tables using the SAP HANA<br />

Ext<strong>en</strong>ded Application Services (SAP HANA XS) table-import feature.<br />

In SAP HANA XS, you create a table-import sc<strong>en</strong>ario by setting up an import-model file, a import-data file, and one<br />

or more comma-separated value (CSV) files containing the cont<strong>en</strong>t you want to import into the specified SAP<br />

HANA table. The import-model file links the import operation to one or more target tables. The table definition (for<br />

example, in the form of a .hdbtable file) can either be created separately or be part of the table-import sc<strong>en</strong>ario<br />

itself.<br />

To use the SAP HANA XS table-import feature to import data into an SAP HANA table, you need to understand the<br />

following table-import concepts:<br />

● Table-Import Model<br />

You define the table-import model in a configuration file that specifies the data fields to import and import<br />

target tables of each data field.<br />

● Table-Import Data<br />

You define the table-import data in a configuration file that specifies how to link the CSV data files to the<br />

respective data field and, in turn, the target tables via the table-import model.<br />

● Table-Import Ext<strong>en</strong>sion<br />

You define the table-import ext<strong>en</strong>sion in a configuration file that modifies the relationship to an existing table<br />

import data file.<br />

CSV Data File Constraints<br />

The following constraints apply to the table-import feature in SAP HANA XS:<br />

● The number of table columns must match the number of CSV columns.<br />

● There must not be any incompatibilities betwe<strong>en</strong> the data types of the table columns and the data types of the<br />

CSV columns.<br />

● Overlapping data in data files is not supported.<br />

82<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model


● The target table of the import must not be modified (or app<strong>en</strong>ded to) outside of the data-import operation. If<br />

the table is used for storage of application data, this data may be lost during any operation to re-import or<br />

update the data.<br />

5.9.1 Table-Import Model<br />

The table-import model is a configuration file that you use to specify the parameters associated with the list of<br />

comma-separated-value (CSV) files that you want to import. The table-import model also specifies, for each<br />

parameter, into which table the linked-data files are imported, for example, the CSV files linked in the table-import<br />

data file.<br />

You can declare a parameter as optional. If a parameter is optional, it is not necessary to assign a value to this<br />

parameter in the implem<strong>en</strong>ting table import data object. To declare a variable as optional in the table-import<br />

model, add the keyword optional before the variable, as illustrated in the example below.<br />

optional listCsvFile csvList;<br />

If you want to add comm<strong>en</strong>ts to your table-import model, use two back slashes (//) as illustrated in the example<br />

below.<br />

listCsvFile fileList; //this is the csv file list<br />

Example Table-Import Model File<br />

listCsvFile csvFiles;<br />

import csvFiles "TISCHEMA" "TiPackage::TiTable";<br />

5.9.2 Table-Import Data<br />

The table-import data configuration file <strong>en</strong>ables you to specify which table-import model is to be implem<strong>en</strong>ted, for<br />

example, TiModel.hdbtim. The file-list parameters created in the table import-model file are assigned to lists of<br />

data-file links, for example, comma-separated values (.csv) files. In the example illustrated below, the .csv is<br />

called TiCsv.csv.<br />

If you want to add comm<strong>en</strong>ts to your table-import model, use two back slashes (//) as illustrated in the example<br />

below.<br />

implem<strong>en</strong>ts TiPackage:TiModel.hdbtim; //This is a the import model<br />

You can declare a parameter as final. If a parameter is defined as final, you can prev<strong>en</strong>t modifications of values<br />

assigned to file lists, for example, in a table-import ext<strong>en</strong>sion. To declare a variable as final in the table-import data<br />

file, add the keyword final before the variable, as illustrated in the example below.<br />

final csvFiles = ["sap.mypackage:data.csv"];<br />

Example Table-Import Data File<br />

implem<strong>en</strong>ts TiPackage:TiModel.hdbtim; //This is a comm<strong>en</strong>t<br />

csvFiles = ["TiPackage:TiCsv.csv"];<br />

csvFilesExt = [<br />

{<br />

file="TiPackage:TiCsv.csv"<br />

},<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 83


{<br />

}<br />

];<br />

header = false;<br />

file = "sap.xse:csv_config.csv";<br />

keys = [ "Col1" : "b*", "Col1" : "a"];<br />

5.9.3 Table-Import Ext<strong>en</strong>sions<br />

The table-import feature <strong>en</strong>ables you to modify the initial settings for variables defined in table-import<br />

configuration files by specifying new settings for defined variables in separate ext<strong>en</strong>sion files.<br />

If both a table-import model and a table-import data file exist, th<strong>en</strong> you can modify initial variable assignm<strong>en</strong>ts<br />

made in one table-import data file in a subsequ<strong>en</strong>t table-import data files (so called ext<strong>en</strong>sions) - as long as the<br />

variables are not declared explicitly as final in a previous file. The modification takes place only on the data values<br />

of variables, for example, in a table-import-ext<strong>en</strong>sion data file, where values can be augm<strong>en</strong>ted or be replaced.<br />

The result is a chain of table-import data artifacts. The <strong>en</strong>d result of a successful table import operation is based<br />

on the resulting definition of the file-list parameter as a result of all data files in the chain.<br />

Note: You can only create a linear chain of ext<strong>en</strong>sions. It is not permitted to create two table import data<br />

files modifying the same base table import data files.<br />

The following example illustrates a simple table-import model named timodel.hdbtim in the package<br />

TiPackage.<br />

csvFileList csvList;<br />

import csvList "TISCHEMA" "TiPackage::TiTable";<br />

The following example illustrates the cont<strong>en</strong>ts of a simple table-import data file named tidata.hdbtid, which<br />

implem<strong>en</strong>ts the table-import model defined in timodel.hdbtim illustrated above.<br />

implem<strong>en</strong>ts TiPackage:timodel.hdbtim;<br />

csvList = ["TiPackage:mydata.csv"];<br />

The following example illustrates how to ext<strong>en</strong>d the definition in the table-import data file tidata.hdbtid<br />

illustrated above.<br />

modifies sap.myPackage:tidata.hdbtid;<br />

csvList = csvList + ["TiPackage:myotherdata.csv"];<br />

After activation of the table-import files, the data from both CSV files (TiPackage:mydata.csv, and<br />

TiPackage:myotherdata.csv) is imported into the target table.<br />

5.9.4 Table-Import Configuration-File Syntax<br />

Wh<strong>en</strong> you define the details of the table-import operation, you use the following file-list types to <strong>en</strong>able the<br />

processing of certain data formats:<br />

● csvFileList<br />

Used to specify list of comma-separated values (CSV) file links. The linked CSV files are imported into the<br />

target table specified in the table import model. The import process parses and validates the CSV file format.<br />

● csvFileListExt<br />

84<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model


Similar to (but more flexible than) csvFileList since more settings are possible. You must specify the target<br />

table and the destination file list of CSV files, which is also ext<strong>en</strong>dable. For each CSV file it is possible to define<br />

the following additional options:<br />

○ If a header is giv<strong>en</strong> or not<br />

○ Which delimiter is use to separate the CSV data<br />

○ The key area of the input values<br />

○ If values are optionally <strong>en</strong>closed by an giv<strong>en</strong> delimiter<br />

Table Import Model Example<br />

The following example shows how to use the file list types csvFileList and csvFileListExt in the table-import<br />

model definition:<br />

listCsvFile csvFiles;<br />

import csvFiles "TISCHEMA" "TiPackage::TiTable";<br />

listCsvFileExt csvFilesExt;<br />

import csvFilesExt "TISCHEMA" "TiPackage::TiTableExt";<br />

Table Import Data Example<br />

The following example shows how to use the file list types csvFileList and csvFileListExt in the table-import<br />

data definition:<br />

implem<strong>en</strong>ts TiPackage:TiModel.hdbtim;<br />

csvFiles = ["TiPackage:TiCsv.csv"];<br />

csvFilesExt = [<br />

{<br />

file="TiPackage:TiCsv.csv"<br />

},<br />

{<br />

header = false;<br />

file = "sap.xse:csv_config.csv";<br />

keys = [ "Col1" : "b*", "Col1" : "a"];<br />

}<br />

];<br />

5.10 Importing Data Using Table Import<br />

The table-import function imports data from comma-separated values (CSV) files into SAP HANA tables.<br />

Before you start this task, make sure that the following prerequisites are met:<br />

● An SAP HANA database instance is available.<br />

● The SAP HANA database cli<strong>en</strong>t is installed and configured.<br />

● You have a database user account set up with the roles containing suffici<strong>en</strong>t privileges to perform actions in<br />

the repository, for example, add packages, add objects, and so on.<br />

● The SAP HANA studio is installed and connected to the SAP HANA repository.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 85


● You have a <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t including a repository workspace, a package structure for your<br />

application, and a shared project to <strong>en</strong>able you to synchronize changes to the project files in the local file<br />

system with the repository.<br />

Note: The names used in the following task are for illustration purposes only; replace the names of<br />

schema, tables, files, and so on shown in the following examples with your own names.<br />

1. Create a root package for your table import application.<br />

In SAP HANA studio, op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective and perform the following steps:<br />

a) In the Navigator view, right-click the package in the package hierarchy where you want to create the new<br />

package for your table-import configuration and choose New > Package... .<br />

b) Enter a name for your package, for example TiPackage.<br />

Note: Naming conv<strong>en</strong>tions exist for package names, for example, a package name must not start<br />

with either a dot (.) or a hyph<strong>en</strong> (-) and cannot contain two or more consecutive dots (..). In<br />

addition, the name must not exceed 190 characters.<br />

a) Choose OK to create the new package.<br />

2. Create a set of table-import files.<br />

The following files are required for a table import sc<strong>en</strong>ario.<br />

○ The table-import data file, for example, TiData.hdbtid<br />

Links the CSV data files to the data field and thus the target tables via the model<br />

○ A table-import model, for example, TiModel.hdbtim<br />

Defines the data fields and import target tables of each data field<br />

○ A table import package, for example, TiPackage<br />

Contains all the artifacts you need to complete the table-import operation<br />

○ A CSV file, for example, TiCsv.csv<br />

Contains the data to be imported into the SAP HANA table<br />

○ A table definition, for example, TiTable.hdbtable<br />

Defines the structure of the target import table<br />

○ The schema definition, for example, TISCHEMA.schema<br />

Specifies the name of the schema in which the target import table is created<br />

○ An application-logic, for example, TiConsumerApp.xsjs<br />

Once all files are created, you can import data from a source file, such as a CSV file, into the desired table<br />

during a commit.<br />

3. Using any code editor, op<strong>en</strong> the schema definition (TISCHEMA.schema) file that you just created and <strong>en</strong>ter<br />

86<br />

the name of the schema you want to apply.<br />

schemaname=TISCHEMA<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model


4. Op<strong>en</strong> the table definition of the target import table (TiTable.hdbtable) file that you just created and <strong>en</strong>ter<br />

the following lines of text.<br />

table.schemaName = "TISCHEMA";<br />

table.tableType = COLUMNSTORE;<br />

table.columns =<br />

[<br />

{name = "Surname"; sqlType = VARCHAR; nullable = false; l<strong>en</strong>gth =<br />

40; comm<strong>en</strong>t = "Person's surname";},<br />

{name = "For<strong>en</strong>ame"; sqlType = VARCHAR; nullable = false; l<strong>en</strong>gth =<br />

40; comm<strong>en</strong>t = "Person's for<strong>en</strong>ame";}<br />

...<br />

];<br />

table.primaryKey.pkcolumns = ["Surname"];<br />

5. Op<strong>en</strong> the CSV file, for example, TiCsv.csv in a text editor and <strong>en</strong>ter some values, for example, the following<br />

lines.<br />

Meyer,Hugo<br />

Schmitt,Michael<br />

Foo,Bar<br />

6. Op<strong>en</strong> the table-import model (TiModel.hdbtim) file that you just created and <strong>en</strong>ter the following lines of<br />

text.<br />

listCsvFile csvFiles;<br />

import csvFiles "TISCHEMA" "TiPackage::TiTable";<br />

7. Op<strong>en</strong> the data definition file (TiData.hdbtid) file that you just created in the same package and <strong>en</strong>ter the<br />

following lines of text.<br />

implem<strong>en</strong>ts TiPackage:TiModel.hdbtim;<br />

csvFiles = ["TiPackage:TiCsv.csv"];<br />

8. Deploy the table import.<br />

a) Select the package that you created in the first step.<br />

b) Click the alternate mouse button and choose Commit.<br />

c) Click the alternate mouse button and choose Activate.<br />

You have imported data into the SAP HANA table using the table import feature.<br />

5.11 Using Imported Table Data in SAP HANA<br />

Before you start, <strong>en</strong>sure that you have deployed a table import.<br />

Note: If you activate the files and th<strong>en</strong> log on to the system using the SAP HANA studio, you do not have<br />

suffici<strong>en</strong>t privileges to execute a SELECT statem<strong>en</strong>t on the table that was created. To be able to execute<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 87


the select statem<strong>en</strong>t on the table that was created, execute the following statem<strong>en</strong>t using the SQL editor<br />

in the SAP HANA studio:<br />

call<br />

_SYS_REPO.GRANT_PRIVILEGE_ON_ACTIVATED_CONTENT('select','"::"','');<br />

1. In the SAP HANA studio, write a Select statem<strong>en</strong>t to view the imported data.<br />

For example:<br />

SELECT * FROM "TiPackage::TiTable";<br />

2. Choose Execute.<br />

You can view the cont<strong>en</strong>ts of the comma-separated values (CSV) file in the SAP HANA table.<br />

5.12 Using Imported Table Data in an SAP HANA XS<br />

Application<br />

Before you start, <strong>en</strong>sure that you have deployed a table import.<br />

Note: If you activate the files and th<strong>en</strong> log on to the system using the SAP HANA studio, you do not have<br />

suffici<strong>en</strong>t privileges to execute a SELECT statem<strong>en</strong>t on the table that was created. You must execute the<br />

following statem<strong>en</strong>t using the SQL editor in the SAP HANA studio:<br />

call<br />

_SYS_REPO.GRANT_PRIVILEGE_ON_ACTIVATED_CONTENT('select','"Ti<br />

Package::TiTable"','');<br />

The example in the note above is for illustration purposes only. In the example shown, TiPackage is the path to<br />

the table-import package in the repository, where package names are separated by a dot (.); TiTable is the name<br />

of the table that is the target for the data-import operation; and is the name of a valid SAP HANA<br />

database user.<br />

To use imported table in an SAP HANA XS application, perform the following steps:<br />

1. Create an application-descriptor file and place it in your table-import package, for example, TiPackage.<br />

The application-descriptor file has no cont<strong>en</strong>ts and no name; it only has the file ext<strong>en</strong>sion .xsapp.<br />

2. Create an application-access file and place it in the package to which you want to grant access, for example, in<br />

same TiPackage package as the application descriptor file you created in the previous step.<br />

The application-access file does not have a name; it only has the file ext<strong>en</strong>sion .xsaccess.<br />

3. In the application-access (.xsaccess) file, <strong>en</strong>ter the following lines of text:<br />

88<br />

{<br />

}<br />

"auth_required" : true<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model


4. Create an application-logic file using server-side JavaScript, for example, TiConsumerApp.xsjs and place it<br />

in your table-import package, for example TiPackage.<br />

The application-logic file is the SAP HANA XS JavaScript application you use to access the data imported into<br />

the table.<br />

5. Enter the following lines of text into your application-logic file, for example, TiConsumerApp.xsjs.<br />

Note: The following example is for illustration purposes only. In the example shown,<br />

.TiPackage is the absolute path to the table-import package in the repository and<br />

TiTable is the name of the table that is the target for the data-import operation.<br />

$.response.cont<strong>en</strong>tType = "text/plain";<br />

var conn = $.db.getConnection();<br />

var pstatem<strong>en</strong>t1 = conn.prepareStatem<strong>en</strong>t( "SELECT * FROM<br />

\"TiPackage::TiTable\" WHERE \"Surname\"='Meyer");<br />

var result = pstatem<strong>en</strong>t1.executeQuery();<br />

if (result)<br />

{<br />

if (result.next())<br />

{<br />

$.response.setBody('The sql statem<strong>en</strong>t execution was successful.');<br />

}<br />

else<br />

{<br />

$.response.setBody("No data found");<br />

}<br />

$.response.status = $.net.http.OK;<br />

}<br />

else<br />

{<br />

$.response.status = $.net.http.INTERNAL_SERVER_ERROR;<br />

}<br />

result.close();<br />

pstatem<strong>en</strong>t1.close();<br />

conn.close();<br />

6. Select the package that you created in the first step.<br />

7. Click the alternate mouse button and choose Commit.<br />

8. Click the alternate mouse button and choose Activate.<br />

9. Access the SAP HANA XS application with the following URL http://:<br />

80//.xsjs.<br />

You receive the message, The SQL statem<strong>en</strong>t execution was sucessful.<br />

5.13 Ext<strong>en</strong>ding a Table Import<br />

Ext<strong>en</strong>d an existing table import file by creating a new table-import configuration file that you use to specify how to<br />

modify the relation to an existing table-import file.<br />

Before you start, <strong>en</strong>sure that you have deployed a table import; the following files are required for a table import<br />

ext<strong>en</strong>sion sc<strong>en</strong>ario.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 89


● The table-import data file, for example, TiData.hdbtid<br />

Links the new comma-separated-values CSV data files to the data fields and, in turn, the target tables via the<br />

model<br />

● The table-import ext<strong>en</strong>sion file, for example, TiDataExt<strong>en</strong>d.hdbtid<br />

Ext<strong>en</strong>ds the table-import data file TiData.hdbtid<br />

● A table-import model, for example, TiModel.hdbtim<br />

Defines the data fields and import target tables of each data field<br />

● A table import package, for example, TiPackage<br />

Contains all the artifacts you need to complete the table-import operation<br />

● A CSV file, for example, TiCsv.csv<br />

Contains the data to be imported into the SAP HANA table<br />

● A second CSV file, for example, TiCsvExt<strong>en</strong>d.csv<br />

Contains the new (ext<strong>en</strong>ded) data to be imported into the table<br />

● A table definition, for example, TiTable.hdbtable<br />

Defines the structure of the target import table<br />

● The schema definition, for example, TISCHEMA.schema<br />

Specifies the name of the schema in which the target import table is created<br />

● An application-logic, for example, TiConsumerApp.xsjs<br />

1. Op<strong>en</strong> the repository package that contains the table-import data file (for example, TiData.hdbtid) that you<br />

want to ext<strong>en</strong>d.<br />

2. Create a CSV file and give the new CSV file a name, for example, TiCsvExt<strong>en</strong>d.csv.<br />

This is the CSV file that contains the new, ext<strong>en</strong>ded data to be imported into the table. The ext<strong>en</strong>ded data<br />

either changes or adds to the date specified in the original CSV file TiCsv.csv.<br />

3. Op<strong>en</strong> the new CSV file TiCsvExt<strong>en</strong>d.csv in any code editor and <strong>en</strong>ter the new, ext<strong>en</strong>ded values you want to<br />

import separated by a comma.<br />

For example, <strong>en</strong>ter the name NewFoo,Bar.<br />

NewFoo,Bar<br />

Note: The value NewFoo in theTiCsvExt<strong>en</strong>d.csv modifies the original Foo value specified in the first<br />

CSV file TiCsv.csv.<br />

4. Create a table-import data-ext<strong>en</strong>sion file (for example, TiDataExt<strong>en</strong>d.hdbtid) and place the new data-<br />

ext<strong>en</strong>sion file in the same package (for example, TiPackage) as the other files.<br />

5. Enter the following lines into the data-ext<strong>en</strong>sion file TiDataExt<strong>en</strong>d.hdbtid.<br />

90<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model


Note: The following example is for illustration purposes only. In the example shown,<br />

.TiPackage is the absolute path to the table-import package in the repository and<br />

TiData.hdbtid is the name of the data-ext<strong>en</strong>sion file for the data-import operation.<br />

modifies TiPackage:TiData.hdbtid;<br />

csvFiles = csvFiles + ["TiPackage:TiCsvExt<strong>en</strong>d.csv"];<br />

6. In the SAP HANA XS application .xsjs, modify the script to query the<br />

new value(s) specified in the table-import ext<strong>en</strong>sion configuration.<br />

In this example, the table-import ext<strong>en</strong>sion adds the name NewFoo to the data to be imported to SAP HANA;<br />

you now want to query the value NewFoo.<br />

Note: The following example is for illustration purposes only. In the example shown,<br />

TiPackage is the absolute path to the table-import package in the repository and<br />

TiTable is the name of the table that is the target for the data-import operation.<br />

$.response.cont<strong>en</strong>tType = "text/plain";<br />

var conn = $.db.getConnection();<br />

var pstatem<strong>en</strong>t1 = conn.prepareStatem<strong>en</strong>t( "SELECT * FROM<br />

\"TiPackage::TiTable\" WHERE \"Surname\"='NewFoo");<br />

var result = pstatem<strong>en</strong>t1.executeQuery();<br />

if (result)<br />

{<br />

if (result.next())<br />

{<br />

$.response.setBody('The sql statem<strong>en</strong>t execution was successful.');<br />

}<br />

else<br />

{<br />

$.response.setBody("No data found");<br />

}<br />

$.response.status = $.net.http.OK;<br />

}<br />

else<br />

{<br />

$.response.status = $.net.http.INTERNAL_SERVER_ERROR;<br />

}<br />

result.close();<br />

pstatem<strong>en</strong>t1.close();<br />

conn.close();<br />

7. Access the SAP HANA XS application with the following URL http://:<br />

80//.xsjs.<br />

You receive the message, The SQL statem<strong>en</strong>t execution was successful.<br />

SAP HANA Developer Guide<br />

Setting up the Persist<strong>en</strong>ce Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 91


6 Setting Up the Analytic Model<br />

Modeling refers to an activity of refining or slicing data in database tables by creating views to depict a business<br />

sc<strong>en</strong>ario. The views can be used for reporting and decision-making.<br />

The modeling process involves the simulation of <strong>en</strong>tities, such as CUSTOMER, PRODUCT, and SALES, and<br />

relationships betwe<strong>en</strong> them. These related <strong>en</strong>tities can be used in analytics applications such as SAP<br />

BusinessObjects Explorer and Microsoft Office. In SAP HANA, these views are known as information views.<br />

Information views use various combinations of cont<strong>en</strong>t data (that is, non-metadata) to model a business use case.<br />

Cont<strong>en</strong>t data can be classified as follows:<br />

● Attribute: Descriptive data, such as customer ID, city, and country.<br />

● Measure: Quantifiable data, such as rev<strong>en</strong>ue, quantity sold and counters.<br />

You can model <strong>en</strong>tities in SAP HANA using the Modeler perspective, which includes graphical data modeling tools<br />

that allow you to create and edit data models (cont<strong>en</strong>t models) and stored procedures. With these tools, you can<br />

also create analytic privileges that govern the access to the models, and decision tables to model related business<br />

rules in a tabular format for decision automation.<br />

You can create the following types of information views:<br />

● Attribute Views<br />

● Analytic Views<br />

● Calculation Views<br />

The figure below shows the process flow for modeling in SAP HANA.<br />

92<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


You can perform the following tasks in the Modeler perspective:<br />

● Import metadata<br />

Create tables by importing the table definitions from the source systems using the Data Services<br />

infrastructure. For more information, see Importing Table Definitions.<br />

● Load data<br />

Note: You can also create tables from scratch using the SAP HANA Developm<strong>en</strong>t perspective. For<br />

more information, see Setting Up the Persist<strong>en</strong>ce Model.<br />

Load data into the table definitions imported from the source system using the Load Controller, Sybase<br />

Replication Server or SAP Landscape Transformation, and from flat files. For more information, see Loading<br />

Data into Tables.<br />

● Create packages<br />

Note: You can also provision data into the table definitions in the SAP HANA Developm<strong>en</strong>t perspective.<br />

For more information, seeSetting Up the Persist<strong>en</strong>ce Model.<br />

Logically group objects together in a structured way. For more information, see Maintaining Repository<br />

Packages.<br />

● Create information views<br />

Model various slices of the data stored in the SAP HANA database. Information views are oft<strong>en</strong> used for<br />

analytical use cases, such as operational data mart sc<strong>en</strong>arios or multidim<strong>en</strong>sional reporting on rev<strong>en</strong>ue,<br />

profitability, and so on. For more information, see Creating Views.<br />

● Create procedures<br />

Create procedures using SQLScript for implem<strong>en</strong>ting a complex logic that cannot be achieved using other<br />

objects. For more information, see Developing Procedures.<br />

● Create analytic privileges<br />

Control which data that individual users sharing the same data foundation or view can see. For more<br />

information, see Setting Up Roles and Authorizations.<br />

● Import SAP NetWeaver BW objects<br />

Import SAP NetWeaver BW objects into SAP HANA, and expose them as information views. For more<br />

information, seeImporting BW Objects.<br />

● Create decision tables<br />

Create a tabular repres<strong>en</strong>tation of related rules using conditions and actions. For more information, see<br />

Creating Decision Tables.<br />

● Import and export objects<br />

Import and export the cont<strong>en</strong>t objects from and to the cli<strong>en</strong>t and server location. For more information,<br />

seeImplem<strong>en</strong>ting Lifecycle Managem<strong>en</strong>t.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 93


Related Links<br />

SAP HANA Studio [page 23]<br />

The SAP HANA studio is an Eclipse-based <strong>dev</strong>elopm<strong>en</strong>t and administration tool for working with SAP HANA,<br />

including creating projects, creating <strong>dev</strong>elopm<strong>en</strong>t objects, and deploying them to SAP HANA. As a <strong>dev</strong>eloper,<br />

you may want to also perform some administrative tasks, such as configuring and monitoring the system.<br />

6.1 Setting Up the Modeling Environm<strong>en</strong>t<br />

6.1.1 Setting Modeler Prefer<strong>en</strong>ces<br />

You can set prefer<strong>en</strong>ces for your Eclipse workspace to set up the default settings that the system uses wh<strong>en</strong>ever<br />

you log on.<br />

1. Choose Window Prefer<strong>en</strong>ces Modeler<br />

Note: You can also set the prefer<strong>en</strong>ces choosing Quick Launch Manage Prefer<strong>en</strong>ces<br />

2. Id<strong>en</strong>tify the required prefer<strong>en</strong>ce and perform the corresponding substeps from the table below:<br />

94<br />

Requirem<strong>en</strong>t Prefer<strong>en</strong>ce Substeps<br />

To specify the structure of cont<strong>en</strong>t<br />

packages in the navigator panel<br />

To set the prefer<strong>en</strong>ces for loading data<br />

using flat file<br />

To set the default value for the cli<strong>en</strong>t<br />

that will be used while previewing<br />

model data<br />

Cont<strong>en</strong>t Pres<strong>en</strong>tation Hierarchical - to view the package<br />

structure in a hierarchical manner<br />

such that, the child folder is inside the<br />

par<strong>en</strong>t folder. Flat - to view all the<br />

packages at the same level for<br />

example, sap, sap.ecc, sap.ecc.ui.<br />

Show Object Type Folders - to group<br />

together similar objects in a package<br />

such as attribute views in the Attribute<br />

View package.<br />

Data From Local File 1. Browse the location to save error<br />

log files for data load using flat<br />

files.<br />

2. Enter the batch size for loading<br />

data. For example, if you specify<br />

2000 and a file has records of<br />

10000 rows the data load will<br />

happ<strong>en</strong> in 5 batches.<br />

3. Enter a decision maker count that<br />

will be used to propose data types<br />

based on the file. For example,<br />

<strong>en</strong>ter 200 if you want the<br />

proposal to be made based on the<br />

200 rows of file data.<br />

Default Model Parameters Select the cli<strong>en</strong>t from the Default<br />

Cli<strong>en</strong>t drop-down list.<br />

To <strong>en</strong>force various rules on objects Validation Rules Select the required rules to be applied<br />

while performing object validation.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Requirem<strong>en</strong>t Prefer<strong>en</strong>ce Substeps<br />

Note: Enforcing validation<br />

rules with severity “Error”<br />

are mandatory.<br />

To determine the numbers of rows to<br />

be displayed in a page<br />

Data Preview Select the maximum rows for data<br />

preview as required.<br />

To specify a location for job log files Logs 1. Expand the Logs node.<br />

To <strong>en</strong>able logging the repository calls<br />

and specify location for repository log<br />

files<br />

To <strong>en</strong>able search for the attributes<br />

used in the views<br />

To allow lower case alphabets for<br />

attribute view, analytic view,<br />

calculation view, procedure and<br />

analytic privilege names<br />

2. Select Job Log.<br />

3. Browse the location where you<br />

want to save the job log files.<br />

Logs 1. Expand the Logs node.<br />

2. Select Job Log.<br />

3. Select true from the drop-down<br />

list.<br />

4. Browse the location where you<br />

want to save the repository log<br />

files.<br />

Search Options Select Enable Search Attributes. .<br />

Case Restriction Deselect the Model name in upper<br />

case checkbox.<br />

Note: After changing the prefer<strong>en</strong>ces make sure you choose Apply and OK.<br />

6.1.2 Configuring the Import Server<br />

In order to load data from external sources to SAP HANA you need to establish a connection with the server. To<br />

connect you need to provide the details of BusinessObjects Data Services repository and ODBC drivers. Once the<br />

connection is established you can import the tables definition and th<strong>en</strong> load the data into table definitions.<br />

1. In the Quick Launch tab page, choose Configure Import Server.<br />

2. Enter the IP address of the server from which you want to import data.<br />

3. Enter the repository name.<br />

4. Enter the ODBC data source, and choose OK.<br />

6.1.3 Importing Table Definitions<br />

One of the ways to create tables to load source system data into SAP HANA is to import the table definitions from<br />

the source system.<br />

You have configured the SAP HANA modeler for importing metadata using the Data Services infrastructure.<br />

Use this procedure to import table definitions (metadata) from a source system to load source system data into<br />

SAP HANA. You can point to these table definitions for creating various cont<strong>en</strong>t models such as attribute,<br />

analytic, and calculation views.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 95


Based on your requirem<strong>en</strong>ts, use one of the following approaches:<br />

● Mass Import: To import all table definitions from a source system. For example, you can use this approach if<br />

this is a first import from the giv<strong>en</strong> source system.<br />

● Selective Import: To import only selected table definitions from a source system. For example, you can use<br />

this approach if there are only few table definitions added or modified in the source system after your last<br />

import.<br />

1. If you want to import all table definitions, do the following:<br />

a) In the File m<strong>en</strong>u, choose Import.<br />

b) Expand the SAP HANA Cont<strong>en</strong>t node.<br />

c) Choose Mass Import of Metadata, and choose Next.<br />

d) Select the target system where you want to import all the table definitions, and choose Next.<br />

e) In the Connection Details dialog, <strong>en</strong>ter the operating system user name and password of the target<br />

system.<br />

f) Select the required source system, and choose Finish.<br />

Note: If the required system is not available from the dropdown list, you need to contact your<br />

administrator.<br />

2. If you want to import selective table definitions, do the following:<br />

a) In the File m<strong>en</strong>u, choose Import.<br />

b) Expand the SAP HANA Cont<strong>en</strong>t node.<br />

c) Choose Selective Import of Metadata, and choose Next.<br />

d) Select the target system where you want to import the table definitions, and choose Next.<br />

e) Select the required source system.<br />

Note: If the required system is not available from the dropdown list, you need to add the new<br />

source system using Manage Connections.<br />

f) In the Type of Objects to Import field, select the required type, and choose Next.<br />

g) Add the required objects (tables or extractors) that you want to import.<br />

Note: If you want to add dep<strong>en</strong>d<strong>en</strong>t tables of a selected table, select the required table in the<br />

Target panel, and choose Add Dep<strong>en</strong>d<strong>en</strong>t Tables in the context m<strong>en</strong>u.<br />

h) Select the schema into which you want to import the metadata.<br />

i) If you selected object type as extractor, select the package into which you want to place the<br />

corresponding objects.<br />

j) Choose Next, th<strong>en</strong> review and confirm the import by choosing Finish.<br />

If the source object is a table or non V-type extractor, the system creates physical tables and stores them in<br />

the selected schema. However, if the source object is a V-Type extractor, the system creates cont<strong>en</strong>t models<br />

and stores these models in the selected package, and the underlying physical tables in the schema.<br />

Configuring Data Services for Metadata Import<br />

Use this procedure to <strong>en</strong>able the SAP HANA modeler to import table definitions from the source system using the<br />

Data Services infrastructure.<br />

1. Set the Passphrase<br />

96<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


a) Log on to the C<strong>en</strong>tral Managem<strong>en</strong>t Console of SAP BusinessObjects Enterprise (BOE).<br />

b) Choose Manage Applications Data Services Application Settings .<br />

c) In the Encryption Passphrase field, <strong>en</strong>ter the passphrase that you have be<strong>en</strong> using for the SAP HANA<br />

studio, and choose Save.<br />

d) Restart the TOMCAT and BOE services.<br />

2. Disable Session Security<br />

a) Log on to the Data Services Managem<strong>en</strong>t Console.<br />

b) Choose Administrator.<br />

c) In the Navigator panel, choose Web Services.<br />

d) Choose the Web Services Configuration tab page.<br />

e) Select the Import_Repo_Object checkbox to save the connection details.<br />

f) Select Disable Session Security from the dropdown m<strong>en</strong>u, and choose Apply.<br />

3. Creating a Data Source<br />

a) Go to Start Control Panel Administrative Tools .<br />

b) Choose Data Sources (ODBC).<br />

c) Choose the System DSN tab page, and choose Add.<br />

d) Select HDBODBC from the driver list, and choose Finish.<br />

e) Enter a name and description for the data source.<br />

f) Enter server details.<br />

Note: The format in which you need to <strong>en</strong>ter details is . For<br />

example, abc2012.wdf.sap.corp:30115.<br />

g) Enter the required database details in the format, . For example, M4701.<br />

h) Choose Connect.<br />

Managing Source System Connections<br />

Use this procedure to add or manage a source system connection that is required to import table definitions.<br />

6.1.4 Loading Data into Tables<br />

● If you are using the Load Controller or Sybase Replication Server infrastructure, make sure that you have<br />

imported all table definitions into the SAP HANA database. For more information, see Importing Table<br />

Definitions.<br />

● If you are using the SLT compon<strong>en</strong>t, the source system(s), target system and the target schema, are<br />

configured by the administrator during the installation.<br />

Use this procedure to load data into your table definitions. Dep<strong>en</strong>ding on your requirem<strong>en</strong>ts, you can perform the<br />

following:<br />

● Initial Load - to load all data from a source SAP ERP system into the SAP HANA database by using Load<br />

Controller or SAP Landscape Transformation (SLT). This is mostly applicable wh<strong>en</strong> you are loading data from<br />

the source for the first time.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 97


● Data Replication - to keep the data of selected tables in the SAP HANA database up-to date with the source<br />

system tables by using SyBase Replication Server or SAP Landscape Transformation (SLT).<br />

1. In the Quick Launch tab page, choose Data Provisioning.<br />

2. If you are using SLT-based replication, choose Source.<br />

3. Choose Load (for initial load) or Replicate (for data replication) as appropriate.<br />

4. Select the required tables to load or replicate data in any of the following ways:<br />

○ Search for the required tables.<br />

1. Select the table from the list, and choose Add.<br />

2. If you want to save the selected list of tables locally for future refer<strong>en</strong>ce, select the Export selected<br />

tables checkbox, and specify the target location.<br />

○ Load the list of tables from a local file as follows:<br />

1. Choose Load from file.<br />

2. Select the file that contains the required list of tables.<br />

Note: The supported file type is .csv.<br />

5. If you are using the load controller infrastructure, choose Next and <strong>en</strong>ter the operating system user name and<br />

password.<br />

6. Choose Finish.<br />

Susp<strong>en</strong>ding and Resuming Data Load<br />

If you are using SLT- based replication, you can choose to stop data replication temporarily for a selected list of<br />

tables, and later resume data load for these.<br />

1. In the Quick Launch tab page, choose Data Provisioning.<br />

2. Select the source system for which you want to susp<strong>en</strong>d or resume data load.<br />

3. Choose Susp<strong>en</strong>d or Resume as required.<br />

4. Select the tables, and choose Add.<br />

5. Choose Finish.<br />

Uploading Data from Flat Files<br />

Use this procedure to upload data from flat files available in a cli<strong>en</strong>t file system, to SAP HANA database.<br />

● If the table schema corresponding to the file to be uploaded already exists in the SAP HANA database, the<br />

new data records are app<strong>en</strong>ded to the existing table.<br />

● If the required table for loading the data does not exist in the SAP HANA database, create a table structure<br />

based on the flat file.<br />

The application suggests the column names and data types for the new tables and allows you to edit them. The<br />

new table always has a 1:1 mapping betwe<strong>en</strong> the file and table columns. The application does not allow you to<br />

overwrite any columns or change the data type of existing data. The supported file types are .csv, .xls, and .xlsx.<br />

1. In the File m<strong>en</strong>u, choose Import.<br />

2. In the Select an import source section, expand the SAP HANA cont<strong>en</strong>t node.<br />

3. Select Data from Local File, and choose Next.<br />

98<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


4. In the Target System section, select the target system to which you want to import the data using the flat file,<br />

and choose Next.<br />

5. In the Define Import Properties page, browse and select the file containing the data you want to load.<br />

6. If you have selected a CSV file, select a delimiter.<br />

Note: A delimiter is used to determine columns and pick the correct data from them. In a csv file, the<br />

accepted delimiters are ',', ';' and ':'.<br />

7. If you have selected an .xls or .xlsx file, select a worksheet.<br />

8. If you want to load the data into a new table, select the New option and perform the following substeps:<br />

a. Choose Next.<br />

b. On the Manage Table Definition and Data Mapping scre<strong>en</strong>, map the source and target columns.<br />

Note:<br />

○ Only 1:1 column mapping is supported. You can also edit the table definition by changing the<br />

data types, r<strong>en</strong>aming columns, adding or deleting the columns, and so on.<br />

○ You can choose to map the source and target columns using the Auto Map option. If you<br />

choose the one to one option, th<strong>en</strong> first column of the source is mapped to the first column at<br />

the target. If you choose the option Map by name, the source and target columns with the<br />

same name are mapped.<br />

9. If you want to app<strong>en</strong>d the data to an existing table, select the Existing option and perform the following<br />

substeps:<br />

a. Choose Next.<br />

b. On the Manage Table Definition and Data Mapping scre<strong>en</strong>, map the source and target columns.<br />

10. If you want to provide a constant value for a column at the target, perform the following substeps:<br />

a. Right-click the column.<br />

b. From the context m<strong>en</strong>u, choose Make As Constant.<br />

c. In the Constant dialog box, <strong>en</strong>ter a value, and choose OK.<br />

Note: You can set a column to constant if it is not mapped to a source column.<br />

11. To provide a default value for a column at the target, <strong>en</strong>ter a value in the Default Value column.<br />

12. Choose Finish.<br />

6.1.5 Copying Cont<strong>en</strong>t Delivered by SAP<br />

You have the following privileges:<br />

● REPO.READ for the source package.<br />

● REPO.MAINTAIN_NATIVE_PACKAGES and REPO.EDIT_NATIVE_OBJECTS for the root package.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 99


Use this functionality for one of the most common sc<strong>en</strong>arios, that is, to copy the standard cont<strong>en</strong>t shipped by SAP<br />

or an SAP partner to your local package to meet your modeling and reporting use cases. For example, from<br />

sap.ecc.fin to customer.ecc.fin.<br />

Tip: We recomm<strong>en</strong>d you copy the cont<strong>en</strong>t shipped by SAP or an SAP partner to your local package to<br />

avoid overwriting your changes during the subsequ<strong>en</strong>t import.<br />

You can also use this procedure to copy objects, other than SAP-shipped in a package to other packages in the<br />

same system based on your business use case.<br />

Caution: If you copy an object but not its dep<strong>en</strong>d<strong>en</strong>t objects (if any), the copied object in the target<br />

package will have refer<strong>en</strong>ces to the dep<strong>en</strong>d<strong>en</strong>t objects in the source package.<br />

To copy the objects, you need to map the source root packages to the target root packages. You need to activate<br />

the copied objects in the target package to consume them for reporting purposes.<br />

Restriction: For script-based calculation views and procedures, ev<strong>en</strong> if you copy the dep<strong>en</strong>d<strong>en</strong>t objects,<br />

you need to change the script manually and adjust the dep<strong>en</strong>d<strong>en</strong>t object refer<strong>en</strong>ces.<br />

1. In the Quick Launch tab page, choose Mass Copy.<br />

2. To create a mapping betwe<strong>en</strong> the source package and the target package, perform the following substeps:<br />

a) Choose Add.<br />

b) Select a source package and a target package, and choose Next.<br />

Tip: If you want to create more package mapping, select the source and target packages as<br />

required.<br />

c) Select the required objects, and choose Add.<br />

3. Choose Next to view the summary.<br />

Tip: You can deselect an object to avoid copying it to the target package.<br />

4. Choose Finish to confirm cont<strong>en</strong>t copy.<br />

6.1.6 Mapping the Authoring Schema to the Physical Schema<br />

Schema mapping is done wh<strong>en</strong> the physical schema in the target system is not the same as the physical schema<br />

in the source system, usually in a transport sc<strong>en</strong>ario. The schema mapping is maintained via a mapping table.<br />

You use this procedure to map the authoring schemas to the physical database schemas in the target system to<br />

access and deploy the transported objects.<br />

A physical schema is the schema in which the tables are available. It may differ in the source and target systems.<br />

An authoring schema (logical schema) is the physical database schema in the source system with which the<br />

cont<strong>en</strong>t objects are created.<br />

Cont<strong>en</strong>t object definitions are stored in the repository, and contain refer<strong>en</strong>ces to the physical database schemas.<br />

Wh<strong>en</strong> you copy the cont<strong>en</strong>t objects to a differ<strong>en</strong>t system, for example, from an SAP system to a customer system,<br />

or betwe<strong>en</strong> customer systems, the object definition still refers to the physical database schemas at the source. To<br />

resolve this, you use schema mapping.<br />

100<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Remember: Schema mapping only applies to refer<strong>en</strong>ces from repository objects to catalog objects. It is<br />

not int<strong>en</strong>ded to be used for repository to repository refer<strong>en</strong>ces.<br />

Restriction: You need to map the refer<strong>en</strong>ces of script-based calculation views and procedures manually,<br />

that is, by changing the script.<br />

You can map several authoring schemas to the same physical schema. For example, cont<strong>en</strong>t objects delivered by<br />

SAP refer to differ<strong>en</strong>t authoring schemas, whereas in the customer system, all these authoring schemas are<br />

mapped to a single physical schema where the tables are replicated.<br />

Remember: The mapping betwe<strong>en</strong> authoring and physical schema is stored in the configuration table<br />

“_SYS_BI”.”M_SCHEMA_MAPPING”<br />

Note:<br />

● In a system having no schema mapping, the authoring schema is filled 1:1 from the physical schema<br />

otherwise it would not be possible to change the default schema.<br />

● In a system if authoring schema mapping is found, it is checked that whether the curr<strong>en</strong>t authoring<br />

schema is mapped to the curr<strong>en</strong>t physical schema as follows: If yes, nothing is done. If not (including<br />

an empty authoring schema case), th<strong>en</strong> the authoring schema is filled. With the backwards mapped<br />

authoring schema if there is a 1:1 mapping i.e. only one authoring schema was found. With this we<br />

simplify the mapping table in customer systems because ev<strong>en</strong> for <strong>en</strong>hancem<strong>en</strong>ts the cont<strong>en</strong>t schema<br />

is kept and no additional mapping must be introduced if the customer transports from <strong>dev</strong>elopm<strong>en</strong>t<br />

to production With the physical schema in case no or more than one authoring schemas are found.<br />

This indicates that the customer has changed the schema-dep<strong>en</strong>d<strong>en</strong>t parts and that therefore his<br />

physical schema is stored also in the authoring schema.<br />

Example use case: Lets assume we have only SAP_ERP -> ERP in the mapping table and an analytic<br />

view having defaultSchema = SAP_ERP. Let's assume the customer changes the defaultSchema to<br />

CUS. Since CUS has no mapping the authoringSchema of the defaultSchema is set to CUS as well.<br />

Th<strong>en</strong> the customer changes the defaultSchema back to ERP. A 1:1 mapping for ERP is found<br />

(SAP_ERP) and th<strong>en</strong> the authoring schema is set back to SAP_ERP.<br />

1. In the Quick Launch tab page, choose Schema Mapping.<br />

2. Choose Add.<br />

3. Enter the authoring schema and physical schema that need to be mapped.<br />

4. Choose OK.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 101


Consider a source system, SAP, with an information object, AV1. This refers to the table MARA in the<br />

SAP_ERP physical database schema. There is a target system, Customer, with the physical database<br />

schema EMEA.<br />

After you import cont<strong>en</strong>t, the object AV1 cannot be activated in the Customer system, since it still refers<br />

to SAP_ERP schema.<br />

AV1 in the Customer system curr<strong>en</strong>tly refers to SAP_ERP. To be able to activate the object, you need to<br />

modify the mapping of AV1 in the Customer system.<br />

To do this, a mapping is created in the target system Customer betwe<strong>en</strong> the authoring and physical<br />

schema as follows:<br />

Authoring Schema Physical Schema<br />

SAP_ERP EMEA<br />

6.1.7 G<strong>en</strong>erating Time Data<br />

For modeling a business sc<strong>en</strong>ario that requires time dim<strong>en</strong>sion, you can populate time data in the default time-<br />

related tables pres<strong>en</strong>t in _SYS_BI schema, for example while creating time attribute views. You can choose to<br />

g<strong>en</strong>erate the time data for a giv<strong>en</strong> time span based on your requirem<strong>en</strong>ts such as, cal<strong>en</strong>dar type and granularity.<br />

If you model a time attribute view without g<strong>en</strong>erating time data, wh<strong>en</strong> you use data preview an empty view is<br />

shown. Note that if you populate the data before modeling time attribute views, you can use the Value Help from<br />

the respective time tables.<br />

1. In the Quick Launch tab page, choose G<strong>en</strong>erate Time Data.<br />

2. If your financial year is same as that of the cal<strong>en</strong>dar year, that is, January to December, in the Cal<strong>en</strong>dar Type<br />

dropdown, select Gregorian.<br />

102<br />

a) Enter the period for which you want to g<strong>en</strong>erate time data.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


) Select the required granularity<br />

c) Choose G<strong>en</strong>erate.<br />

Note: If the selected granularity is Week or Month, specify the First day of the week.<br />

System populates the g<strong>en</strong>erated time data in M_TIME_DIMENSION_YEAR, M_TIME_DIMENSION_MONTH,<br />

M_TIME_DIMENSION_WEEK, M_TIME_DIMENSION tables in _SYS_BI schema.<br />

3. If your financial year is not same as that of the Cal<strong>en</strong>dar Year for example, March to April, , in the Cal<strong>en</strong>dar<br />

Type dropdown, select Fiscal.<br />

a) Enter the period for which you want to g<strong>en</strong>erate the time data.<br />

b) Select the Variant Schema where tables containing variant data are maintained.<br />

Note: Tables T009 and T009B contains Variants information.<br />

c) Select the required variant that specifies the number of periods along with their start and <strong>en</strong>d dates<br />

according to your use case.<br />

d) Choose G<strong>en</strong>erate.<br />

System populates the g<strong>en</strong>erated time data in M_FISCAL_CALENDAR table pres<strong>en</strong>t in the _SYS_BI schema.<br />

6.2 Creating Views<br />

6.2.1 Attributes and Measures<br />

Attributes and measures form the cont<strong>en</strong>t data that is used for modeling. While attributes repres<strong>en</strong>t the<br />

descriptive data like city and country, measures repres<strong>en</strong>t quantifiable data like rev<strong>en</strong>ue and quantity sold.<br />

Attributes<br />

Attributes are the individual non-measurable analytical elem<strong>en</strong>ts.<br />

● Simple Attributes<br />

Simple attributes are individual non-measurable analytical elem<strong>en</strong>ts that are derived from the data<br />

foundation.<br />

For example, PRODUCT_ID and PRODUCT_NAME are attributes of a PRODUCT subject area.<br />

● Calculated Attributes<br />

Calculated attributes are derived from one or more existing attributes or constants.<br />

For example, deriving the full name of a customer (first and last name), assigning a constant value to an<br />

attribute that can be used for arithmetic calculations.<br />

● Private Attributes<br />

Private attributes used in an analytic view allow you to customize the behavior of an attribute for only that<br />

view.<br />

For example, if an analytic view or a calculation view include an attribute view, it inherits the behavior of the<br />

attributes from the attribute view (set the parameter once and it is replicated in all views consuming it).<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 103


By contrast, if you create an analytic view for one specific use case in which you want a particular attribute to<br />

behave differ<strong>en</strong>tly than it does in the attribute view to which it belongs, you can define it as a private attribute.<br />

Measures<br />

Measures are simple measurable analytical elem<strong>en</strong>ts. Measures are derived from analytic and calculation views.<br />

● Simple Measures<br />

A simple measure is a measurable analytical elem<strong>en</strong>t that is derived from the data foundation.<br />

For example, PROFIT.<br />

● Calculated Measure<br />

Calculated measures are defined based on a combination of data from OLAP cubes, arithmetic operators,<br />

constants, and functions.<br />

For example, calculated measures can be used to calculate the total sales of a product across five regions, or<br />

to assign a constant value to a measure for a calculation.<br />

● Restricted Measure<br />

Restricted measures are used to filter the value based on the user-defined rules for the attribute values.<br />

● Counters<br />

Counters add a new measure to the calculation view definition to count the recurr<strong>en</strong>ce of an attribute. For<br />

example, to count how many times Product appears.<br />

Note:<br />

You can choose to hide the attributes and measures that are not required for cli<strong>en</strong>t consumption. For<br />

example, for a complex calculation that is derived from a series of computations, you can hide the levels of<br />

computations that are not required for reporting purposes.<br />

6.2.2 Attribute Views<br />

Attribute views are used to model an <strong>en</strong>tity based on the relationships betwe<strong>en</strong> attribute data contained in<br />

multiple source tables.<br />

For example, customer ID is the attribute data that describes measures (that is, who purchased a product).<br />

However, customer ID has much more depth to it wh<strong>en</strong> joined with other attribute data that further describes the<br />

customer (customer address, customer relationship, customer status, customer hierarchy, and so on).<br />

You create an attribute view to locate the attribute data and to define the relationships betwe<strong>en</strong> the various tables<br />

to model how customer attribute data, for example, will be used to address business needs.<br />

You can model the following elem<strong>en</strong>ts within an attribute view:<br />

● Columns<br />

● Calculated Columns<br />

104<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


● Hierarchies<br />

Note: In the Semantics node, you can classify the columns as attributes and build calculated columns<br />

of attribute type.<br />

Note: For more information about the attributes and hierarchies m<strong>en</strong>tioned above, see sections<br />

Attributes and Measures, and Hierarchies.<br />

You can choose to further fine-tune the behavior of the attributes of an attribute view by setting the properties as<br />

follows:<br />

● Filters to restrict values that are selected wh<strong>en</strong> using the attribute view.<br />

● Attributes can be defined as Hidd<strong>en</strong> so that they can be used in processes but are not visible to <strong>en</strong>d users.<br />

● Attributes can be defined as key attributes and used wh<strong>en</strong> joining multiple tables.<br />

● The Drill Down Enabled property can be used to indicate if an attribute is available for further drill down wh<strong>en</strong><br />

consumed.<br />

Attribute views can later be joined to tables that contain measures within the definition of an analytic view or a<br />

calculation view to create virtual star schema on the SAP HANA data.<br />

6.2.3 Creating Attribute Views<br />

Attribute views are used to define joins betwe<strong>en</strong> tables, and to select a subset (or all) of the table's columns and<br />

rows. The rows selected can also be restricted by filters. One application of attribute views is to join multiple<br />

tables together wh<strong>en</strong> using star schemas, to create a single dim<strong>en</strong>sion table. The resultant dim<strong>en</strong>sion attribute<br />

view can th<strong>en</strong> be joined to a fact table via an analytic view to provide meaning to its data. In this use case, the<br />

attribute view adds more columns and also hierarchies as further analysis criteria to the analytic view. In the star<br />

schema of the analytic view, the attribute view is shown as a single dim<strong>en</strong>sion table (although it might join multiple<br />

tables), that can be joined to a fact table. For example, attribute views can be used to join employees to<br />

organizational units which could th<strong>en</strong> be joined to a sales transaction via an analytic view<br />

You have imported T009 and T009B tables for creating attribute view of type Time.<br />

Use this procedure to create a view that is used to model descriptive attribute data (that does not contain<br />

measures) using attributes.<br />

Tip: You need this view for creating a multidim<strong>en</strong>sional view.<br />

1. Set Parameter<br />

1. In the Modeler perspective, expand the Cont<strong>en</strong>t node of the required system.<br />

2. Expand the package to which you want to save your information object.<br />

3. In the context m<strong>en</strong>u of Attribute Views node, choose New .<br />

4. Enter a name and description for the view.<br />

5. To create data foundation for the view, perform substeps of the required sc<strong>en</strong>ario giv<strong>en</strong> in the table<br />

below:<br />

Sc<strong>en</strong>ario Substeps<br />

Create a view with table<br />

attributes.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

In the Sub Type dropdown list, choose Standard.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 105


Sc<strong>en</strong>ario Substeps<br />

Create a view with time<br />

characteristics.<br />

Copy a view from an<br />

existing view – in this case,<br />

you can modify the copied<br />

view.<br />

Derive a view from an<br />

existing view – in this case,<br />

you cannot modify the<br />

derived view that acts as a<br />

refer<strong>en</strong>ce to the base<br />

attribute view.<br />

6. Choose Finish.<br />

1. In the Sub Type dropdown list, choose Time.<br />

2. Select the required cal<strong>en</strong>dar type as follows:<br />

a. If the cal<strong>en</strong>dar type is Fiscal, select a variant schema, and a fiscal<br />

variant.<br />

b. If the cal<strong>en</strong>dar type is Gregorian, select the granularity for the<br />

data.<br />

3. To use the system-g<strong>en</strong>erated time attribute view, select Auto Create.<br />

Note:<br />

The system creates a time attribute view based on the default<br />

time tables, and defines the appropriate columns/attributes<br />

based on the granularity. It also creates the required filters.<br />

Note: The tables used for time attribute creation with cal<strong>en</strong>dar<br />

type Gregorian are, M_TIME_DIMENSION, M_TIME_DIMENSION_<br />

YEAR, M_TIME_DIMENSION_ MONTH,<br />

M_TIME_DIMENSION_WEEK and for cal<strong>en</strong>dar type Fiscal is<br />

M_FISCAL_CALENDAR. If you want to do a data preview for the<br />

created attribute view, you need to g<strong>en</strong>erate time data into the<br />

m<strong>en</strong>tioned tables from the Quick Launch tab page.<br />

1. Choose Copy From.<br />

2. Select the required attribute view.<br />

1. In the Sub Type dropdown, choose Derived.<br />

2. Select the required attribute view.<br />

The attribute view editor op<strong>en</strong>s. The Sc<strong>en</strong>ario panel of the editor consist of two nodes - Data Foundation and<br />

Semantics. The Data Foundation node repres<strong>en</strong>ts the tables used for defining the output structure of the view.<br />

The Semantics node repres<strong>en</strong>ts the output structure of the view, that is, the dim<strong>en</strong>sion. In the Details panel<br />

you define the relationship betwe<strong>en</strong> data sources and output elem<strong>en</strong>ts.<br />

2. Define Output Structure<br />

106<br />

a) Add the tables that you want to use in any of the following ways:<br />

○ Drag the required tables pres<strong>en</strong>t in the Catalog to the Data Foundation node.<br />

○ Select the Data Foundation node in the Sc<strong>en</strong>ario panel, and in the context m<strong>en</strong>u of the Details panel,<br />

choose Add.<br />

Note: You can choose to add the same table again in Data Foundation using table aliases in the<br />

editor. For example, in cases where you want to have differ<strong>en</strong>t cardinalities from the same table.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Restriction: It is not allowed to add column views to the Data Foundation.<br />

b) If you want to query data from more than one table, in the Details panel context m<strong>en</strong>u, choose Create<br />

Join, and <strong>en</strong>ter the required details.<br />

Note: After creating the join, you can edit its properties like join type, cardinality, etc in the<br />

Properties view. You can choose to create Text Join betwe<strong>en</strong> table fields in order to get languagespecific<br />

data. For example, consider that you have a product table that contains product IDs and<br />

no description about products, and you have a text table for products that has a language-specific<br />

description for each product. You can create a text join betwe<strong>en</strong> the two tables to get languagespecific<br />

details. In a text join, the right table should be the text table and it is mandatory to specify<br />

the Language Column.<br />

c) Add the table columns to the output structure that is, the Semantics node that you want to use to define<br />

attribute data. You can define the attribute data by doing one of the following:<br />

○ Select the toggle button on the left of the table field.<br />

○ Right-click the table field, and choose Add to Output.<br />

d) If you want to specify a filter condition based on which system must display data for a table field in the<br />

output do the following:<br />

1. Right-click the table field, and choose Apply Filter.<br />

2. Select the required operator, and <strong>en</strong>ter filter values.<br />

All the table fields that you have added to the output are automatically mapped as attributes.<br />

3. Define Key Attributes<br />

a) Select the Semantics node.<br />

b) In the Attributes tab page of the Column panel, select the required attribute and select the Type as Key<br />

Attribute.<br />

Remember: If there is more than one key attribute, all key attributes of the attribute view must<br />

point to the same table in the data foundation. The c<strong>en</strong>tral table of the attribute view is the one to<br />

which all the key attributes point.<br />

Note: In case of auto-g<strong>en</strong>erated time attribute views, the attributes and key attributes are<br />

automatically assigned.<br />

4. Optional Step: Create Calculated Columns<br />

a) In the Output of Data Foundation panel, right-click Calculated Columns.<br />

b) In the context m<strong>en</strong>u, choose New.<br />

c) Enter a name and description (label) for the calculated column.<br />

d) Select a data type for the calculated column.<br />

e) Enter l<strong>en</strong>gth and scale for the calculated coulmn.<br />

f) In the Expression Editor <strong>en</strong>ter the expression. For example, you can write a formula such as,<br />

if("PRODUCT" = 'ABC', "DISCOUNT" * 0.10, "DISCOUNT"). This means if attribute PRODUCT equals the<br />

string ‘ABC’ th<strong>en</strong> DISCOUNT equals to DISCOUNT multiplied by 0.10 should be returned. Otherwise the<br />

original value of attribute DISCOUNT should be used.<br />

g) Choose OK.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

Note: The expression can also be assembled by dragging and dropping the expression elem<strong>en</strong>ts<br />

from the m<strong>en</strong>us below the editor window.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 107


5. Optional Step: To filter and view the table data in the modeled view, which is relevant to a specific cli<strong>en</strong>t as<br />

specified in the table fields, such as, MANDT or CLIENT, at runtime perform the following:<br />

1. Select the Semantics node, in the Properties panel edit the Default Cli<strong>en</strong>t property.<br />

Note: The default value for the property is the one that is specified as a prefer<strong>en</strong>ce. At runtime, if the<br />

property is set to Dynamic th<strong>en</strong>, the value set for the Session Cli<strong>en</strong>t property is used to filter table<br />

data. The Session Cli<strong>en</strong>t property is set while creating a user.<br />

Note: You can choose to create hierarchies in order to define relationships betwe<strong>en</strong> attributes.<br />

Note:<br />

You can choose to associate an attribute with another attribute, which describes it in detail. For<br />

example, wh<strong>en</strong> reporting via Label Mapping (also known as Description Mapping), you can associate<br />

Region_ID with Region_Text.<br />

Before SP05, you could associate an attribute with another attribute in a model. In the runtime<br />

object an .description column is g<strong>en</strong>erated and is shown during data preview. Now, from<br />

SP05 onwards the behavior is as follows:<br />

○ For an attribute (CUSTOMER) you can now maintain label mapping by selecting another<br />

attribute (TEXT) from the same model as "Label Column" in the Semantics node. The result is<br />

"TEXT" displaying as the label column in data preview. Note that the CUSTOMER.description<br />

column is not g<strong>en</strong>erated and is not shown in data preview anymore.<br />

○ If you have created an object using the old editor (which supported the old style of description<br />

mapping) and try to op<strong>en</strong> it using the new editor you will see a new column<br />

CUSTOMER.description (as an attribute) which is hidd<strong>en</strong> and disabled because this column<br />

cannot be used in other places such as parameter/variable, calculated column, restricted<br />

column and so on. You cannot maintain properties for this attribute for example, description.<br />

CUSTOMER.description displays in the data preview as long as you do not change it in the<br />

editor. You can change its name. After changing the name you can maintain its properties and<br />

use it like other attributes.<br />

6. Activate the view using one of the following options in the toolbar:<br />

○ Save and Activate - to activate the curr<strong>en</strong>t view and redeploy the affected objects if an active version of<br />

the affected object exists. Otherwise only curr<strong>en</strong>t view gets activated.<br />

○ Save and Activate All - to activate the curr<strong>en</strong>t view along with the required and affected objects.<br />

Note: You can also activate the curr<strong>en</strong>t view by selecting the view in the Navigator panel and choosing<br />

Activate in the context m<strong>en</strong>u.<br />

You can find the activated model in the related package. If you want to modify this model, from the context m<strong>en</strong>u,<br />

choose Op<strong>en</strong> and make the necessary changes.<br />

108<br />

Restriction: The behavior of attribute views with the new editor is as follows:<br />

● Wh<strong>en</strong> an object (a table of an attribute view) is removed and added again in an attribute view in order<br />

to reflect the rec<strong>en</strong>tly modified columns with its data type, it reflects the previous state of the columns<br />

alone. For more information, see SAP Note 1783668.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Related Links<br />

● Wh<strong>en</strong> you op<strong>en</strong> an attribute view and there is a missing column in the required object, an error is<br />

shown and the editor does not op<strong>en</strong>. For information regarding the solution of this issue, see SAP<br />

Note 1788552.<br />

Creating Hierarchies [page 127]<br />

Activating Objects [page 132]<br />

G<strong>en</strong>erating Time Data [page 102]<br />

6.2.4 Analytic Views<br />

Analytic views are used to model data that includes measures.<br />

For example, an operational data mart repres<strong>en</strong>ting sales order history would include measures for quantity,<br />

price, and so on.<br />

The data foundation of an analytic view can contain multiple tables. However, measures that are selected for<br />

inclusion in an analytic view must originate from only one of these tables (for business requirem<strong>en</strong>ts that include<br />

measure sourced from multiple source tables, see calculation view ).<br />

Analytic views can be simply a combination of tables that contain both attribute data and measure data. For<br />

example, a report requiring the following:<br />

<br />

Optionally, attribute views can also be included in the analytic view definition. In this way, you can achieve<br />

additional depth of attribute data. The analytic view inherits the definitions of any attribute views that are included<br />

in the definition. For example:<br />

<br />

You can model the following elem<strong>en</strong>ts within an analytic view:<br />

● Columns<br />

● Calculated Columns<br />

● Restricted Columns<br />

● Variables<br />

● Input parameters<br />

Remember: In the Semantics node, you can classify columns and calculated columns as type<br />

attributes and measures. The attributes you define in an analytic view are Local to that view. However,<br />

attributes coming from attribute views in an analytic view are Shared attributes. For more information<br />

about the attributes and measures m<strong>en</strong>tioned above, see section Attributes and Measures.<br />

Note: For more information about the variables and input parameters m<strong>en</strong>tioned above, see sections<br />

Assigning Variables and Creating Input Parameters.<br />

You can choose to further fine-tune the behavior of the attributes and measures of an analytic view by setting the<br />

properties as follows:<br />

● Filters to restrict values that are selected wh<strong>en</strong> using the analytic view.<br />

● Attributes can be defined as Hidd<strong>en</strong> so that they are able to be used in processes but are not viewable to <strong>en</strong>d<br />

users.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 109


● Attributes can be defined as key attribute and used wh<strong>en</strong> joining multiple tables.<br />

● The Drill Down Enabled property can be used to indicate if an attribute is available for further drill down wh<strong>en</strong><br />

consumed.<br />

● Aggregation type on measures<br />

● Curr<strong>en</strong>cy and Unit of Measure parameters (you can set the Measure Type property of a measure, and also in<br />

Calculated Column creation dialog, associate a measure with curr<strong>en</strong>cy and unit of measure)<br />

6.2.5 Creating Analytic Views<br />

Analytic views are typically defined on a fact table that contains transactional data (as measures). Using analytic<br />

views you can create a selection of measures, add attributes and join attribute views.<br />

Analytic views leverage the computing power of SAP HANA to calculate aggregate data, e. g. the number of sold<br />

cars per country, or the maximum power consumption per day. They are defined on only one fact table, a table<br />

which contains for example, one row per sold car or one row per power meter reading, or some form of business<br />

transaction records. Fact tables can be joined to allow access to more detailed data using a single analytic view as<br />

long as the facts (measures) come from a single table. Analytic views can be defined in a single table, or in joined<br />

tables.<br />

Analytic views can contain two types of columns, attributes and measures, for which measures are of type simple,<br />

calculated, and restricted. Measures are attributes for which an aggregation must be defined. If analytic views are<br />

used in SQL statem<strong>en</strong>ts th<strong>en</strong> the measures have to be aggregated e. g. using the SQL functions SUM(), MIN(), or MAX(). Normal columns can be handled as regular attributes.<br />

They do not need to be aggregated.<br />

1. Set Parameters<br />

a) In the Modeler perspective, expand the Cont<strong>en</strong>t node of the required system.<br />

b) Select the package in which you want to save your information object.<br />

c) From the context m<strong>en</strong>u of the package, choose New Analytic View .<br />

Note: Once you have an analytic view in a package, you can also create another one from the<br />

context m<strong>en</strong>u of the Analytic View node in the respective package.<br />

d) Enter a name and description for the view.<br />

e) If you want to create a view based on the existing one, choose Copy From option, and select the required<br />

view.<br />

f) Choose Finish.<br />

The analytic view editor op<strong>en</strong>s. The Sc<strong>en</strong>ario panel of the editor consist of the following three nodes:<br />

○ Data Foundation - repres<strong>en</strong>ts the tables used for defining the fact table of the view.<br />

○ Logical Join - repres<strong>en</strong>ts the relationship betwe<strong>en</strong> the selected table fields (fact table) and attribute views<br />

that is, used to create the star schema.<br />

○ Semantics - repres<strong>en</strong>ts the output structure of the view.<br />

In the Details panel you define the relationship betwe<strong>en</strong> data sources and output elem<strong>en</strong>ts.<br />

2. Define Output Structure<br />

110<br />

a) Add the tables that you want to use in any of the following ways:<br />

○ Drag the required tables pres<strong>en</strong>t in the Catalog to the Data Foundation node.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


○ Select the Data Foundation node in the Sc<strong>en</strong>ario panel, and in the context m<strong>en</strong>u of the Details panel,<br />

choose Add Tables.<br />

Note: You can choose to add the same table again in Data Foundation using table aliases in the<br />

editor. For example, if you want to have differ<strong>en</strong>t cardinalities from the same table.<br />

Restriction: It is not allowed to add column views to the Data Foundation of an analytic view.<br />

However, you can add column views in a calculation view.<br />

Remember: If there is more than one table, you need to specify one of the tables as the c<strong>en</strong>tral<br />

table (fact table) from which the measures will be derived. You can specify the c<strong>en</strong>tral table by<br />

selecting a value in the C<strong>en</strong>tral Entity property of the Data Foundation node.<br />

b) If you want to query data from more than one table, in the Details panel context m<strong>en</strong>u, choose Create<br />

Join, and <strong>en</strong>ter the required details.<br />

Tip: After specifying the c<strong>en</strong>tral table or choosing one of the field as measure, wh<strong>en</strong> you save the<br />

view automatic assignm<strong>en</strong>t of attributes and measures is done. All the numeric fields from the<br />

c<strong>en</strong>tral table are assigned as measures and others as attributes. In this case, you will not be able<br />

to join measures with other numeric fields. Also, if you have specified all the attributes and<br />

measures of the view before saving it, automatic assignm<strong>en</strong>t of attributes and measures will not<br />

overwrite them.<br />

Note: After creating the join, you can edit its properties such as join type, cardinality, etc in the<br />

Properties view. You can choose to create a Text Join betwe<strong>en</strong> table fields in order to get language<br />

specific data. For example, consider that you have a product table that contains product IDs but<br />

no product description, and you have a text table for products that has language-specific<br />

description for each product. You can create a text join betwe<strong>en</strong> the two tables to get languagespecific<br />

details. In a text join, the right table should be the text table and it is mandatory to specify<br />

the Language Column.<br />

c) Add the table columns to the output structure (Semantics node) that you want to use to define the facts<br />

in any of the following ways:<br />

○ Select the toggle button on the left of the table field.<br />

○ Right-click the table field, and choose Add to Output.<br />

d) If you want to specify a filter condition based on which system must display data for a table field in the<br />

output, for example to display rev<strong>en</strong>ue for only selected companies based on the filter value, do the<br />

following:<br />

1. Right-click the table field, and choose Apply Filter.<br />

2. Select the required operator, and <strong>en</strong>ter filter values.<br />

The table fields selected above form the fact table.<br />

e) To create a star schema that is, linking the fact table with the descriptive data (attribute views), do the<br />

following:<br />

1. Add the required attribute views in the Logical Join node in any of the following ways:<br />

○ Drag the required attribute views pres<strong>en</strong>t in the Cont<strong>en</strong>t node to the Logical Join node.<br />

○ Select the Logical Join node in the Sc<strong>en</strong>ario panel, and choose Add button to add the attribute<br />

views.<br />

2. Create joins betwe<strong>en</strong> the views and fact table.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 111


Note: In the Logical Join, you can create a temporal join betwe<strong>en</strong> the date field of the fact<br />

table to an interval (to and from) field of the attribute view. The temporal join has to start from<br />

the fact table such that the single column must be in the fact table and, the to and from<br />

columns must be in the table that is directly joined to the fact table. The join type must be a<br />

refer<strong>en</strong>tial join. The supported data types are timestamp, date, and integer.<br />

Restriction: While creating joins you must <strong>en</strong>sure that a table does not appear twice in any join path (in<br />

particular a self join is not supported). A join path is the set of joins that links the fact table to other<br />

tables.<br />

While creating joins betwe<strong>en</strong> analytic view and attribute view the same table cannot be used both in<br />

the join path of analytic view and attribute view. Also, in a join path of analytic view and attribute view,<br />

the table of the attribute view which is linked to the fact table should not have an alias table.<br />

3. Optional Step: Create Calculated Column<br />

a) In the Output of Logical Join panel, right-click Calculated Columns.<br />

b) In the context m<strong>en</strong>u, choose New.<br />

c) Enter a name and description (label) for the calculated column.<br />

d) Select a data type, and <strong>en</strong>ter the l<strong>en</strong>gth and scale for the calculated column.<br />

e) Select the Column Type to determine whether it is a calculated attribute or a calculated measure.<br />

f) If you select Calculate Before Aggregation, select the aggregation type.<br />

Note: If you select Calculate Before Aggregation, the calculation happ<strong>en</strong>s as per the expression<br />

specified and th<strong>en</strong> the results are aggregated as SUM, MIN, MAX or COUNT. If Calculate Before<br />

Aggregation is not selected, the data is not aggregated but it gets calculated as per calculation<br />

expression (formula), and the aggregation is shown as FORMULA. If the aggregation is not set,<br />

th<strong>en</strong> it will be considered as an attribute.<br />

g) In the Expression Editor <strong>en</strong>ter the expression. For example, you can write a formula:<br />

if("PRODUCT" = 'ABC, "DISCOUNT" * 0.10, "DISCOUNT") which is equival<strong>en</strong>t to, if attribute PRODUCT<br />

equals the string ‘ABC’ th<strong>en</strong> DISCOUNT equals to DISCOUNT multiplied by 0.10 should be returned.<br />

Otherwise the original value of attribute DISCOUNT should be used.<br />

Note: The expression can also be assembled by dragging and dropping the expression elem<strong>en</strong>ts<br />

from the m<strong>en</strong>us below the editor window.<br />

h) If you want to associate the calculated column with curr<strong>en</strong>cy and unit of measuring quantity, select the<br />

Advanced tab page and select the required Type.<br />

i) Choose OK.<br />

Remember: Calculated Columns can be created only at the Logical Join level and not at the Data<br />

Foundation level.<br />

Note: The aggregation type for calculated columns is only tak<strong>en</strong> into account, if they are calculated<br />

before aggregation<br />

4. Optional Step: Create Restricted Columns<br />

112<br />

You can create restricted columns if you want to filter the value for an output field based on the user-defined<br />

rules. For example, you can choose to restrict the value for the Rev<strong>en</strong>ue column only for Region = APJ, and<br />

Year = 2012.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


a) In the Output panel of the Logical Join, right-click Restricted Columns, and choose New.<br />

b) Enter a name and description for the restricted column.<br />

c) From the Column dropdown list, select the column for which you want to apply a restriction.<br />

Caution: The column for which you apply a restriction must be defined as measure in the<br />

semantics node otherwise the validation will fail.<br />

d) Choose Add Restriction.<br />

e) In the Parameter field, select the column that you want to create a restriction for, th<strong>en</strong> select the operator<br />

and value.<br />

f) Choose OK.<br />

Note: For a restricted column the aggregation type of the base column is applied.<br />

5. Define Attributes and Measures<br />

a) Select the Semantics node.<br />

b) In the Column panel, select the Local tab page, and change the type as attributes and measures.<br />

Note: The Shared tab page shows the attributes of the used attribute views. While g<strong>en</strong>erating the<br />

column views, the joined private attribute name is ignored and the shared attribute name is<br />

considered, therefore the joined private attribute is not shown on the Semantics node.<br />

Remember: If the MultiDim<strong>en</strong>sional Reporting property of the analytic view is set to false, the view<br />

will not be available for reporting purposes. If the value is set to true, an additional column<br />

Aggregation is available to specify the aggregation type for measures.<br />

Note:<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

You can choose to associate an attribute with another attribute, which describes it in detail. For<br />

example, wh<strong>en</strong> reporting via Label Mapping (also known as Description Mapping), you can<br />

associate Region_ID with Region_Text.<br />

Before SP05, you could associate an attribute with another attribute in a model. In the runtime<br />

object an .description column is g<strong>en</strong>erated and is shown during data preview. Now,<br />

from SP05 onwards the behavior is as follows:<br />

○ For an attribute (CUSTOMER) you can now maintain label mapping by selecting another<br />

attribute (TEXT) from the same model as "Label Column" in the Semantics node. The result is<br />

"TEXT" displaying as the label column in data preview. Note that the CUSTOMER.description<br />

column is not g<strong>en</strong>erated and is not shown in data preview anymore.<br />

○ If you have created an object using the old editor (which supported the old style of description<br />

mapping) and try to op<strong>en</strong> it using the new editor you will see a new column<br />

CUSTOMER.description (as an attribute) which is hidd<strong>en</strong> and disabled because this column<br />

cannot be used in other places such as parameter/variable, calculated column, restricted<br />

column and so on. You cannot maintain properties for this attribute for example, description.<br />

CUSTOMER.description displays in the data preview as long as you do not change it in the<br />

editor. You can change its name. After changing the name you can maintain its properties and<br />

use it like other attributes.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 113


Note: You can change the type of a measure and perform curr<strong>en</strong>cy conversion by selecting it in<br />

the Local tab page and changing the Measure Type property in the properties panel.<br />

6. Optional Step: You can filter and view the table data in the modeled view for a specific cli<strong>en</strong>t as specified in the<br />

table fields, such as MANDT or CLIENT, by doing the following:<br />

1. Select the Semantics node, in the Properties panel, edit the Default Cli<strong>en</strong>t property.<br />

Note: The default value for the property is the one that is specified as a prefer<strong>en</strong>ce. If the property is<br />

set to Dynamic, at runtime the value set for the Session Cli<strong>en</strong>t property is considered to filter table<br />

data. The Session Cli<strong>en</strong>t property is set while creating a user.<br />

7. Optional Step: Assign Variable<br />

You assign variables to a field at design time for obtaining data based on the values you provide for the<br />

variable. At runtime, you can provide differ<strong>en</strong>t values to the variable to view the corresponding set of attribute<br />

data.<br />

a) In the Semantics node Variables/Input Parameter panel, choose the Create Variable option.<br />

b) Enter a name and description for the variable.<br />

c) Select the required attribute from the dropdown list.<br />

Note: At runtime, the value for the variable is fetched from the selected attribute's data.<br />

d) Choose the required Selection Type from the dropdown list.<br />

Note:<br />

○ Single Value - Used to filter and view data based on a single attribute value. For example, to<br />

view the sales of a product where the month is equal to January.<br />

○ Interval - Used to filter and view a specific set of data. For example, to view the exp<strong>en</strong>diture of<br />

a company from March to April.<br />

○ Range - Used to filter and view data based on the conditions that involve operators such as:<br />

○ "="(equal to)<br />

○ ">" (greater than)<br />

○ "=" (greater than or equal to)<br />

○ "


Related Links<br />

Note: If an active version of the affected objects exist, activating the curr<strong>en</strong>t view redeploys the<br />

affected objects. You can also activate an object from the object context m<strong>en</strong>u in the Navigator panel.<br />

Tip: You can choose to activate the other objects (required or impacted objects) along with the<br />

curr<strong>en</strong>ct object using the Save and Activate All option in the toolbar.<br />

Note:<br />

Restriction: The behavior of analytic views with the new editor is as follows:<br />

○ Wh<strong>en</strong> an object (a table of or an attribute view) is removed and added again in an attribute<br />

view and analytic view editor in order to reflect the rec<strong>en</strong>tly modified columns with its data<br />

type, it reflects the previous state of the columns . For more information about the<br />

problem and its solution, see SAP Note 1783668.<br />

○ Wh<strong>en</strong> you op<strong>en</strong> an analytic view and there is a missing column in the required object, an<br />

error is shown and the editor does not op<strong>en</strong>. For information regarding the solution of this<br />

issue, see SAP Note 1788552.<br />

Using Curr<strong>en</strong>cy and Unit of Measure [page 130]<br />

Activating Objects [page 132]<br />

Creating Input Parameters [page 125]<br />

6.2.6 Calculation Views<br />

A calculation view is used to define more advanced slices on the data in SAP HANA database. Calculation views<br />

can be simple and mirror the functionality found in both attribute views and analytic views. However, they are<br />

typically used wh<strong>en</strong> the business use case requires advanced logic that is not covered in the previous types of<br />

information views.<br />

For example, calculation views can have layers of calculation logic, can include measures sourced from multiple<br />

source tables, can include advanced SQL logic, and so on. The data foundation of the calculation view can include<br />

any combination of tables, column views, attribute views and analytic views. You can create joins, unions,<br />

projections, and aggregation levels on the sources.<br />

You can model the following elem<strong>en</strong>ts within a calculation view:<br />

● Attributes<br />

● Measures<br />

● Calculated measures<br />

● Counters<br />

● Hierarchies (created outside of the attribute view)<br />

● Variables<br />

● Input parameters<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

Note: For more information about the attributes, measures, counters, and hierarchies m<strong>en</strong>tioned<br />

above, see sections Attributes and Measures, and Hierarchies.<br />

Note: For more information about the variables and input parameters m<strong>en</strong>tioned above, see sections<br />

AssigningVariables and Creating Input Parameters.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 115


Calculation views can include measures and be used for multi-dim<strong>en</strong>sional reporting or can contain no measures<br />

and used for list-type of reporting. Calculation views can either be created using a graphical editor or using a SQL<br />

editor. These various options provide maximum flexibility for the most complex and compreh<strong>en</strong>sive business<br />

requirem<strong>en</strong>ts.<br />

6.2.7 Creating Calculation Views<br />

Calculation views are used to provide composites of other views. Ess<strong>en</strong>tially they are based on a join or union of<br />

two or more data flows or on invoke of built-in or g<strong>en</strong>eric SQL functions.<br />

Calculation views are defined as either graphical views or scripted views but not as SQLScript (for exceptions, see<br />

below) dep<strong>en</strong>ding on how they are created. They can be used in the same way as analytic views, however, in<br />

contrast to analytic views it is possible to join several fact tables in a calculation view.<br />

Graphical views can be modeled using the graphical modeling features of the SAP HANA Modeler. Scripted views<br />

are created as sequ<strong>en</strong>ces of SQL statem<strong>en</strong>ts.<br />

As m<strong>en</strong>tioned previously calculation views are g<strong>en</strong>erally not created using SQLScript. There are however,<br />

exceptions to this rule. SQLScripts with the following properties can be used in calculation views:<br />

- No input parameters<br />

- Always read-only (that is, do not make changes to the database)<br />

- Side-effect free<br />

You can use calculation views to derive values and key performance indicators(KPIs).<br />

Note: The terms "attribute" and "columns" are used interchangeably in this procedure. They may d<strong>en</strong>ote a<br />

table column, a particular data field of a table row, or the cont<strong>en</strong>ts of such a data field. The respective<br />

meaning should be clear from the context.<br />

Procedure<br />

1. In the Modeler perspective, expand the system node from the Navigator pane.<br />

2. Expand the Cont<strong>en</strong>t node.<br />

3. Right-click the required package.<br />

4. From the context m<strong>en</strong>u, choose New Calculation View .<br />

a. Enter a name and description.<br />

b. Select the required package.<br />

Create a Script-Based Calculation View<br />

1. Choose SQL Script.<br />

2. Select the required schema from the Default Schema dropdown list, for unqualified access in SQL.<br />

Note: If you do not select a default schema, while scripting, you need to provide fully qualified names<br />

of the objects used.<br />

3. Select the required option from the Run With dropdown list, which id<strong>en</strong>tifies whose rights are to be considered<br />

116<br />

while executing the calculation sc<strong>en</strong>ario.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Note:<br />

Definer's right: If you want system to use the rights of the definer while executing the view or<br />

procedure for any user.<br />

Invoker's right: If you want system to use the rights of the curr<strong>en</strong>t user while executing the view or<br />

procedure .<br />

4. Choose Finish.<br />

5. Define the Output Structure<br />

a. Choose Define Output Parameter from the Output pane.<br />

b. To add the output parameters with the required data type and l<strong>en</strong>gth, from the Output pane toolbar,<br />

choose Define Output Parameter button.<br />

c. Choose OK.<br />

6. Define the Function<br />

Note: The order and data types of the output parameters should match the table columns order<br />

and data type which is used in the select query.<br />

a. Define the function using SQL Script commands.<br />

Note:<br />

7. Save and Activate<br />

○ You can create variables, and bind them to attributes for filtering data. The values you provide<br />

for the variables at runtime determine which data records are selected for consumption.<br />

○ You can create input parameters for the calculation view that works as a placeholder in a<br />

query.<br />

○ You can create a hierarchy betwe<strong>en</strong> attributes of the view.<br />

a. To save the view, choose File Save .<br />

b. From the context m<strong>en</strong>u of the calculation view, choose Activate.<br />

Create a Graphical Calculation View<br />

1. Choose Graphical.<br />

2. Select the required schema from the Schema for Conversion dropdown list.<br />

Note: The schema selected for conversion is used during the curr<strong>en</strong>cy conversion. It list down all the<br />

schemas which has curr<strong>en</strong>cy related tables and the same can be changed during design time from the<br />

properties.<br />

3. Choose Next.<br />

4. Follow the instructions in the wizard to select the required tables and cont<strong>en</strong>t models.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 117


118<br />

Adding Unions/Joins/ Projections/ Aggregation<br />

a. From the Tools Palette, choose the required option as follows:<br />

View Description<br />

Union Used to combine the result set of two or more data<br />

sources. For example, to show the names of all the<br />

employees of a store which has differ<strong>en</strong>t branches each<br />

maintaining its own employee records table.<br />

Join Used to query data from two or more data sources,<br />

based on a specified condition. For example, to retrieve<br />

the sales of two stores maintaining individual table for<br />

sales based on the customer ID.<br />

Projection Used to filter or create a subset of the required columns<br />

of a table or view for creating the model. For example,<br />

selecting the employee name and sales quantity from a<br />

table consisting of many more columns.<br />

Aggregation Used to summarize data of a group of rows by<br />

calculating values in a column. For example, to retrieve<br />

total sales of a product in a month. The supported<br />

aggregation types are sum, min, and max.<br />

Note:<br />

○ The input for union, join, projection, and aggregation views can consist of data sources, union,<br />

join, projection, or aggregation views.<br />

○ You can have only one source of input for aggregation and projection views.<br />

○ You can choose to create filters on projection and aggregation view attributes.<br />

b. Map the input to the selected option.<br />

Mapping attributes<br />

a. To map attributes in a union view, drag and drop the required columns from Source to Target.<br />

You can also modify the attribute mapping. For more information, see Managing Attribute Mappings<br />

[page 122]<br />

Tip: To create a system g<strong>en</strong>erated mapping, choose Auto Map By Name.<br />

b. In case of a join view, join the columns of the source data sources.<br />

Note:<br />

○ The output of a union view is the attributes that you added to the Target.<br />

○ The output of a join view is the joined attributes. However, to add additional attributes to the<br />

view's output, from the context m<strong>en</strong>u, choose Add to Output.<br />

○ To add attributes of projection or aggregation view to its output, choose Add to Output from<br />

the context m<strong>en</strong>u.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Optional Step: Creating Calculated Columns<br />

The output of union, join, or projection view is stored under the Column node in the Output panel.To<br />

perform calculations on these columns, do the following:<br />

1. Right-click the Calculated Columns node.<br />

2. From the context m<strong>en</strong>u, choose New.<br />

a. Enter the name.<br />

b. Select the data type.<br />

c. Enter the l<strong>en</strong>gth and scale.<br />

d. To perform calculations on the output columns, do the following:<br />

○ If you know the formula, <strong>en</strong>ter the expression to perform the calculation.<br />

○ From the list, select the required elem<strong>en</strong>ts, operator, and functions.<br />

e. Choose Add.<br />

Optional Step: Applying Filter on Aggregation and Projection View Attributes<br />

1. Right-click the required attribute.<br />

2. From the context m<strong>en</strong>u, choose Apply Filter.<br />

3. Select the required operator.<br />

4. Enter value.<br />

5. Choose OK.<br />

Note: You can edit a filter using filter expressions from the Output pane which provides you<br />

with more conditions that can be used in the filter including AND, OR, and NOT. For example,<br />

to retrieve the sales of a product where (rev<strong>en</strong>ue >= 100 AND region = India) OR (rev<strong>en</strong>ue<br />

>=50 AND region = Germany).<br />

Note: In order to define pattern-based filters in calculation views, you use the expression<br />

editor accessed by double-clicking the expression icon under the filter node of the Output<br />

panel. If you type<br />

match("ABC",'*abc*')<br />

the equival<strong>en</strong>t SQL is<br />

.<br />

where “ABC“ like ‘%abc%’<br />

Adding Attributes and Measures to Calculation View Output<br />

a. From the designer panel, choose the Output node.<br />

b. To add an attribute, from the context m<strong>en</strong>u, choose Add as Attribute.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 119


120<br />

c. To add a measure, from the context m<strong>en</strong>u, choose Add as Measure.<br />

Note: You can choose to associate a measure with the curr<strong>en</strong>cy or unit of measure. To do so,<br />

select the measure and in the Properties panel select Measure Type.<br />

d. If you want to create calculated attributes, perform the following substeps:<br />

a. In the Output pane, right-click Calculated Attributes.<br />

b. From the context m<strong>en</strong>u, choose New.<br />

c. Enter a name and description.<br />

d. On the Key tab, define the formula for the calculated attribute as follows:<br />

a. Select a data type for the calculated attribute from the dropdown list.<br />

b. Enter the l<strong>en</strong>gth and scale.<br />

c. Select the required attributes, operator, and function.<br />

d. To check the validity of the formula, choose Validate.<br />

e. Choose Add.<br />

e. To add a Description to the calculated attribute, write the formula as above.<br />

e. If you want to create calculated measures, do the following:<br />

a. In the Output pane, right-click Calculated Measures.<br />

b. From the context m<strong>en</strong>u, choose New.<br />

a. Enter a name and description.<br />

b. Select the required Aggregation Type.<br />

c. If you want to hide the measure while previewing data, choose Hidd<strong>en</strong>.<br />

d. Select the required data type.<br />

e. Enter the l<strong>en</strong>gth and scale.<br />

f. Define the measure by selecting the required measures, operator, and function.<br />

g. Choose Validate.<br />

h. Choose OK.<br />

Note: You can choose to r<strong>en</strong>ame the attributes, calculated attributes, measures, and calculated<br />

measures of the view using the R<strong>en</strong>ame button in the Output panel toolbar. However, r<strong>en</strong>aming a<br />

field can impact other objects that reuse the field as the new name is not reflected in the other<br />

objects.<br />

Optional Step: Creating Counters<br />

To obtain the number of distinct values of an attribute, do the following:<br />

1. In the Output pane, right-click Counters.<br />

2. From the context m<strong>en</strong>u, choose New.<br />

3. Choose Add Attribute.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


4. Choose OK.<br />

Activate<br />

Note:<br />

1. If you set the calculation view property Multidim<strong>en</strong>sional Reporting as disabled, you can<br />

create a calculation view without adding any measure to the calculation view output. A<br />

calculation view without any measure works like an attribute view and is not available for<br />

reporting purposes.<br />

2. You can choose to hide the attributes and measures that are not required for cli<strong>en</strong>t<br />

consumption by assigning value true to the property Hidd<strong>en</strong> in the Properties pane.<br />

3. You can choose to create variables, and bind them to attributes for filtering data. The values<br />

you provide to the variables at runtime determine which data records are selected for<br />

consumption.<br />

4. You can choose to create input parameters for the union, join, projection, aggregation, and<br />

calculation view output. Also, if the calculation view data sources have input parameters, you<br />

can map them to the calculation view input parameters.<br />

5. You can choose to create hierarchy betwe<strong>en</strong> attributes of the view.<br />

6. You can specify a value for the view's Default Cli<strong>en</strong>t property to filter the table data that is<br />

relevant to a specific cli<strong>en</strong>t as specified in the table fields at runtime, such as, MANDT or<br />

CLIENT. The default value for the property is the one that is specified as a prefer<strong>en</strong>ce. If the<br />

property is set to Dynamic, at runtime, the value set for the Session Cli<strong>en</strong>t property is<br />

considered to filter table data. The Session Cli<strong>en</strong>t property is set while creating a user.<br />

a. To activate the view select Save and Activate from the toolbar.<br />

Note:<br />

Note: Activating the curr<strong>en</strong>t view redeploys the impacted objects if an active version of the<br />

impacted objects exist. You can also activate an object from the context m<strong>en</strong>u of the object in<br />

the Navigator panel.<br />

Tip: You can choose to activate the other objects (required or impacted objects) along with<br />

the curr<strong>en</strong>t object using the Save and Activate All from the toolbar.<br />

Note: For more information about activation, see Activating Objects [page 132].<br />

1. For an active calculation view, you can preview the data of an intermediate node in a calculation view,<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

which helps to debug each level of a complex calculation sc<strong>en</strong>ario having join, union, aggregation,<br />

projection, and output nodes. The data you preview for a node is for the active version of the<br />

calculation view. If no active version for the object exists th<strong>en</strong> you need to activate the object first. You<br />

can choose the Data Preview option from the context m<strong>en</strong>u of a node.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 121


Related Links<br />

2. You can choose to g<strong>en</strong>erate docum<strong>en</strong>tation for the calculation view. For more information, see<br />

G<strong>en</strong>erating Object Docum<strong>en</strong>tation [page 144].<br />

Assigning Variables [page 123]<br />

Creating Input Parameters [page 125]<br />

Creating Hierarchies [page 127]<br />

Managing Attribute Mappings [page 122]<br />

Using Curr<strong>en</strong>cy and Unit of Measure [page 130]<br />

Activating Objects [page 132]<br />

Mapping Input Parameters [page 122]<br />

Mapping Input Parameters<br />

You use this procedure to map the input parameters in the underlying data sources (analytic views and<br />

calculation views) of the calculation view to the calculation view parameters. You can:<br />

● Map many data source parameters to one calculation view input parameter.<br />

● Perform a one on one mapping of the data source parameters to the calculation view parameters.<br />

Procedure<br />

1. In the Output pane, select an input parameter.<br />

2. In the context m<strong>en</strong>u, choose Manage Mappings.<br />

3. In the Map Data Source Parameters dialog, map the data source input parameters with the calculation view<br />

parameters.<br />

Note: You can choose the Auto Map by Name option to automatically create the input parameters<br />

corresponding to the source and perform a 1:1 mapping. You can also select a source input parameter<br />

and use the following context m<strong>en</strong>u options:<br />

○ Create New Map 1:1 - to create the same input parameter for the calculation view as for the<br />

source, and create a 1:1 mapping betwe<strong>en</strong> them.<br />

○ Map By Name - to map the source input parameter with the calculation view input parameter<br />

having the same name.<br />

○ Remove Mapping - to delete the mapping betwe<strong>en</strong> the source and calculation view input<br />

parameter.<br />

Managing Attribute Mappings<br />

You use this procedure to map the source attribute to the target attribute if there are a large number of attributes,<br />

or to assign a constant value to the target attribute.<br />

Procedure<br />

1. Right-click the attribute in the target list.<br />

2. From the context m<strong>en</strong>u, choose Manage Mappings.<br />

122<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


a. To map the source to the target column, select the required source from the dropdown list.<br />

b. To assign a default value to the constant column, <strong>en</strong>ter the value in the Constant Value field. For more<br />

information, see Constant Column [page 123].<br />

c. Select the required data type.<br />

d. Enter the l<strong>en</strong>gth and scale as required.<br />

e. Choose OK.<br />

Constant Column<br />

In a union view, a Constant Column is created if there are any target or output attributes for which there are no<br />

mappings to the source attributes. The default value for the constant column is NULL.<br />

Note: The target attribute is mapped to all the sources.<br />

For example, you have two tables with similar structures, Actual Sales and Planned Sales, corresponding to the<br />

sales of products. You want to see the combined data in a single view, but differ<strong>en</strong>tiate betwe<strong>en</strong> the data from the<br />

two tables for comparison. To do so, you can create a union view betwe<strong>en</strong> the two tables and have a constant<br />

column indicating constant values like A & P, as shown below:<br />

Actual Sales<br />

Sales Product<br />

5000 A1<br />

2000 B1<br />

Planned Sales<br />

Sales Product<br />

3000 A1<br />

6000 B1<br />

The result of this query can be as follows:<br />

Actual Planned Indicator Sales Product<br />

A 5000 A1<br />

P 3000 A1<br />

A 2000 B1<br />

P 6000 B1<br />

6.2.8 Assigning Variables<br />

You use this procedure to assign variables to a filter at design time for obtaining data based on the values you<br />

provide for the variable. At runtime, you can provide differ<strong>en</strong>t values to the variable to view the corresponding set<br />

of attribute data. You provide values to the variables either by <strong>en</strong>tering the values manually, or by selecting them<br />

from the Value Help dialog.<br />

Note: You can apply variables to attributes of analytic and calculation views.<br />

The following types of variables are supported:<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 123


Type Description<br />

Single Value Use this to filter and view data based on a single attribute<br />

value. For example, to view the sales of a product where the<br />

month is equal to January.<br />

Interval Use this to filter and view a specific set of data. For example,<br />

to view the exp<strong>en</strong>diture of a company from March to April.<br />

Range Use this to filter and view data based on the conditions that<br />

involve operators such as "="(equal to), ">" (greater than),<br />

"=" (greater than or equal to), and "


a. Enter a name and description.<br />

b. Select the required attribute from the dropdown list.<br />

Note: At runtime, the value for the variable is fetched from the selected attribute's data.<br />

c. Choose the required Selection Type from the dropdown list.<br />

d. If you want to specify a default value that is used to filter attribute data, <strong>en</strong>ter the value in the Default<br />

Value field.<br />

e. Choose OK.<br />

Note: You can also choose to create a variable using the Create Variable option from the context m<strong>en</strong>u of<br />

an attribute. In this case, the details of the variable are pre-filled.<br />

2. Assign a Variable to a Filter<br />

1. On the Output panel, right-click the attribute.<br />

2. In the context m<strong>en</strong>u, choose Apply Filter.<br />

3. In the Operator dropdown list, choose Variable.<br />

4. In the Variable dropdown list, choose the required variable.<br />

5. Choose OK.<br />

Note: You can also choose to create a variable and apply a filter using the Create Variable - Apply Filter<br />

option from the context m<strong>en</strong>u of an attribute.<br />

6.2.9 Creating Input Parameters<br />

Use this procedure to allow you to provide input for the parameters within stored procedures, in order to obtain a<br />

desired functionality wh<strong>en</strong> the procedure is executed.<br />

In an analytic view you use input parameters as placeholders during curr<strong>en</strong>cy conversion and formulas like<br />

calculated columns. Wh<strong>en</strong> used in formulas, the calculation of the formula is based on the input that you provide<br />

at runtime during data preview. Input parameters are not used for filtering attribute data in analytic views that can<br />

be achieved using variables.<br />

In calculation views you can use input parameter during curr<strong>en</strong>cy conversion, calculated measures, input<br />

parameters of the script node, and to filter data as well.<br />

You can apply input parameters in analytic and calculation views. If a calculation view is created using an analytic<br />

view with input parameters, those input parameters are also available in the calculation view but you cannot edit<br />

them.<br />

The following types of input parameters are supported:<br />

Type Description<br />

Attribute Value/ Column Use this wh<strong>en</strong> the value of a parameter comes from an<br />

attribute.<br />

Curr<strong>en</strong>cy (available in Calculation View only) Use this wh<strong>en</strong> the value of a parameter is in a curr<strong>en</strong>cy<br />

format, for example, to specify the target curr<strong>en</strong>cy during<br />

curr<strong>en</strong>cy conversion.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 125


Type Description<br />

Date (available in Calculation View only) Use this wh<strong>en</strong> the value of a parameter is in a date format, for<br />

example, to specify the date during curr<strong>en</strong>cy conversion.<br />

Static List Use this wh<strong>en</strong> the value of a parameter comes from a userdefined<br />

list of values.<br />

Derived From Table (available in Analytic View and Graphical<br />

Calculation View)<br />

Use this wh<strong>en</strong> the value of a parameter comes from a table<br />

column based on some filter conditions and you do not need<br />

to provide any input at runtime.<br />

Empty Use this wh<strong>en</strong> the value of a parameter could be anything<br />

from the selected data type.<br />

Direct Type (available in Analytic View) Use this to specify an input parameter as curr<strong>en</strong>cy and date<br />

during curr<strong>en</strong>cy conversion.<br />

In the case of analytic views, all input parameters are mandatory. However, in the case of calculation views, each<br />

type of input parameter can be either mandatory or non-mandatory. For a mandatory input parameter, it is<br />

necessary to provide a value at runtime. However, for a non-mandatory input parameter, if you do not specify a<br />

value at runtime, the data for the column in which the input parameter is used remains blank.<br />

Note: You can check whether an input parameter is mandatory or not from the properties of the input<br />

parameter in the Properties pane.<br />

Procedure<br />

● If you want to create a formula to analyze the annual sales of a product in various regions, you can use<br />

Year and Region as input parameters.<br />

● If you want to preview a sales report with data for various countries in their respective curr<strong>en</strong>cy for a<br />

Analytic View<br />

particular date for correct curr<strong>en</strong>cy conversion, you can use Curr<strong>en</strong>cy and Date as input parameters.<br />

1. In the Output panel of the Data Foundation or Logical Join node, right-click the Input Parameters node.<br />

Note: You can also create input parameters at the Semantics node level, using the Create Input<br />

Parameter option in the Variables/Input Parameters panel.<br />

2. From the context m<strong>en</strong>u, choose New.<br />

126<br />

a. Enter a name and description.<br />

b. Select the type of input parameter from the Parameter Type dropdown list.<br />

Note:<br />

○ For the Column type of input parameter, you need to select the attribute from the dropdown<br />

list. At runtime the value for the input parameter is fetched from the selected attribute's data.<br />

○ For an input parameter of type Derived from Table, you need to select a table and one of it's<br />

column as Return Column whose value is th<strong>en</strong> used as input for the formula calculation. You<br />

can also define conditions to filter the values of Return Column in the Filters panel. For<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


example, to calculate Discount for specific cli<strong>en</strong>ts, you can create an input parameter based<br />

on Sales table and return column Rev<strong>en</strong>ue with filter set on the Cli<strong>en</strong>t_ID.<br />

○ For Direct Type input parameter, specify the Semantic Type that describes the use parameter<br />

as a curr<strong>en</strong>cy or date, for example, to specify the target curr<strong>en</strong>cy during curr<strong>en</strong>cy conversion.<br />

c. If required, select a data type.<br />

d. Enter l<strong>en</strong>gth and scale for the input parameter.<br />

e. Choose OK.<br />

Calculation View<br />

1. In the Output panel, right-click the Input Parameters node.<br />

2. From the context m<strong>en</strong>u, choose New.<br />

a. Enter a name and description.<br />

b. Select the type of input parameter from the dropdown list.<br />

Note:<br />

c. Select a data type.<br />

○ For the Attribute Value type of input parameter, you need to select the attribute from the<br />

dropdown list. At runtime the value for the input parameter is fetched from the selected<br />

attribute's data.<br />

○ For an input parameter of type Derived from Table, you need to select a table and one of it's<br />

column as Return Column whose value is th<strong>en</strong> used as input for the formula calculation. You<br />

can also define conditions to filter the values of Return Column in the Filters panel. For<br />

example, to calculate Discount for specific cli<strong>en</strong>ts, you can create an input parameter based<br />

on Sales table and return column Rev<strong>en</strong>ue with filter set on the Cli<strong>en</strong>t_ID.<br />

d. Enter l<strong>en</strong>gth and scale for the input parameter.<br />

e. Choose OK.<br />

6.2.10 Creating Hierarchies<br />

You use this procedure to create hierarchies betwe<strong>en</strong> attributes to <strong>en</strong>hance analysis by displaying attributes<br />

according to their defined hierarchical relationships. Hierarchies can exist cross-attributes (that is, Country -<br />

State - City) or within the values of a single attribute (that is, employee manager - employee direct report).<br />

You structure and define relationships betwe<strong>en</strong> attributes in the attribute view and calculation view using the<br />

following hierarchy types:<br />

● Level Hierarchy<br />

A level hierarchy is rigid in nature, and the root and the child nodes can be accessed only in the defined order.<br />

Level hierarchies consist of one or more levels of aggregation. Attributes roll up into the next higher level in a<br />

many-to-one relationship, and members at this higher level roll up into the next higher level, and so on to the<br />

top level.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 127


For example: an address hierarchy comprised of region, country, state, and so on.<br />

● Par<strong>en</strong>t/Child Hierarchy<br />

A par<strong>en</strong>t/child hierarchy is a hierarchy in a standard view that contains a par<strong>en</strong>t attribute. A par<strong>en</strong>t attribute<br />

describes a self-refer<strong>en</strong>cing relationship, or self-join, within the main table. Par<strong>en</strong>t-child hierarchies are<br />

constructed from a single par<strong>en</strong>t attribute.<br />

For example: a bill of materials hierarchy (par<strong>en</strong>t and child) or an employee master (employee and manager)<br />

hierarchy.<br />

Procedure<br />

Creating a Level Hierarchy<br />

1. Select the Semantics node.<br />

2. In the Hierarchies panel, choose Create option .<br />

3. Enter a name and description for the hierarchy.<br />

4. In the Hierarchy Type dropdown, select Level Hierarchy.<br />

5. Select the required value in the Aggregate All Nodes.<br />

Note: This option indicates that data is posted on aggregate nodes and should be shown in the user<br />

interface. For example, if you have the members A with value 100, A1 with value 10, and A2 with value<br />

20 where A1 and A2 are childr<strong>en</strong> of A. By default the value is set to false, and you will see a value of 30<br />

for A.<br />

With the value set to true, you will count the posted value 100 for A as well and see a result of 130.<br />

If you are sure that there is no data posted on aggregate nodes you should set the option to false. The<br />

<strong>en</strong>gine will th<strong>en</strong> calculate the hierarchy faster as wh<strong>en</strong> the option is set.<br />

Note that this flag is only interpreted by the SAP HANA MDX <strong>en</strong>gine. In the BW OLAP <strong>en</strong>gine the node<br />

values are always counted.<br />

6. Enter a value for the default member.<br />

7. Select the required option in the With Root Node dropdown.<br />

Note: If a hierarchy doesn't have a root node but needs one for reporting use case, set the option to<br />

true. This will create a root node.<br />

8. Select the required value from the Node Style dropdown list.<br />

128<br />

Note: Node style determines the composition of a unique node ID. The differ<strong>en</strong>t values for node styles<br />

are as:<br />

○ Level Name - the unique node ID is composed of level name and node name, for example "[Level<br />

2].[B2]".<br />

○ Name Only - the unique node ID is composed of level name, for example "B2".<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


○ Name Path - the unique node ID is composed of the result node name and the names of all<br />

ancestors apart from the (single physical) root node. For example "[A1].[B2]".<br />

9. Add the required attributes from the drop-down list.<br />

Note: You can select attributes from the required table columns in the drop-down list to add to the<br />

view.<br />

10. Select the required Level Type.<br />

11. Choose OK.<br />

Note: The level type is used to specify formatting instructions for the level attributes.<br />

For example, a level of the type LEVEL_TYPE_TIME_MONTHS can indicate that the attributes of the<br />

level should have a text format such as "January", and LEVEL_TYPE_REGULAR indicates that a level<br />

does not require any special formatting.<br />

Creating a Par<strong>en</strong>t/Child Hierarchy<br />

1. Select the Semantics node.<br />

2. In the Hierarchies panel, choose Create option .<br />

3. Enter a name and description for the hierarchy.<br />

4. In the Hierarchy Type dropdown, choose Par<strong>en</strong>t Child Hierarchy.<br />

5. Select the required value in the Aggregate All Nodes.<br />

Note: This option indicates that data is posted on aggregate nodes and should be shown in the user<br />

interface. For example, if you have the members A with value 100, A1 with value 10, and A2 with value<br />

20 where A1 and A2 are childr<strong>en</strong> of A. By default the value is set to false, and you will see a value of 30<br />

for A.<br />

With the value set to true, you will count the posted value 100 for A as well and see a result of 130.<br />

If you are sure that there is no data posted on aggregate nodes you should set the option to false. The<br />

<strong>en</strong>gine will th<strong>en</strong> calculate the hierarchy faster as wh<strong>en</strong> the option is set.<br />

Note that this flag is only interpreted by the SAP HANA MDX <strong>en</strong>gine. In the BW OLAP <strong>en</strong>gine the node<br />

values are always counted.<br />

6. Enter a value for the default member.<br />

7. Select the required option in the With Root Node dropdown.<br />

Note: If a hierarchy doesn't have a root node but needs to have one for reporting use case, set the<br />

option to true. This will create a root node.<br />

8. Select the Par<strong>en</strong>t Node and Child Node from the dropdown list.<br />

9. Choose OK.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 129


Note: The hierarchies belonging to an attribute view are available in an analytic view that reuses the<br />

attribute view, in read-only mode. However, the hierarchies belonging to an attribute view are not available<br />

in a calculation view that reuses the attribute view.<br />

6.2.11 Using Curr<strong>en</strong>cy and Unit of Measure<br />

Use this procedure to define a measure as an amount or weight in the analytical space and to perform curr<strong>en</strong>cy<br />

conversion.<br />

To simplify the process of curr<strong>en</strong>cy conversion, the system provides a list of curr<strong>en</strong>cies, and exchange rates<br />

based on the tables imported for curr<strong>en</strong>cy. Curr<strong>en</strong>cy conversion is performed based on source curr<strong>en</strong>cy, target<br />

curr<strong>en</strong>cy, exchange rate, and date of conversion. You can also select curr<strong>en</strong>cy from the attribute data used in the<br />

view.<br />

For example, you need to g<strong>en</strong>erate a sales report for a region in a particular curr<strong>en</strong>cy, and you have sales data in<br />

database tables in a differ<strong>en</strong>t curr<strong>en</strong>cy. You can create an analytic view by selecting the table column containing<br />

the sales data in this other curr<strong>en</strong>cy as a measure, and perform curr<strong>en</strong>cy conversion. Once you activate the view,<br />

you can use it to g<strong>en</strong>erate reports.<br />

Note: Curr<strong>en</strong>cy conversion is <strong>en</strong>abled for analytic views and base measures of calculation views.<br />

Prerequisites<br />

● You have imported tables T006 and T006A for Unit of Measure.<br />

● You have imported TCURC, TCURF, TCURN, TCURR, TCURT, TCURV, TCURW, and TCURX for curr<strong>en</strong>cy.<br />

Procedure<br />

1. Select a measure.<br />

2. In the Properties pane, select Measure Type.<br />

3. If you want to associate the measure with a curr<strong>en</strong>cy, do the following:<br />

130<br />

a. In the Measure Type dropdown list, select the value Amount with Curr<strong>en</strong>cy.<br />

b. In the Curr<strong>en</strong>cy Dialog, select the required Type as follows:<br />

Type Purpose<br />

Fixed To select curr<strong>en</strong>cy from the curr<strong>en</strong>cy table TCURC.<br />

Attribute To select curr<strong>en</strong>cy from one of the attributes used in the<br />

view.<br />

c. Select the required value, and choose OK.<br />

d. If you want to convert the value to another curr<strong>en</strong>cy, choose Enable for Conversion.<br />

a. To select the source curr<strong>en</strong>cy, choose Curr<strong>en</strong>cy.<br />

b. Select the target curr<strong>en</strong>cy.<br />

Note: For curr<strong>en</strong>cy conversion, in addition to the types Fixed and Attribute, you can select an<br />

Input Parameter to provide target curr<strong>en</strong>cy at runtime. If you select an input parameter for<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


specifying target curr<strong>en</strong>cy and deselect Enable for Conversion checkbox, the target curr<strong>en</strong>cy<br />

field is cleared because input parameters can be used only for curr<strong>en</strong>cy conversion.<br />

c. To specify exchange rate type, in the Exchange Rate Types dialog, select the Type as follows:<br />

Type Purpose<br />

Fixed To select exchange rate from the curr<strong>en</strong>cy table<br />

TCURW.<br />

Input Parameter To provide exchange rate input at runtime as input<br />

parameter.<br />

d. To specify the date for curr<strong>en</strong>cy conversion, in the Conversion Date dialog, select the Type as follows:<br />

Type Purpose<br />

Fixed To select conversion date from the cal<strong>en</strong>dar.<br />

Attribute To select conversion date from one of the attributes<br />

used in the view.<br />

Input Parameter To provide conversion date input at runtime as input<br />

parameter.<br />

e. To specify the schema where curr<strong>en</strong>cy tables are located for conversion, in the Schema for curr<strong>en</strong>cy<br />

conversion, select the required schema.<br />

f. To specify the cli<strong>en</strong>t for which the conversion rates to be looked for, in the Cli<strong>en</strong>t for curr<strong>en</strong>cy<br />

conversion, select the required option.<br />

e. From the dropdown list, select the required value that is used to populate data if the conversion fails:<br />

Option Result<br />

Fail In data preview, the system displays an error for<br />

conversion failure.<br />

Set to NULL In data preview, the value for the corresponding records<br />

is set to NULL.<br />

Ignore In data preview, you view the unconverted value for the<br />

corresponding records.<br />

4. If you want to associate a measure with a unit of measure other than curr<strong>en</strong>cy, do the following:<br />

a. Select the value Quantity with Unit of Measure in the Measure Type dropdown list.<br />

b. In the Quantity Units dialog , select the required Type as follows:<br />

Type Purpose<br />

Fixed To select a unit of measure from the unit tables T006<br />

and T006A.<br />

Attribute To select a unit of measure from one of the attributes<br />

used in the view.<br />

c. Select the required value, and choose OK.<br />

5. Choose OK.<br />

Note: You can associate curr<strong>en</strong>cy or unit of measure with a calculated measure, and perform curr<strong>en</strong>cy<br />

conversion for a calculated measure by editing it.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 131


6.2.12 Activating Objects<br />

You activate objects available in your workspace to expose the objects for reporting and analysis. Based on your<br />

requirem<strong>en</strong>ts, you can do the following:<br />

● Activate - Deploys the inactive objects.<br />

● Redeploy - Deploys the active objects in one of the following sc<strong>en</strong>arios:<br />

○ If your runtime object gets corrupted or deleted, and you want to create it again.<br />

○ If an object goes through cli<strong>en</strong>t-level activation and server-level activation but fails at MDX, and the object<br />

status is still active.<br />

The following activation modes are supported:<br />

● Activate and ignore the inconsist<strong>en</strong>cies in impacted objects - To activate the selected objects ev<strong>en</strong> if it results<br />

in inconsist<strong>en</strong>t impacted objects. For example, if you choose to activate an object A that is used by B and C,<br />

and it causes inconsist<strong>en</strong>cies in B and C but you can choose to go ahead with the activation of A. This is the<br />

default activation mode.<br />

● Stop activation in case of inconsist<strong>en</strong>cies in impacted objects - To activate the selected objects only if there<br />

are no inconsist<strong>en</strong>t impacted objects.<br />

Note: Irrespective of the activation mode, if ev<strong>en</strong> one of the selected objects fails (either during validation<br />

or during activation), the complete activation job will fail and none of the selected objects will be activated.<br />

Dep<strong>en</strong>ding on where you invoke the activation, redeploym<strong>en</strong>t or cascade activation, the behavior is as follows:<br />

Context Activate Redeploy<br />

Quick Launch tab page A dialog box appears with a preselected<br />

list of all your inactive objects.<br />

Package context m<strong>en</strong>u A dialog box appears with a preselected<br />

list of all your inactive objects.<br />

Cont<strong>en</strong>t context m<strong>en</strong>u A dialog box appears with a preselected<br />

list of all your inactive objects.<br />

Editor ● If you select Save and Activate,<br />

curr<strong>en</strong>t object is activated and the<br />

impacted objects are redeployed if<br />

an active version for the impacted<br />

objects exist.<br />

● If you select Save and Activate All, a<br />

dialog box appears with a<br />

preselected list of the selected<br />

object along with all the required<br />

and impacted objects.<br />

Object context m<strong>en</strong>u A dialog box appears with a preselected<br />

list of the selected object along with all<br />

the required objects.<br />

132<br />

Note:<br />

A dialog box appears with a list of active<br />

objects in your workspace.<br />

A dialog box appears with a list of active<br />

objects in your workspace.<br />

Not applicable<br />

Not applicable<br />

A redeploym<strong>en</strong>t job is submitted for the<br />

selected object.<br />

● If an object is the only inactive object in the workspace, the activation dialog box is skipped and the<br />

activation job is submitted.<br />

● If an object is inactive and you want to revert back to the active version, from the editor or object<br />

context m<strong>en</strong>u, choose Revert To Active.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


● In the Activate dialog, you can select the Bypass validation checkbox in order to skip validation before<br />

activation to improve the activation time. For example, if you have imported a number of objects and<br />

want to activate them without sp<strong>en</strong>ding time on validation.<br />

Note: During delivery unit import, full server side activation is <strong>en</strong>abled, activation of objects after import is<br />

done. In this case all the imported objects are activated (moved to active table), ev<strong>en</strong> if there are errors in<br />

activated or impacted objects. But the objects for which activation results in error are considered as<br />

brok<strong>en</strong> or inconsist<strong>en</strong>t objects which means that the curr<strong>en</strong>t runtime repres<strong>en</strong>tation of these objects is<br />

not in sync with the active design time version. The brok<strong>en</strong> objects are shown in the Navigator with an ‘x’<br />

along side.<br />

Note: The behavior of activation job is as follows:<br />

● The status (completed, completed with warnings, and completed with errors) of the activation job<br />

indicates whether the activation of the objects is successful or failed.<br />

● In case of failure that is wh<strong>en</strong> the status is completed with errors, the process is rolled back. This<br />

means, ev<strong>en</strong> if there are individual objects successfully activated, since the activation job is rolled<br />

back, none of the objects are activated.<br />

● Ev<strong>en</strong> in case of failure, the job log shows success in the summary part. This is to help the user to<br />

indicate that those objects were successfully activated without any issues. But because the <strong>en</strong>tire job<br />

is a failure, none of the objects are activated and all of them are rolled back.<br />

● Wh<strong>en</strong> you op<strong>en</strong> the job log, the summary list shows only those objects that are submitted for<br />

activation. It does not list all the affected objects. They are listed only in detail section.<br />

6.3 Creating Decision Tables<br />

You use this procedure to create a decision table to model related business rules in a tabular format for decision<br />

automation. Using decision tables you can manage business rules, data validation, data quality rules without any<br />

IT knowledge on technical languages like, SQL Script, MDX . A data architect or a <strong>dev</strong>eloper creates the decision<br />

table and activates it. The active version of the decision table can be used in applications.<br />

Procedure<br />

1. Set Parameters<br />

1. In the Modeler perspective, expand Cont<strong>en</strong>t .<br />

2. In the context m<strong>en</strong>u of the package, choose New Decision Table .<br />

3. In the New Decision Table dialog box, <strong>en</strong>ter a name and description for the decision table.<br />

4. To create data foundation for the decision table, perform substeps of the required sc<strong>en</strong>ario giv<strong>en</strong> in the table<br />

below:<br />

Sc<strong>en</strong>ario Substeps<br />

Create a decision table from scratch. 1. Choose Create New.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

2. Choose Next.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 133


Sc<strong>en</strong>ario Substeps<br />

Note: If you launch the New Decision Table<br />

dialog from the Quick Launch tab page,<br />

specify the package where you want to save<br />

the decision table.<br />

3. Add the required tables, table type or an information<br />

view to the Selected list.<br />

4. Choose Finish.<br />

Create a decision table from an existing decision table. 1. Choose Copy From.<br />

Note:<br />

Note: You can choose to add the required<br />

data sources to the decision table later by<br />

dragging them from the Catalog node in the<br />

Navigator panel to the Data Foundation<br />

panel.<br />

Note: If you launch the New Decision Table<br />

dialog from the Quick Launch page, specify<br />

the package where you want to save the<br />

decision table.<br />

2. Select the required decision table.<br />

3. Choose Finish.<br />

○ Only an active version of an information view can be used. Any changes made to the information<br />

view are not reflected in the decision table.<br />

○ You can create a decision table using an analytic view only if it has a calculated attribute.<br />

○ If you create a decision table using an analytic view, the analytic view must have a calculated<br />

attribute.<br />

2. Create Joins<br />

○ If you choose to create a decision table based on a table type or an information view, you cannot<br />

add any other data source. This implies that a decision table can be based on multiple tables or a<br />

table type or an information view.<br />

○ You can add only one table type or information view to the data foundation.<br />

○ You can mark table type columns and information view columns only as conditions.<br />

1. If you want to define a relationship betwe<strong>en</strong> tables to query data from two or more tables, do the following:<br />

134<br />

a. In the editor pane, from the context m<strong>en</strong>u, choose Create Join.<br />

b. In the Create Join dialog, select the required tables, columns, join type, and cardinality.<br />

c. Choose Create Join.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Note: You can also create a join betwe<strong>en</strong> table columns by dragging it from one table column to<br />

another table column. The supported join types are inner, left outer and right outer.<br />

3. Add Conditions and Actions<br />

1. In the Data Foundation view, select the required column, and perform substeps of the required sc<strong>en</strong>ario giv<strong>en</strong><br />

in the table below:<br />

Sc<strong>en</strong>ario Substeps<br />

Include table field in the output structure. From the context m<strong>en</strong>u, choose Add as Attribute.<br />

Note: Attributes contains a subset of columns<br />

that you use to derive conditions and actions.<br />

Add conditions based on which you want to derive actions. 1. In the Output view, select the required attributes .<br />

2. From the context m<strong>en</strong>u, choose Add as Conditions.<br />

Add actions for the selected conditions. 1. In the Output view, select the required attributes .<br />

2. To add condition values, do the following:<br />

2. From the context m<strong>en</strong>u, choose Add as Actions.<br />

a. In the Decision Table view, right-click a condition, and choose Add Conditions Values.<br />

Note: The supported data types for an operator are:<br />

Operator Supported Data Types Syntax<br />

Not Equal To Number & CHAR-based != ABC<br />

In Number & Char-based In ABC;CDA<br />

Not In Number & Char-based Not In A;B;C<br />

Like CHAR-based Like Abc*<br />

Not Like CHAR-based Not Like Abc*<br />

Greater Than<br />

Greater Than or Equals<br />

Less Than<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

Less Than or Equals<br />

Number & CHAR-based >20<br />

>=20<br />

Number & CHAR-based


Operator Supported Data Types Syntax<br />

< 2012-12-12<br />

After Date Dates After 2012-12-12<br />

Or<br />

> 2012-12-12<br />

Betwe<strong>en</strong> Date Dates Betwe<strong>en</strong> 2012-12-12 and<br />

b. Enter a value, and choose OK.<br />

Note:<br />

2012-12-25<br />

○ If a database table column is used as condition, you can use the value help dialog to select the<br />

condition values. You can select multiple values at one time. You can edit a condition value by<br />

selecting the condition, and <strong>en</strong>tering a value.<br />

○ You can <strong>en</strong>ter a pattern for the condition values having data type as VARCHAR. The pattern<br />

must be prefixed with the LIKE and NOT LIKE operators. For example, LIKE a*b or NOT LIKE<br />

a?b. If the LIKE or NOT LIKE operator is not pres<strong>en</strong>t the pattern is treated as a string<br />

3. To set action values, right-click an action cell, and <strong>en</strong>ter value.<br />

4. If you want to write a complex expression as action value, do the following:<br />

a. Right-click the action field.<br />

b. From the context m<strong>en</strong>u, choose Set Dynamic Value.<br />

c. Write the expression for example, PRICE-(PRICE*0.1).<br />

d. To edit a value you need to select that value.<br />

Note: You can use parameters and table columns of the same data type as that of the action in<br />

expressions.<br />

5. To assign a value to a condition or an action based on the table data, choose Op<strong>en</strong> Value Help Dialog, and do<br />

136<br />

the following:<br />

a. In the Value Help for Column dialog, <strong>en</strong>ter the search string, and choose Find.<br />

Note: If you do not provide a value for search and choose Find, all the data corresponding to the<br />

selected column is shown.<br />

b. Select a value, and choose OK.<br />

Remember:<br />

● You can provide an alias name to a condition or an action by editing the value of Alias name property.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


● You can choose to create parameters and use them as conditions or actions. The values you provide<br />

to the parameters at the runtime determine which data records are selected for consumption. For<br />

more information regarding how to use parameters, Using Parameters in a Decision Table [page<br />

139].<br />

● You can export decision table data to an excel sheet using context m<strong>en</strong>u option Export Data to Excel in<br />

the Decision Table view. You can also import decision table data from an excel using context m<strong>en</strong>u<br />

option Import Data from Excel in the Decision Table view.<br />

● You can arrange the condition and action columns of the decision table dep<strong>en</strong>ding on how you want<br />

them to appear. For more information, see Changing the Layout of a Decision Table [page 139].<br />

6. Optional Step: Validate Decision Table<br />

1. To set the rules that you want to use for validation do the following:<br />

a. Choose Window Prefer<strong>en</strong>ces .<br />

b. In the Prefer<strong>en</strong>ces dialog box, expand Modeler Validation Rules .<br />

c. In the Validation Rules view, select Decision Table checkbox to check for all the rules during validation.<br />

d. If you want to check for individual rules, select the required rules.<br />

e. Choose OK.<br />

2. In the decision table editor, choose Validate in the editor toolbar .<br />

Note: In the Job Log section, you can see the validation status and detailed report of the decision table<br />

7. Activate Decision Table<br />

1. Choose File Save .<br />

2. From the context m<strong>en</strong>u of the decision table, choose Activate.<br />

Note: You can choose to save and activate the view from the editor using .<br />

Result: On successful activation, a procedure corresponding to the decision table is created in _SYS_BIC schema.<br />

The name of the procedure is in the format, /. In addition, if a parameter<br />

is used as an action in the decision table, the corresponding table type is created in _SYS_BIC schema. The name<br />

of the table type is in the format, //TT.<br />

Remember: If in a decision table, parameters are used as conditions th<strong>en</strong> corresponding IN parameters<br />

are g<strong>en</strong>erated. Also, if the parameters are used as actions th<strong>en</strong> an OUT parameter is g<strong>en</strong>erated.<br />

8. Execute Decision Table Procedure<br />

1. To execute the decision table procedure perform the following steps as required:<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 137


Data Source Condition Action Script<br />

Physical tables Physical table<br />

column<br />

Physical table<br />

column<br />

Physical tables Parameters Physical table<br />

Physical tables Physical table<br />

column<br />

column<br />

call ""."";<br />

call "".""(,…,);<br />

Parameters call "".""(?);<br />

Physical tables Parameters Parameters call "".""(,…,,?);<br />

View attributes Parameters call "".""(?);<br />

Parameters Parameters call "".""(,…,,?);<br />

Parameters call "".""(?);<br />

Table Type Parameters Parameters call "".""(,…,,?);<br />

Tip: You can view the procedure name using the Op<strong>en</strong> Definition context m<strong>en</strong>u option on the selected<br />

procedure.<br />

Result: On execution of the procedure, the physical table data is updated (if no parameters are used) based on the<br />

data that you <strong>en</strong>ter in the form of condition values and action values.<br />

Remember: If parameters are being used as actions in a decision table, the physical table is not updated.<br />

9. Data Preview<br />

To preview the populated data in the decision table, in the Decision Table editor, from the toolbar, choose Op<strong>en</strong><br />

Data Preview.<br />

138<br />

Restriction: Data preview is supported only if:<br />

● A decision table is based on physical tables and has at least one parameter as action.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


● A decision table is based on information views and parameter(s) as action.<br />

6.3.1 Changing the Layout of a Decision Table<br />

Use this procedure to change the decision table layout by arranging the condition and action columns. By default,<br />

all the conditions appear as vertical columns in the decision table. You can choose to mark a condition as a<br />

horizontal condition, and view the corresponding values in a row. The evaluation order of the conditions is such<br />

that first the horizontal condition is evaluated and th<strong>en</strong> the vertical ones.<br />

Note: You can only change the layout of a decision table if it has more than one condition. You can select<br />

only one condition as horizontal condition.<br />

Procedure<br />

1. In the context m<strong>en</strong>u of the Decision Table editor, choose Change Layout.<br />

2. If you want to view a condition as a horizontal condition, in the Change Decision Table Layout dialog, select<br />

Table has Horizontal Condition (HC) checkbox.<br />

Note: By default the first condition in the list of conditions is marked as horizontal.<br />

3. In the Conditions and Actions sections, choose options on the right-hand side of the dialog box to arrange the<br />

conditions and actions in the desired sequ<strong>en</strong>ce.<br />

4. Choose OK.<br />

5. Save the changes.<br />

Note: The available options to arrange the conditions in a sequ<strong>en</strong>ce are:<br />

○ Move Condition to Top<br />

○ Move Condition Up<br />

○ Move Condition Down<br />

○ Move Condition to Bottom<br />

Note: You can also set a condition as horizontal from the context m<strong>en</strong>u of the condition in the Output view.<br />

You can also arrange the conditions and actions in the desired sequ<strong>en</strong>ce in the Output view using the<br />

respective buttons.<br />

6.3.2 Using Parameters in a Decision Table<br />

You use this procedure to create a parameter that can be used to simulate a business sc<strong>en</strong>ario. You can use<br />

parameters as conditions and actions in the decision table at design time. Parameters used as conditions,<br />

determine the set of physical table rows to be updated based on the condition value that you provide at runtime<br />

during procedure call. Parameters used as actions, simulate the physical table without updating to it.<br />

The following parameter types are supported:<br />

Type Description<br />

Static List Use this wh<strong>en</strong> the value of a parameter comes from a userdefined<br />

list of values.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 139


Type Description<br />

Empty Use this wh<strong>en</strong> the value of a parameter could be anything of<br />

the selected data type.<br />

Procedure<br />

Consider a sales order physical table with column headers as follows:<br />

ID Name Supplier Model Price Quantity<br />

If you want to evaluate Discount based on the Quantity and Order Amount, you can create two<br />

parameters, Order Amount and Discount. Use Quantity and Order Amount as the condition, and Discount<br />

as the action. The sample decision table could be:<br />

Quantity Order Amount Discount<br />

>5 50000 10<br />

>=10 100000 15<br />

1. Create a Parameter<br />

1. In the Output pane, right-click the Parameters node.<br />

2. From the context m<strong>en</strong>u, choose New and do the following:<br />

a. Enter a name and description.<br />

b. Select the required data type from the dropdown list.<br />

c. Enter the l<strong>en</strong>gth and scale as required.<br />

d. Choose the required Type from the dropdown list.<br />

e. Choose OK.<br />

Note: If you have selectedStatic List for Type, choose Add in the List of Values section to add<br />

values. You can also provide an alias for the <strong>en</strong>umeration value.<br />

2. Use Parameter as Condition or Action<br />

1. In the Output pane, expand the Parameters node.<br />

2. Right-click a parameter, choose Add As Conditions/ Add as Actions.<br />

6.4 Managing Object Versions<br />

6.4.1 Switching Ownership of Inactive Objects<br />

Use this procedure to take over the ownership of the inactive version of an object from other users' workspace.<br />

140<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Objects in edit mode in other workspaces are not available for modification. In order to modify such objects you<br />

need to own the inactive object.<br />

The options available for changing the inactive object ownership are as follows:<br />

Option Purpose<br />

Switch Ownership To take over multiple inactive objects from other users.<br />

Inactive objects that do not have an active version are also<br />

available for take over using this option<br />

Take Over To take a single inactive object from another workspace that<br />

you wish to edit using the editor.<br />

Note: Using this functionality you can only own the inactive version of the object. The active version is<br />

owned by the user who created and activated the object.<br />

Prerequisite<br />

You have obtained the Work in Foreign Workspace authorization.<br />

Procedure<br />

1. If you want to own multiple inactive objects from other workspaces, do the following:<br />

a. In the Quick Launch page, choose Switch Ownership.<br />

b. In the Source User field, select the user who owns the inactive objects.<br />

c. Add the required inactive objects to the Selected Models section.<br />

d. Choose OK.<br />

2. If an object op<strong>en</strong>s in read-only mode and you want to edit it, do the following:<br />

a. In the editor toolbar, select Switch Version.<br />

b. Choose Take Over.<br />

Note: You can choose to save the changes made by the other user (previous owner of the inactive<br />

version) to the inactive version of the object.<br />

6.4.2 Toggling Versions of Cont<strong>en</strong>t Objects<br />

You use this procedure to view the active version of an information object while working with its inactive version<br />

for example, to view the changes made to the active version.<br />

Procedure<br />

1. In the Modeler perspective, expand the Cont<strong>en</strong>t node of the required system.<br />

2. Select the required object from a package.<br />

3. From the context m<strong>en</strong>u, choose Op<strong>en</strong>.<br />

4. In the editor pane, choose Show Active Version.<br />

5. Compare the inactive and active versions of the object.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 141


6. Choose OK.<br />

6.4.3 Viewing Version History of Cont<strong>en</strong>t Objects<br />

You use this procedure to view the version details of an information model for tracking purposes.<br />

Procedure<br />

1. In the Modeler perspective, expand the Cont<strong>en</strong>t node of the required system.<br />

2. Select the required object from a package.<br />

3. From the context m<strong>en</strong>u, choose History.<br />

6.5 Working with Objects<br />

6.5.1 Managing Layout<br />

You use this procedure to adjust the data foundation and logical view layout comprising user interface controls<br />

like, tables and attribute views in a more readable manner. This functionality is supported for attribute views and<br />

analytic views.<br />

The options available are as follows:<br />

Option Purpose Substeps<br />

Auto Arrange Use this option to arrange the user<br />

interface elem<strong>en</strong>ts automatically.<br />

Show outline Use this option to view an outline of the<br />

elem<strong>en</strong>ts arranged so that , you do not<br />

have to navigate in the editor using<br />

horizontal and vertical scrollbars.<br />

Highlight related tables Use this option if you want to view only<br />

those tables that are related to a table<br />

selected in the editor.<br />

Display Use this option if you have a table with a<br />

large number of columns in the editor,<br />

and you want to view them in a way that<br />

meets your needs: for example, only the<br />

table name, or only joined columns, or<br />

the expanded form with all the columns.<br />

6.5.2 Filtering Packages and Objects<br />

In the editor tool bar, choose .<br />

In the editor tool bar, choose .<br />

1. In the editor, right-click the<br />

selected table.<br />

2. From the context m<strong>en</strong>u, choose<br />

Highlight related tables.<br />

1. In the editor, right-click the relevant<br />

table.<br />

2. From the context m<strong>en</strong>u, choose<br />

Display.<br />

3. If you want to view only the table<br />

name, choose Collapsed.<br />

4. If you want to view all the columns<br />

of the table, choose Expanded.<br />

5. If you want to view only the joined<br />

columns of the table, choose Joins<br />

only.<br />

You use this procedure to filter the cont<strong>en</strong>t, and view packages and objects that you want to work with. If you<br />

apply a filter at the package level, all the packages including subpackages that satisfies the search criteria are<br />

142<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


shown. You can apply a filter for packages only on the Cont<strong>en</strong>t node in the Navigator panel. You can apply a filter<br />

for objects at the package level including subpackages.<br />

Applying Filter for Packages<br />

1. In the Navigator pane, select the Cont<strong>en</strong>t node.<br />

2. In the context m<strong>en</strong>u, choose Filter Packages....<br />

3. In the Filter Packages dialog, <strong>en</strong>ter the filter text.<br />

4. If you want to search for the exact word writt<strong>en</strong> in the filter text, select Match whole word checkbox.<br />

5. Choose OK.<br />

Note: If a filter already exists on the Cont<strong>en</strong>t node, the new filter will overwrite the existing one. You can<br />

also apply the previous filter on the Cont<strong>en</strong>t using Apply Filter '' option.<br />

Applying Filter for Objects<br />

1. In the Navigator pane, expand the Cont<strong>en</strong>t node.<br />

2. In the context m<strong>en</strong>u of a package, choose Filter Objects....<br />

3. In the Filter Objects dialog, <strong>en</strong>ter the filter text.<br />

4. If you want to search for the exact word writt<strong>en</strong> in the filter text, select Match whole word checkbox.<br />

5. If you want to apply the filter on the subpackages, choose Apply filter to sub packages checkbox.<br />

○ If you want to apply a filter only if no filter already exists on the selected package or otherwise retain the<br />

existing filter, choose Apply only if no filter already exists.<br />

○ If you want to apply filter ev<strong>en</strong> if there is an existing filter, choose Apply to all and overwrite existing.<br />

6. Choose OK.<br />

Note: If a filter already exists on the package, the new filter will overwrite the existing one.<br />

6.5.3 Refactoring Objects<br />

You use this procedure to restructure your cont<strong>en</strong>t objects in the Navigator without changing their behavior. As<br />

you move the objects, their refer<strong>en</strong>ces are automatically adjusted. Objects available for refactoring are, packages,<br />

attribute views, analytic views, graphical calculation views, and analytic privileges.<br />

The activation state of the objects from source package to target package is maintained as follows:<br />

At Source At Target<br />

Base Object- active<br />

Impacted Object- active<br />

Base Object- inactive<br />

Impacted Object- inactive<br />

Base Object- active<br />

Impacted Object- active<br />

Base Object- inactive<br />

Impacted Object- inactive<br />

Base Object- active Base Object- active<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 143


At Source At Target<br />

Impacted Object- inactive Impacted Object- active<br />

Base Object- inactive<br />

Impacted Object- active<br />

Base Object- inactive<br />

Impacted Object- inactive<br />

Note: An impacted object (also known as affected object) is the one that uses the base object. For<br />

example, an analytic view using an attribute view is called impacted object for that attribute view.<br />

1. Op<strong>en</strong> the Modeler perspective.<br />

2. Expand the Cont<strong>en</strong>t node.<br />

3. Select the required objects, in the context m<strong>en</strong>u, choose Refactor Move .<br />

4. In the Move dialog, select the target package where you want to move the package/objects, and choose Next.<br />

5. If you want to skip the movem<strong>en</strong>t of objects/packages, in the Changes to be performed panel, deselect them.<br />

6. Choose Finish.<br />

6.5.4 Validating Models<br />

You use this procedure to check if there are any errors in an information object and if the object is based on the<br />

rules that you specified as part of prefer<strong>en</strong>ces. For example, the "Check join: SQL" rule checks that the join is<br />

correctly formed.<br />

For more information about setting prefer<strong>en</strong>ces, see Setting Prefer<strong>en</strong>ces for Modeler .<br />

Procedure<br />

1. On the Quick Launch page, choose Validate.<br />

2. From the Available list, select the required models that system must validate.<br />

3. Choose Add.<br />

4. Choose Validate.<br />

6.5.5 G<strong>en</strong>erating Object Docum<strong>en</strong>tation<br />

Use this procedure to capture the details of an information model or a package in a single docum<strong>en</strong>t. This helps<br />

you view the necessary details from the docum<strong>en</strong>t, instead of referring to multiple tables. The following table<br />

specifies the details that you can view from the docum<strong>en</strong>t.<br />

Type Description<br />

Attribute View G<strong>en</strong>eral object properties, attributes, calculated attributes,<br />

data foundation joins, cross refer<strong>en</strong>ces, and where-used<br />

Analytic View G<strong>en</strong>eral object properties, private attributes, calculated<br />

attributes, attribute views, measures, calculated measures,<br />

restricted measures, variables, input parameters, data<br />

foundation joins, logical view joins, cross refer<strong>en</strong>ces, and<br />

where-used<br />

144<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Type Description<br />

Calculation View G<strong>en</strong>eral object properties, attributes, calculated attributes,<br />

measures, calculated measures, counters, variables, input<br />

parameters, calculation view SQL script, cross refer<strong>en</strong>ces,<br />

and where-used<br />

Package Sub-packages, g<strong>en</strong>eral package properties, and list of<br />

cont<strong>en</strong>t objects<br />

Procedure<br />

1. From the Quick Launch page, choose Auto Docum<strong>en</strong>tation.<br />

2. In the Select Cont<strong>en</strong>t Type field, select one of the following options as required:<br />

Option Description<br />

Model Details To g<strong>en</strong>erate docum<strong>en</strong>tation for models such as attribute,<br />

analytic, and calculation views.<br />

Model List To g<strong>en</strong>erate docum<strong>en</strong>tation for packages.<br />

3. Add the required objects to the Target list.<br />

4. Browse the location where you want to save the file.<br />

5. Choose Finish.<br />

6.5.6 Enabling Multilanguage Support for Objects<br />

You use this procedure to <strong>en</strong>able translation of text pertaining to objects and their elem<strong>en</strong>ts that did not have<br />

multilanguage support.<br />

For example, you can <strong>en</strong>able multilanguage support for models along with their elem<strong>en</strong>ts like attributes and<br />

measures in differ<strong>en</strong>t languages.<br />

Procedure<br />

1. From the Quick Launch tab page, choose Migrate.<br />

2. Select the required objects.<br />

3. Choose Add.<br />

4. Choose OK.<br />

Result<br />

Object texts along with the corresponding elem<strong>en</strong>ts are flagged for translation. These objects can be viewed in<br />

multiple languages provided that the object texts are translated.<br />

6.5.7 Checking Model Refer<strong>en</strong>ces<br />

You use this procedure to id<strong>en</strong>tify whether an information model is refer<strong>en</strong>ced by any other information model(s).<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 145


Procedure<br />

1. In the Modeler perspective, expand the system node in the Navigator pane.<br />

2. Expand the Cont<strong>en</strong>t node.<br />

3. Expand the required package node.<br />

4. Select the required object.<br />

5. From the context m<strong>en</strong>u, choose Where Used.<br />

6.5.8 Viewing the Job Log<br />

The job log displays information related to requests <strong>en</strong>tered for a job. A job log consists of two tab pages as<br />

follows:<br />

● Curr<strong>en</strong>t: Lists all waiting, running, and last five jobs.<br />

● History: Lists all the jobs.<br />

Note: You can terminate the job only if it is in the waiting state.<br />

You can perform the following operations using the job log:<br />

● Op<strong>en</strong> Job Details: Use this to view the job summary in the curr<strong>en</strong>t tab page.<br />

● Op<strong>en</strong> Job Log File: Use this to view the information pertaining to a job in detail using the internal<br />

browser.<br />

● Clear Log Viewer: Use this to delete all the job from the curr<strong>en</strong>t tab page.<br />

● Export Log File: Use this to export the log file to a target location other than the default location for<br />

further refer<strong>en</strong>ce.<br />

● Delete Job: Use this to delete single job from the curr<strong>en</strong>t tab page.<br />

6.5.9 Maintaining Search Attributes<br />

You use this procedure to <strong>en</strong>able an attribute search for an attribute used in a view. Various properties related to<br />

attribute search are as follows:<br />

● Freestyle Search: Set to True if you want to <strong>en</strong>able the freestyle search for an attribute. You can exclude<br />

attributes from freestyle search by setting the property to False.<br />

● Weights for Ranking: To influ<strong>en</strong>ce the relevancy of items in the search results list, you can vary the weighting<br />

of the attribute. You can assign a higher or lower weighting (range 0.0 to 1.0). The higher the weighting of the<br />

attribute, the more influ<strong>en</strong>ce it has in the calculation of the relevance of an item. Items with a higher relevance<br />

are located higher up the search results list. Default value: 0.5.<br />

Note: To use this setting the property Freestyle Search must be set to True.<br />

● Fuzziness Threshold: This parameter is reserved for the future usage of the fault-tolerant search..<br />

Note: It is recomm<strong>en</strong>ded to use the default values for ranking and fuzziness at the beginning. You can finetune<br />

the search settings based on the experi<strong>en</strong>ce gained using the search. You can also fine-tune the<br />

search using feedback collected from your users.<br />

6.5.10 Previewing Data of Cont<strong>en</strong>t Objects<br />

You use this procedure to preview the cont<strong>en</strong>t of cont<strong>en</strong>t models for analysis purposes.<br />

1. In the Modeler perspective, expand the Cont<strong>en</strong>t node of the required system.<br />

2. Select the object from a package for which you want to view the cont<strong>en</strong>t.<br />

146<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


3. From the context m<strong>en</strong>u, choose Data Preview.<br />

The system displays the cont<strong>en</strong>t in differ<strong>en</strong>t formats as shown in the table below.<br />

Tab Page Displays…<br />

Raw Data All attributes along with data in a table format.<br />

Distinct values All attributes along with data in a graphical format.<br />

Analysis All attributes and measures in a graphical format.<br />

Tip: If there are inconsist<strong>en</strong>cies in runtime information (that is, calculation views in catalog or in tables<br />

related to runtime) of a view, you might get invalidated view error. In such cases, you need to<br />

redeploy the view in order to correct the inconsist<strong>en</strong>cies with runtime information.<br />

4. Navigate to the required tab page and view the cont<strong>en</strong>t.<br />

6.5.11 Functions used in Expressions<br />

This topic covers the functions that you can use while creating expressions like, calculated attributes and<br />

calculated measures.<br />

Conversion Functions<br />

Function Syntax Purpose Example<br />

int int int(arg) convert arg to int type int(2)<br />

float float float(arg) convert arg to float type float(3.0)<br />

double double double (arg) convert arg to double type double(3)<br />

sdfloat sdfloat sdfloat (arg) convert arg to sdfloat type<br />

decfloat decfloat decfloat (arg) convert arg to decfloat type<br />

fixed fixed fixed (arg, int, int) arg2 and arg3 are the<br />

intDigits and fractdigits<br />

parameters, respectively.<br />

Convert arg to a fixed type of<br />

either 8, 12, or 16 byte l<strong>en</strong>gth,<br />

dep<strong>en</strong>ding on intDigits and<br />

fractDigits<br />

string string string (arg) convert arg to string type<br />

raw raw raw (arg) convert arg to raw type<br />

date date date(stringarg)<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

date date(fixedarg)<br />

date date(int, int)<br />

date date(int, int, int)<br />

date date(int, int, int, int)<br />

convert arg to date type. The<br />

first version parses a string in<br />

the format "yyyy-mm-dd<br />

hh:mi:ss" where trailing<br />

compon<strong>en</strong>ts except for the<br />

year may be omitted. The<br />

version with one fixed<br />

number arg strips digits<br />

fixed(3.2, 8, 2) + fixed(2.3, 8,<br />

3)<br />

date(2009) -> date('2009')<br />

date(2009, 1, 2) -><br />

date('2009-01-02')<br />

date(fixed(20000203135026<br />

.1234567, 10, 4)) -><br />

date('2000-02-03 13:50:26')<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 147


Function Syntax Purpose Example<br />

date date(int, int, int, int, int)<br />

date date(int, int, int, int, int,<br />

int)<br />

longdate longdate longdate(stringarg)<br />

longdate longdate(fixedarg)<br />

longdate longdate(int, int, int)<br />

longdate longdate(int, int, int,<br />

int, int)<br />

longdate longdate(int, int, int,<br />

int, int, int)<br />

longdate longdate(int, int, int,<br />

int, int, int, int)<br />

time time time(stringarg)<br />

String Functions<br />

time time(fixedarg)<br />

time time(int, int)<br />

time time(int, int, int)<br />

behind the comma and tries<br />

to make a date from the rest.<br />

The other versions accept the<br />

individual compon<strong>en</strong>ts to be<br />

set.<br />

convert arg to longdate type,<br />

similar to date function<br />

above.<br />

convert arg to time type,<br />

similar to date function above<br />

Function Syntax Purpose<br />

longdate(fixed(2000020313<br />

5026.1234567, 10, 5)) -><br />

longdate('2000-02-03<br />

13:50:26.1234500')<br />

longdate(2011, 3, 16, 9, 48,<br />

12, 1234567) -><br />

longdate('2011-03-16<br />

09:48:12.1234567')<br />

strl<strong>en</strong> int strl<strong>en</strong>(string) returns the l<strong>en</strong>gth of a string in bytes, as<br />

an integer number.<br />

midstr string midstr(string, int, int) returns a part of the string starting at<br />

arg2, arg3 bytes long.<br />

arg2 is counted from 1 (not 0)<br />

leftstr string leftstr(string, int) returns arg2 bytes from the left of the<br />

arg1. If arg1 is shorter<br />

than the value of arg2, the complete<br />

string will be returned.<br />

rightstr string rightstr(string, int) returns arg2 bytes from the right of the<br />

arg1. If arg1 is shorter<br />

than the value of arg2, the complete<br />

string will be returned.<br />

instr int instr(string, string) returns the position of the first<br />

occurr<strong>en</strong>ce of the second string<br />

148<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

within the first string (>= 1) or 0, if the<br />

second string is not<br />

contained in the first.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Function Syntax Purpose<br />

hextoraw string hextoraw(string) convert a hexadecimal repres<strong>en</strong>tation of<br />

bytes to a string of<br />

bytes. The hexadecimal string may<br />

contain 0-9, upper or lowercase a-f and<br />

no spaces betwe<strong>en</strong> the two digits of a<br />

byte; spaces betwe<strong>en</strong> bytes are allowed.<br />

rawtohex string rawtohex(string) convert a string of bytes to its<br />

hexadecimal repres<strong>en</strong>tation.<br />

ltrim string ltrim(string)<br />

string ltrim(string, string)<br />

rtrim string rtrim(string)<br />

string rtrim(string, string)<br />

trim string trim(string)<br />

string trim(string, string)<br />

lpad string lpad(string, int)<br />

string lpad(string, int, string)<br />

rpad string rpad(string, int)<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

string rpad(string, int, string)<br />

The output will contain only 0-9 and<br />

(upper case) A-F, no spaces and is twice<br />

as many bytes as the original string.<br />

removes a whitespace prefix from a<br />

string. The Whitespace characters may<br />

be specified in an optional argum<strong>en</strong>t.<br />

This functions operates on raw bytes of<br />

the UTF8-string and has no knowledge<br />

of multi byte codes (you may not<br />

specify multi byte whitespace<br />

characters).<br />

removes trailing whitespace from a<br />

string. The Whitespace characters may<br />

be specified in an optional argum<strong>en</strong>t.<br />

This functions operates on raw bytes of<br />

the UTF8-string and has no knowledge<br />

of multi byte codes (you may not<br />

specify multi byte whitespace<br />

characters).<br />

removes whitespace from the beginning<br />

and <strong>en</strong>d of a string.<br />

add whitespace to the left of a string. A<br />

second string argum<strong>en</strong>t specifies the<br />

whitespace which will be added<br />

repeatedly until the string has reached<br />

the int<strong>en</strong>ded l<strong>en</strong>gth. If no second string<br />

argum<strong>en</strong>t is specified, chr(32) (' ') will<br />

be added. This function operated on<br />

UTF-8 bytes and has no knowledge of<br />

unicode characters (neither for the<br />

whitespace string nor for l<strong>en</strong>gth<br />

computation).<br />

add whitespace to the <strong>en</strong>d of a string. A<br />

second string argum<strong>en</strong>t specifies the<br />

whitespace which will be added<br />

repeatedly until the string has reached<br />

the int<strong>en</strong>ded l<strong>en</strong>gth. If no second string<br />

argum<strong>en</strong>t is specified, chr(32) (' ') will<br />

be added. This function operated on<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 149


Function Syntax Purpose<br />

UTF-8 bytes and has no knowledge of<br />

unicode characters (neither for the<br />

whitespace string nor for l<strong>en</strong>gth<br />

computation).<br />

replace string replace(string, string, string) replace every occurr<strong>en</strong>ce of arg2 in arg1<br />

with arg3 and return the resulting string<br />

Mathematical Functions<br />

Function Syntax Purpose Example<br />

sign int sign(double)<br />

int sign(time)<br />

int sign(date)<br />

abs double abs(double)<br />

round<br />

.<br />

rounddown<br />

Date Functions<br />

decfloat abs(decfloat)<br />

decfloat abs(decfloat)<br />

time abs(time)<br />

Sign returns -1, 0 or 1<br />

dep<strong>en</strong>ding on the sign of its<br />

argum<strong>en</strong>t. Sign is<br />

implem<strong>en</strong>ted for all numeric<br />

types, date and time.<br />

Abs returns arg, if arg is<br />

positive or zero, -arg else.<br />

Abs is implem<strong>en</strong>ted for all<br />

numeric types and time.<br />

double round(double, int) round does rounding of<br />

absolute values toward zer<br />

while the sign is retained<br />

double rounddown(double,<br />

int)<br />

rounddown rounds toward<br />

negative infinity making<br />

rounddown(-1.1, 0) = -2<br />

Function Syntax Purpose<br />

round(123.456, 0) = 123<br />

round(123.456, 1) = 123.5<br />

round(-123.456, 1) = -123.5<br />

round(123.456, -1) = 120<br />

rounddown(123.456, -1) =<br />

120<br />

rounddown(-123.456, -1) =<br />

-130<br />

utctolocal utctolocal(datearg, timezonearg) interprets datearg (a date, without<br />

timezone) as utc and convert it to the<br />

timezone named by timezonearg (a<br />

string)<br />

localtoutc localtoutc(datearg, timezonearg) converts the local datetime datearg to<br />

the timezone specified by the string<br />

timezonearg, return as a date<br />

weekday weekday(date) returns the weekday as an integer in the<br />

range 0..6, 0 is monday.<br />

now now() returns the curr<strong>en</strong>t date and time<br />

(localtime of the server timezone) as<br />

date<br />

150<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


Function Syntax Purpose<br />

daysbetwe<strong>en</strong> daysbetwe<strong>en</strong>(date1, date2)<br />

daysbetwe<strong>en</strong>(daydate1, daydate2)<br />

daysbetwe<strong>en</strong>(seconddate1,<br />

seconddate2)<br />

daysbetwe<strong>en</strong>(longdate1, longdate2)<br />

secondsbetwe<strong>en</strong> secondsbetwe<strong>en</strong>(seconddate1,<br />

seconddate2)<br />

secondsbetwe<strong>en</strong>(longdate1, longdate2)<br />

returns the number of days (integer)<br />

betwe<strong>en</strong> date1 and date2. The first<br />

version is an alternative to date2 - date1.<br />

Instead of rounding or checking for<br />

exactly 24 hours distance, this will<br />

truncate both date values today<br />

precision and subtract the resulting day<br />

numbers, meaning that if arg2 is not the<br />

cal<strong>en</strong>dar day following arg1,<br />

daysbetwe<strong>en</strong> will return 1 regardless of<br />

the time compon<strong>en</strong>ts of arg1 and arg2.<br />

returns the number of seconds the first<br />

to the second arg, as a fixed point<br />

number. The returned value is positive if<br />

the first argum<strong>en</strong>t is less than the<br />

second. The return values are fixed18.0<br />

in both cases (note that it may prove<br />

more useful to use fixed11.7 in case of<br />

longdate argum<strong>en</strong>ts).<br />

compon<strong>en</strong>t compon<strong>en</strong>t(date, int) the int argum<strong>en</strong>t may be int the range<br />

1..6, the values mean year, day, month,<br />

hour, minute, second, respectively. If a<br />

compon<strong>en</strong>t is not set in the date, the<br />

compon<strong>en</strong>t function will return a default<br />

value, 1 for the month or the day, 0 for<br />

other compon<strong>en</strong>ts. The compon<strong>en</strong>t<br />

function may also be applied to<br />

longdate and time types.<br />

addseconds addseconds(date, int)<br />

addseconds(seconddate, decfloat)<br />

addseconds(longdate, decfloat)<br />

adddays adddays(date, int)<br />

Misc Functions<br />

adddays(daydate, int)<br />

adddays(seconddate, int)<br />

adddays(longdate, int)<br />

Return a date plus a number of seconds.<br />

Fractional seconds will also be used in<br />

case of longdate. Null handling is (in<br />

opposition to the default done with<br />

adds) to return null if any argum<strong>en</strong>t is<br />

null.<br />

Return a date plus a number of days.<br />

Null handling is (in opposition to the<br />

default done with adds) to return null if<br />

any argum<strong>en</strong>t is null.<br />

Function Syntax Purpose Example<br />

if if(intarg, arg2, arg3) return arg2 if intarg is<br />

considered true (not equal to<br />

zero), else return arg3.<br />

Curr<strong>en</strong>tly, no shortcut<br />

evaluation is implem<strong>en</strong>ted,<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

if("NETWR"


Function Syntax Purpose Example<br />

meaning that both arg2 and<br />

arg3 are evaluated in any<br />

case. This means you cannot<br />

use if to avoid a divide by zero<br />

error which has the side<br />

effect of terminating<br />

expression evaluation wh<strong>en</strong> it<br />

occurs.<br />

in in(arg1, ...) return 1 (= true) if arg1 is<br />

equal to any of the remaining<br />

args, return 0 else<br />

case<br />

case(arg1, default) case(arg1,<br />

cmp1, value1, cmp2,<br />

value2, ..., default)<br />

return value1 if arg1 == cmp1,<br />

value2 if arg1 == cmp2 etc,<br />

default if there no match<br />

isnull isnull(arg1) return 1 (= true), if arg1 is set<br />

to null and null checking is on<br />

during Evaluator run<br />

(EVALUATOR_MAY_RETURN<br />

_NULL)<br />

6.5.12 Searching Tables, Models and Column Views<br />

case("CATEGORY", 'A', 'LV',<br />

'B', 'MV', 'HV')<br />

You use this feature to search for tables, models and column views in a system. You can search these objects in<br />

any system from the list of systems added in the Navigator panel that has all services started, and is up and<br />

running.<br />

In the search results, for a matching object you can perform the following actions:<br />

● Tables - you can op<strong>en</strong> the table definition and add the table in the analytic and attribute view editor.<br />

Note: You can add a table only if the editor is op<strong>en</strong> otherwise it results in error.<br />

● Models - you can op<strong>en</strong> the models in the editor and in case of attribute view, you can add it in the view editor<br />

of an analytic view.<br />

Note: You can add a model only if the editor is op<strong>en</strong> otherwise it results in error.<br />

● Column Views - you can only op<strong>en</strong> and view the definition.<br />

1. Enter the object that you want to search in the Modeler toolbar search field.<br />

2. Select the system in which you want to search the object from the dropdown option next to the Search<br />

button.<br />

3. To execute the search, choose Search.<br />

The matching objects are listed in the expanded results pane with three tab pages, Tables, Models, and<br />

Column Views. You can select each to view the matching objects and corresponding actions that you can<br />

perform on them, for example, Op<strong>en</strong> and Add.<br />

152<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


6.5.13 Setting Keyboard Shortcuts<br />

You use this procedure to <strong>en</strong>able the keyboard shortcuts for Modeler actions like, activate, validate, and so on.<br />

The list of supported commands with the default keyboard shortcuts is as follows:<br />

Command Binding Wh<strong>en</strong> Category<br />

Activate Ctrl+Shift+A Navigator Modeler Keys<br />

Activate Ctrl+Shift+A In Windows Modeler Keys<br />

Add Table/Model Ctrl+Shift+= In Windows Modeler Keys<br />

Auto Arrange Ctrl+L In Windows Modeler Keys<br />

Data Preview Alt+Shift+P Navigator Modeler Keys<br />

Data Preview Alt+Shift+P In Windows Modeler Keys<br />

Display XML Alt+D In Windows Modeler Keys<br />

Find Ctrl+F Navigator Modeler Navigator<br />

Fit to Window Ctrl+0 In Windows Modeler Keys<br />

Move Elem<strong>en</strong>t in Output<br />

Pane (Direction: Down)<br />

Move Elem<strong>en</strong>t in Output<br />

Pane (Direction: Up)<br />

Ctrl+] In Windows Modeler Keys<br />

Ctrl+[ In Windows Modeler Keys<br />

Op<strong>en</strong> Ctrl+O Navigator Modeler Keys<br />

Show View (View: History) Alt+Shift+H In Windows Views<br />

Show View (View: Job<br />

Log)<br />

Show View (View: Where-<br />

Used List)<br />

Alt+Shift+L In Windows Views<br />

Alt+Shift+U In Windows Views<br />

Validate Ctrl+Shift+V In Windows Modeler Keys<br />

Validate Ctrl+Shift+V Navigator Modeler Keys<br />

Zoom (Type: In) Ctrl+= In Windows Modeler Keys<br />

Zoom (Type: Out) Ctrl+- In Windows Modeler Keys<br />

Zoom (Type: Reset) Alt+Shift+0 In Windows Modeler Keys<br />

1. Choose Window Prefer<strong>en</strong>ces G<strong>en</strong>eral Keys .<br />

2. In the Keys panel, select Modeler as Scheme.<br />

3. If you want to view only the commands supported by Modeler for keyboard shortcut, in the text field <strong>en</strong>ter<br />

Modeler Keys.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

Note: You cannot add new commands but can choose to customize the commands using the<br />

following options:<br />

○ Copy Command - to provide alternate keyboard shortcut for an existing command.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 153


4. Choose Apply.<br />

○ Unbind Command - to clear the key bindings with the command and provide new keyboard<br />

shortcut for an existing command.<br />

○ Restore Command - to restore the default key bindings provided by Modeler for an existing<br />

command.<br />

6.5.14 Copying an Object<br />

You can choose to copy an object in the Navigator panel and paste it to a required package. You must have write<br />

permissions on the target package where you are pasting the object. The copy paste feature is supported for all<br />

Modeler objects that is, attribute view, analytic view, calculation view, procedure and analytic privilege. The object<br />

that is copied to the target package is always inactive, ev<strong>en</strong> if in the source package it is in active state.<br />

By default the keyboard shortcut for copy and paste is CTRL + C and CTRL + V respectively. To <strong>en</strong>able keyboard<br />

shortcut for copy and paste you must apply the Modeler keyboard shortcuts from the Window Prefer<strong>en</strong>ces<br />

G<strong>en</strong>eral Keys and select Modeler as scheme.<br />

Note: Copy paste is supported only for a single object.<br />

1. In the Navigator panel, select an object and in the contect m<strong>en</strong>u, choose Copy.<br />

Note: If you have applied the Keyboard shortcuts th<strong>en</strong> you can also press CTRL + C to copy an object.<br />

2. Navigate to the package where you want to paste the object, and choose Paste.<br />

Note: If you have applied the Keyboard shortcuts th<strong>en</strong> you can also press CTRL + V to paste an object.<br />

6.6 Importing BW Objects<br />

● You have implem<strong>en</strong>ted SAP Notes 1703061, 1759172, 1752384,1733519, and 1769374.<br />

● You have upgraded your Modeler to SAP HANA 1.0 SP04 Rev 37.<br />

● You have added BW schema in the SQL privileges for the Modeler user to import BW models.<br />

● _SYS_REPO user has SELECT with GRANT privileges on the schema that contains the BW tables.<br />

You use this feature to import SAP NetWeaver Business Warehouse (SAP NetWeaver BW) models that are SAP<br />

HANA-optimized InfoCubes, SAP HANA-optimized DataStore objects, and Query Snapshot InfoProviders to the<br />

SAP HANA modeling <strong>en</strong>vironm<strong>en</strong>t. These imported objects are exposed as SAP HANA information models and<br />

can be consumed for reporting using cli<strong>en</strong>t tools such as, SAP BusinessObjects Explorer, SAP BusinessObjects BI<br />

4.0 Suite (Web Intellig<strong>en</strong>ce via Universes, Dashboards, Crystal Reports), Microsoft Office and so on. The model<br />

properties are set based on the SAP NetWeaver BW models metadata.<br />

If you select a DataStore object, the resultant SAP HANA model is an analytic view with the same name as that of<br />

the DataStore object. If you select an InfoCube, two objects- analytic view and calculation view are created. In this<br />

154<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


case, the name of calculation view and analytic view is same as that of the InfoCube and the name of the analytic<br />

view is suffixed with _INTERNAL. The analytic view g<strong>en</strong>erated in the case of an InfoCube is used internally for the<br />

g<strong>en</strong>eration of the respective calculation view and is not available for cli<strong>en</strong>t consumption. If you select a<br />

QuerySnapshot InfoProvider, the resultant SAP HANA model is an analytic view.<br />

Wh<strong>en</strong> you choose to import the SAP NetWeaver BW InfoProviders, the analysis authorizations set on the<br />

InfoProviders are also imported as analytic privileges in the SAP HANA Modeler. The name of the analytic privilege<br />

is the same as that of the BW Analysis Authorization object. These analysis authorizations set on the<br />

InfoProviders are applicable at runtime for reporting.<br />

Note: In the case of Query Snapshot, all the BW Analysis Authorization objects which are applicable on the<br />

underlying InfoProvider of the query, will also be applicable on the Query Snapshot. These BW analysis<br />

authorization objects will be imported as analytic privileges wh<strong>en</strong> importing the query snapshot.<br />

The g<strong>en</strong>erated models and analytic privileges are placed in the sap.bw package. You can choose to <strong>en</strong>hance the<br />

g<strong>en</strong>erated models. However, with the subsequ<strong>en</strong>t import of the same objects, the changes are overridd<strong>en</strong>. Also,<br />

changes made to the models on BW side are not automatically reflected in the g<strong>en</strong>erated models. This may lead<br />

to inconsist<strong>en</strong>t g<strong>en</strong>erated models based on the changes made to the physical tables. To avoid this, you need to re-<br />

import the models.<br />

Caution:<br />

● The calculated key figures (CKFs) and restricted key figures (RKFs) defined on the SAP BW models<br />

are not created for the g<strong>en</strong>erated SAP HANA models. In this case, you can create an RKF as restricted<br />

measure in the g<strong>en</strong>erated analytic view. For CKF you can create calculated measures in the g<strong>en</strong>erated<br />

calculation view or analytic view. These CKFs and RKFs are retained during subsequ<strong>en</strong>t import. If a<br />

change is made to the characteristics or key figures based on which these restricted measures and<br />

calculated measures are created, this may lead to inconsist<strong>en</strong>cy in the g<strong>en</strong>erated models. In this case,<br />

you need to manually adjust these restricted measures and calculated measures.<br />

● The restricted measures and calculated measures that you define for the analytic view that<br />

correspond to a query snapshot, is overwritt<strong>en</strong> with the subsequ<strong>en</strong>t import.<br />

● The BW analysis authorization objects are not always mapped 1:1 with the g<strong>en</strong>erated analytic<br />

privileges on the SAP HANA Modeler side. If the BW Analysis Authorization object does not include<br />

0TCAIPROV, the authorization is not moved to SAP HANA. Also, restrictions created in the BW<br />

analysis authorization are skipped if they do not match with the restrictions supported by the SAP<br />

HANA Modeler. In such cases, the data available for reporting for a SAP HANA Modeler user differs<br />

from the SAP NetWeaver BW user with the assigned restrictions.<br />

For reporting purposes, data which is visible for a user is:<br />

● For a DSO g<strong>en</strong>erated analytic view, all the data in the active table is available for reporting.<br />

● For an InfoCube g<strong>en</strong>erated calculation view, only successfully loaded requests are available for reporting<br />

(these are the gre<strong>en</strong> requests in manage InfoCube section).<br />

Restriction:<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 155


● The following features are not supported on the g<strong>en</strong>erated SAP HANA models:<br />

○ DSO without any key figure<br />

○ Curr<strong>en</strong>cy and unit of measure conversion<br />

Note: Only curr<strong>en</strong>cy mapping is supported and not the conversion.<br />

○ Time dep<strong>en</strong>d<strong>en</strong>t text and attributes<br />

○ Non-cumulative key figures<br />

○ Conversion routines in the BW system<br />

● The following features are not supported on g<strong>en</strong>erated analytic privileges:<br />

○ Exclude operator<br />

○ Aggregated value operator ‘:’<br />

○ Variables, User exits<br />

○ Authorization on Key Figures<br />

○ Authorization on hierarchy node<br />

○ Exception aggregation such as, average, counter, first value, last value, no aggregation, standard<br />

<strong>dev</strong>iation is not supported for g<strong>en</strong>erated measures.<br />

● The query name for the Query Snapshot should not be the same as the BW InfoProvider name (this<br />

results in conflict on the SAP HANA side).<br />

● Query Snapshot InfoProvider for BOE supports only key figures with aggregation types MIN, MAX,<br />

SUM, and COUNT.<br />

1. Op<strong>en</strong> the Modeler perspective.<br />

2. In the main m<strong>en</strong>u, choose File Import .<br />

3. Expand the SAP HANA Cont<strong>en</strong>t node.<br />

4. Choose Import SAP NetWeaver BW Models, and choose Next.<br />

5. To establish a connection with the SAP NetWeaver BW system (underlying BW Application Server), in the<br />

Source System page, <strong>en</strong>ter the SAP NetWeaver BW system cred<strong>en</strong>tials and choose Next.<br />

Note: To add new connection details, select New Connection option from the Connection dropdown<br />

list. The connection details are saved and are available as dropdown options on subsequ<strong>en</strong>t logons.<br />

6. Select the target system (an SAP NetWeaver BW on SAP HANA) to which you want to import the models, and<br />

choose Next.<br />

7. Select the BW InfoProviders that you want to import and expose as SAP HANA information models.<br />

Remember: In order to import the QuerySnapshot InfoProvider, make sure that the BW Query is<br />

unlocked in transaction RSDDB, and an index is created via the same transaction before it can be used<br />

as InfoProviders.<br />

8. If you want to replace previously imported models in the target system with a new version, select Overwrite<br />

existing models.<br />

9. If you want import the selected models along with the display attributes for IMO Cube and IMO DSO, select<br />

Include display attributes.<br />

156<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model


The g<strong>en</strong>erated information models and analytic privileges are placed in the sap.bw package. In order to view the<br />

data of g<strong>en</strong>erated models, you need to assign the associated analytic privileges that are g<strong>en</strong>erated as part of the<br />

model import to the user. If these privileges are not assigned, user is not authorized to view the data.<br />

SAP HANA Developer Guide<br />

Setting Up the Analytic Model<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 157


7 Developing Procedures<br />

SQL in SAP HANA includes ext<strong>en</strong>sions for creating procedures, which <strong>en</strong>ables you to embed data-int<strong>en</strong>sive<br />

application logic into the database, where it can be optimized for performance (since there are no large data<br />

transfers to the application and features such as parallel execution is possible). Procedures are used wh<strong>en</strong> other<br />

modeling objects, such as analytic or attribute views, are not suffici<strong>en</strong>t.<br />

Some of the reasons to use procedures instead of standard SQL:<br />

● SQL is not designed for complex calculations, such as for financials.<br />

● SQL does not provide for imperative logic.<br />

● Complex SQL statem<strong>en</strong>ts can be hard to understand and maintain.<br />

● SQL queries return one result set. Procedures can return multiple result sets.<br />

● Procedures can have local variables, eliminating the need to explicitly create temporary tables for<br />

intermediate results.<br />

Procedures can be writt<strong>en</strong> in the following languages:<br />

● SQLScript: The language that SAP HANA provides for writing procedures.<br />

● R: An op<strong>en</strong>-source programming language for statistical computing and graphics, which can be installed and<br />

integrated with SAP HANA.<br />

There are additional libraries of procedures, called Business Function Library and Predictive Analysis Library, that<br />

can be called via SQL or from within another procedure.<br />

SQL Ext<strong>en</strong>sions for Procedures<br />

SQL includes the following statem<strong>en</strong>ts for <strong>en</strong>abling procedures:<br />

● CREATE TYPE: Creates a table types, which are used to define parameters for a procedure that repres<strong>en</strong>t<br />

tabular results. For example:<br />

CREATE TYPE tt_publishers AS TABLE (<br />

publisher INTEGER,<br />

name VARCHAR(50),<br />

price DECIMAL,<br />

cnt INTEGER);<br />

● CREATE PROCEDURE: Creates a procedure. The LANGUAGE clause specifies the language you are using to<br />

158<br />

code the procedure. For example:<br />

CREATE PROCEDURE ProcWithResultView(IN id INT, OUT o1 CUSTOMER)<br />

LANGUAGE SQLSCRIPT READS SQL DATA WITH RESULT VIEW ProcView AS<br />

BEGIN<br />

o1 = SELECT * FROM CUSTOMER WHERE CUST_ID = :id;<br />

END;<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Developing Procedures


● CALL: Calls a procedure. For example:<br />

CALL getOutput (1000, 'EUR', NULL, NULL);<br />

Tools for Writing Procedures<br />

Use the SQLScript editor, which includes debugging capabilities, to build SQLScript procedures.<br />

You can also use the Navigator in the Modeler perspective to build procedures, but there are no debugging<br />

capabilities. You should only use this method:<br />

● If you need to <strong>dev</strong>elop a procedure using a local table type as an input or output parameter. A local table type<br />

is created within the Navigator procedure tool and for only the curr<strong>en</strong>t procedure. If you can use a global table<br />

type, th<strong>en</strong> use the SQLScript Editor.<br />

● If you need to edit a procedure previously created in the Navigator that contains table type parameters.<br />

Related Links<br />

SAP HANA SQL Refer<strong>en</strong>ce<br />

SAP HANA SQLScript Refer<strong>en</strong>ce<br />

SAP HANA R Integration Guide<br />

SAP HANA Business Function Library (BFL) Refer<strong>en</strong>ce<br />

SAP HANA Predictive Analysis Library (PAL) Refer<strong>en</strong>ce<br />

Creating Procedures<br />

7.1 Editing SQLScript<br />

The SAP HANA SQLScript editor allows you to create, edit and activate procedures.<br />

Before you begin working in the SAP HANA SQLScript editor, op<strong>en</strong> the SAP HANA Developm<strong>en</strong>t perspective and<br />

do the following:<br />

● Create a <strong>dev</strong>elopm<strong>en</strong>t workspace. For more information, see Creating a Repository Workspace [page 39].<br />

● Checkout a package. For more information, see Working with the Repository [page 27] .<br />

Note: After checking out a package that contains active procedures, you can modify and debug the<br />

procedures.<br />

● Create and share a project. For more information, see Using SAP HANA Projects [page 37].<br />

.<br />

Note: You can also share your project after you create your procedure.<br />

To write and edit a procedure in the SAP HANA SQLScript editor, perform the following steps:<br />

SAP HANA Developer Guide<br />

Developing Procedures<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 159


1. After you have created your workspace and your project, go to the Project Explorer view in the SAP HANA<br />

Developm<strong>en</strong>t perspective , right-click on the file name, select New, and select File. The New File wizard will<br />

appear.<br />

2. Enter or select the par<strong>en</strong>t folder and <strong>en</strong>ter the file name using the following naming conv<strong>en</strong>tion<br />

.procedure. Choose Finish. The icon shows that your procedure is created locally. Choose Save.<br />

Your procedure will op<strong>en</strong> containing the default Create Procedure template. In the Properties view, you will<br />

see the properties of your procedure, such as Access Mode, Name and Language. You can also change the<br />

default schema that this procedure is using.<br />

Note: You can also create a folder first and add a file. Right-click on the project name, select New, and<br />

select Folder. The New Folder wizard will appear. Enter or select the project, <strong>en</strong>ter the folder name,<br />

and choose Finish.<br />

3. To share your project, right-click on the project name, select Team, and select Share Project. The Share<br />

Project wizard will appear. Choose Finish. The icon shows that your procedure is not committed and not<br />

activated.<br />

4. You can begin writing your code inside your new procedure and save it locally. The syntax is checked<br />

simultaneously and is highlighted. Auto-completion of the syntax appears as you type; press Ctrl + Spacebar<br />

to get a list of relevant SQLScript statem<strong>en</strong>ts.<br />

Note: You can only write one stored procedure per file. The file name and the procedure name must<br />

be the same.<br />

5. To commit your new procedure or make changes to an existing one, first save it, right-click on the procedure,<br />

select Team, and select Commit. Your procedure is now synchronized to the repository as a design-time<br />

object and the icon shows that your procedure is committed .<br />

Caution: The design-time pres<strong>en</strong>tation of the procedure is curr<strong>en</strong>tly in XML format that you must not<br />

edit.<br />

6. Wh<strong>en</strong> you have finished writing your procedure and you are ready to activate it, right-click on the procedure,<br />

select Team, and select Activate. Your procedure is created in the catalog as a runtime object and the icon<br />

shows that your procedure is activated . This will allow you and other users to call the procedure and debug it.<br />

If an error is detected during activation, an error message will appear in the Problems view.<br />

Related Links<br />

Note: You can also activate your procedure at the project and folder level.<br />

SAP HANA Developm<strong>en</strong>t Perspective [page 25]<br />

SAP HANA Repository Packages and Namespaces [page 43]<br />

In SAP HANA, a package typically consists of a collection of repository objects, which can be transported<br />

betwe<strong>en</strong> systems. Multiple packages can be combined in a delivery unit (DU).<br />

About SAP HANA SQLScript<br />

SAP HANA SQL Refer<strong>en</strong>ce<br />

SAP HANA System Tables and Monitoring Views Refer<strong>en</strong>ce<br />

160<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Developing Procedures


7.2 Debugging SQLScript<br />

The SAP HANA SQLScript debugger allows you to debug and analyze procedures. In a debug session, your<br />

procedures will be executed in a serial mode, not in parallel (not-optimized). This allows you to test the<br />

correctness of the procedure logic and is not for evaluating the performance.<br />

Before you begin using the SAP HANA SQLScript debugger, you must activate your procedures and they must<br />

belong to a project on your local work station. For more information, see Editing SQLScript.<br />

To debug a procedure in the SAP HANA SQLScript debugger, perform the following steps:<br />

1. Op<strong>en</strong> the Debug perspective in the SAP HANA studio and select the procedure you want to debug by clicking<br />

on the relevant tab in the Editor view.<br />

2. Double-click on the left vertical ruler to add breakpoints to your procedure. You can see a list of all of the<br />

breakpoints in the Breakpoints view.<br />

From the Breakpoints view, you can:<br />

○ Deselect specific breakpoints or skip all of them.<br />

○ Delete a specific breakpoint or delete all.<br />

○ Double-click on a breakpoint to see which line it belongs to in the Editor view.<br />

○ See the status of the breakpoint:<br />

○ P<strong>en</strong>ding<br />

○ Valid<br />

○ Invalid<br />

3. To create a debug session you must first create a debug configuration. Choose and select Debug<br />

Configurations.... The Debug Configurations wizard will appear.<br />

Note: The curr<strong>en</strong>t debug configuration allows you to debug any stored procedure that is op<strong>en</strong>ed in the<br />

editor. Therefore, you do not have to create a new debug configuration for every procedure you want<br />

to debug.<br />

4. Double-click SQLScript Procedure, <strong>en</strong>ter a name, choose Apply, and choose Close.<br />

SAP HANA Developer Guide<br />

Developing Procedures<br />

Note: If you want to start debugging your procedure, choose Apply and choose Debug.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 161


5. To start your debug session, choose and select your debug configuration. The debug session will begin<br />

and you will see the status of the session in the Debug view. The status of a breakpoint may change after the<br />

server has validated it. The breakpoint position might change if it is placed on an invalid line where the<br />

debugger cannot stop. The debugger will stop at the first breakpoint and the session will be susp<strong>en</strong>ded until<br />

you resume it.<br />

If your run is successful, the valid status will appear next to the breakpoints in the Breakpoints view.<br />

Note: You must set breakpoints in the lines you want to break at and resume the session again.<br />

You can evaluate your local scalar and table variables in the Variable view. The view shows the values of the<br />

scalar variables and the number of rows in each table.<br />

6. To view the cont<strong>en</strong>t of the tables listed in the Variable view, right-click on the table name and select Op<strong>en</strong> Data<br />

Preview. The results will appear in the Preview view. This view will automatically close wh<strong>en</strong> you resume your<br />

debug session.<br />

The session will be terminated wh<strong>en</strong> you reach the <strong>en</strong>d of the procedure run.<br />

7.3 Developing Procedures in the Modeler Editor<br />

To create procedures, use the SQLScript Editor, as described in Editing SQLScript [page 159].<br />

If you need to create procedures with local table types, that is, table types created only for the procedure, perform<br />

the steps described in this section.<br />

1. On the Quick Launch tab page, choose Procedure.<br />

If the Quick Launch page is not op<strong>en</strong>, go to Help Quick Launch .<br />

2. Enter a name and description for the procedure.<br />

3. For unqualified access in SQL, select the required schema from the Default Schema dropdown list.<br />

Note:<br />

○ If you do not select a default schema, while scripting you need to provide fully qualified names of<br />

the catalog objects that include the schema.<br />

○ If you specify a default schema, and write SQL such as select * from myTable, the<br />

specified default schema is used at runtime to refer to the table.<br />

4. Select the package in which you want to save the procedure.<br />

5. Select the required option from the Run With dropdown list to select which privileges are to be considered<br />

while executing the procedure.<br />

162<br />

Note:<br />

There are two types of rights, as follows:<br />

Definer's right: If you want the system to use the rights of the definer while executing the procedure<br />

for any user.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Developing Procedures


Invoker's right: If you want the system to use the rights of the curr<strong>en</strong>t user while executing the<br />

procedure.<br />

6. Select the required access mode as follows:<br />

Access Mode Purpose<br />

Read Only Use this mode to create procedures for fetching table data.<br />

Read Write Use this mode to create procedures for fetching and<br />

updating table data.<br />

7. Select the language in which you are writing the procedure.<br />

8. Choose Finish.<br />

9. In the function editor pane, write a script for the function using the following data types:<br />

○ Table or scalar data types for input parameters.<br />

○ Table data types for output parameters.<br />

Note: You can only write one function in the function body. However, you can refer to other functions.<br />

10. Choose File Save .<br />

11. Activate the procedure using one of the following options in the toolbar:<br />

○ Save and Activate: Activate the curr<strong>en</strong>t procedure and redeploy the affected objects if an active version of<br />

the affected object exists. Otherwise only the curr<strong>en</strong>t procedure gets activated.<br />

○ Save and Activate All: Activate the curr<strong>en</strong>t procedure along with the required and affected objects.<br />

SAP HANA Developer Guide<br />

Developing Procedures<br />

Note: You can also activate the curr<strong>en</strong>t procedure by selecting the procedure in the Navigator view<br />

and choosing Activate in the context m<strong>en</strong>u. For more information about activation, see Activating<br />

Objects [page 132].<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 163


8 Defining Web-based Data Access<br />

SAP HANA ext<strong>en</strong>ded application services (SAP HANA XS) provide applications and application <strong>dev</strong>elopers with<br />

access to the SAP HANA database using a consumption model that is exposed via HTTP.<br />

In addition to providing application-specific consumption models, SAP HANA XS also host system services that<br />

are part of the SAP HANA database, for example: search services and a built-in Web server that provides access<br />

to static cont<strong>en</strong>t stored in the SAP HANA repository.<br />

The consumption model provided by SAP HANA XS focuses on server-side applications writt<strong>en</strong> in JavaScript and<br />

making use of a powerful set of specially <strong>dev</strong>eloped API functions. However, you can use other methods to<br />

provide access to the data you want to expose in SAP HANA. For example, you can set up an ODATA service or<br />

use the XML for Analysis (XMLA) interface to s<strong>en</strong>d a Multi-dim<strong>en</strong>sional Expressions (MDX) query. This section<br />

describes how to set up a service that <strong>en</strong>ables you to expose data using OData or XMLA.<br />

8.1 Data Access with OData in SAP HANA XS<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), the persist<strong>en</strong>ce model (for example, tables, views,<br />

and stored procedures) is mapped to the consumption model that is exposed to cli<strong>en</strong>ts - the applications you<br />

write to extract data from the SAP HANA database.<br />

You can map the persist<strong>en</strong>ce and consumption models with OData, a resource-based Web protocol for querying<br />

and updating data. An OData application running in SAP HANA XS is used to provide the consumption model for<br />

cli<strong>en</strong>t applications exchanging OData queries with the SAP HANA database.:<br />

You can use OData to <strong>en</strong>able cli<strong>en</strong>ts to consume authorized data stored in the SAP HANA database. OData<br />

defines operations on resources using RESTful HTTP commands (for example, GET, PUT, POST, and DELETE)<br />

and specifies the URI syntax for id<strong>en</strong>tifying the resources. Data is transferred over HTTP using either the Atom<br />

(XML) or the JSON (JavaScript) format.<br />

Applications running in SAP HANA XS <strong>en</strong>able accurate control of the flow of data betwe<strong>en</strong> the pres<strong>en</strong>tational<br />

layer, for example, in the Browser, and the data-processing layer in SAP HANA itself, where the calculations are<br />

performed, for example, in SQL or SQLScript. If you <strong>dev</strong>elop and deploy an OData service running in SAP HANA<br />

XS, you can take advantage of the embedded access to SAP HANA that SAP HANA XS provides; the embedded<br />

access greatly improves <strong>en</strong>d-to-<strong>en</strong>d performance.<br />

8.1.1 OData in SAP HANA XS<br />

OData is a resource-based web protocol for querying and updating data. OData defines operations on resources<br />

using HTTP commands (for example, GET, PUT, POST, and DELETE) and specifies the uniform resource<br />

indicator (URI) syntax to use to id<strong>en</strong>tify the resources.<br />

Data is transferred over HTTP using the Atom or JSON format:<br />

164<br />

Note: OData makes it easier for SAP, for partners, and for customers to build standards-based<br />

applications for many differ<strong>en</strong>t <strong>dev</strong>ices and on various platforms, for example, applications that are based<br />

on a lightweight consumption of SAP and non-SAP business application data.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


The main aim of OData is to define an abstract data model and a protocol which, combined, <strong>en</strong>able any cli<strong>en</strong>t to<br />

access data exposed by any data source. Cli<strong>en</strong>ts might include Web browsers, mobile <strong>dev</strong>ices, businessintellig<strong>en</strong>ce<br />

tools, and custom applications (for example, writt<strong>en</strong> in programming languages such as PHP or Java);<br />

data sources can include databases, cont<strong>en</strong>t-managem<strong>en</strong>t systems, the Cloud, or custom applications (for<br />

example, writt<strong>en</strong> in Java).<br />

The OData approach to data exchange involves the following elem<strong>en</strong>ts:<br />

● OData data model<br />

Provides a g<strong>en</strong>eric way to organize and describe data. OData uses the Entity 1 Data Model (EDM).<br />

● OData protocol<br />

Enables a cli<strong>en</strong>t to query an OData service. The OData protocol is a set of interactions, which includes the<br />

usual REST-based create, read, update, and delete operations along with an OData-defined query language.<br />

The OData service s<strong>en</strong>ds data in either of the following ways:<br />

○ XML-based format defined by Atom/AtomPub<br />

○ JavaScript Object Notation (JSON)<br />

● OData cli<strong>en</strong>t libraries<br />

Enables access to data via the OData protocol. Since most OData cli<strong>en</strong>ts are applications, pre-built libraries<br />

for making OData requests and getting results reduces and simplifies work for the <strong>dev</strong>elopers who create<br />

those applications.<br />

A broad selection of OData cli<strong>en</strong>t libraries are already widely available, for example: Android, Java, JavaScript,<br />

PHP, Ruby, and the best known mobile platforms.<br />

● OData services<br />

Exposes an <strong>en</strong>d point that allows access to data in the SAP HANA database. The OData service implem<strong>en</strong>ts<br />

the OData protocol (using the OData Data Services runtime) and uses the Data Access layer to map data<br />

betwe<strong>en</strong> its underlying form (database tables, spreadsheet lists, and so on) and a format that the requesting<br />

cli<strong>en</strong>t can understand.<br />

8.1.2 OData Service Definitions<br />

The OData service definition is the mechanism you use to define what data to expose with OData, how, and to<br />

whom. Data exposed as an OData collection is available for analysis and display by cli<strong>en</strong>t applications, for<br />

example, a browser that uses functions provided by an OData cli<strong>en</strong>t library running on the cli<strong>en</strong>t system.<br />

To expose information by means of OData to applications using SAP HANA XS, you must define database views<br />

that provide the data with the required granularity. Th<strong>en</strong> you create an OData service definition, which is a file you<br />

use to specify which database views or tables are exposed as OData collections.<br />

Note: SAP HANA XS curr<strong>en</strong>tly supports OData version 2.0, which you can use to s<strong>en</strong>d OData queries<br />

(using the http GET method). Language <strong>en</strong>coding is restricted to UTF-8.<br />

An OData service for SAP HANA XS is defined in a text file with the file suffix .xsodata, for example,<br />

OdataSrvDef.xsodata. The file must contain at least the <strong>en</strong>try service {}, which would g<strong>en</strong>erate a<br />

completely operational OData service with an empty service catalog and an empty metadata file. However, usually<br />

you use the service definition to expose objects in the database catalog, for example: tables, SQL views, or<br />

calculation rules.<br />

In the OData service-definition file, you can use the following ways to name the SAP HANA objects you want to<br />

expose by OData:<br />

● Repository objects<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 165


Expose an object using the object's repository (design-time) name in the OData service-definition file. This<br />

method of exposing database objects by OData has the advantage that the OData service is automatically<br />

updated if the underlying repository object changes.<br />

● Database objects<br />

Expose an object using the object's database catalog (runtime) name (along with the schema name). The<br />

support for database objects is mainly int<strong>en</strong>ded for existing or replicated objects that do not have a repository<br />

design-time repres<strong>en</strong>tation.<br />

Note: Although both declaration methods are supported, the recomm<strong>en</strong>ded method is to use the<br />

repository name of the object(s) you want to expose using OData.<br />

OData Service-Definition Type Mapping<br />

During the activation of the OData service definition, SQL types are mapped to EDM types according to a mapping<br />

table. For example, the SQL type "Time" is mapped to the EDM type "EDM.Time"; the SQL type "Decimal" is<br />

mapped to the EDM type "EDM.Decimal"; the SQL types "Real" and "Float" are mapped to the EDM type<br />

"EDM.Single".<br />

In the following example, the SQL types of columns in a table are mapped to the EDM types in the properties of an<br />

<strong>en</strong>tity type.<br />

{name = "ID"; sqlType = INTEGER; nullable = false;}, {name = "RefereeID";<br />

sqlType = VARCHAR; nullable = true;}<br />

<br />

OData Service-Definition Features<br />

The OData service definition provides a list of keywords that you use in the OData service-definition file to <strong>en</strong>able<br />

important features. For example, the following list illustrates the most-commonly used features used in an OData<br />

service-definition and, where appropriate, indicates the keyword to use to <strong>en</strong>able the feature:<br />

● Aggregation<br />

The results of aggregations on columns change dynamically, dep<strong>en</strong>ding on the grouping conditions. As a<br />

result, aggregation cannot be done in SQL views; it needs to be specified in the OData service definition itself.<br />

Dep<strong>en</strong>ding on the type of object you want to expose with OData, the columns to aggregate and the function<br />

used must be specified explicitly (explicit aggregation) or derived from metadata in the database (derived<br />

aggregation). Note that aggregated columns cannot be used in combination with the $filter query<br />

parameter, and aggregation is only possible with g<strong>en</strong>erated keys.<br />

● Association<br />

Define associations betwe<strong>en</strong> <strong>en</strong>tities to express relationships betwe<strong>en</strong> <strong>en</strong>tities. With associations it is possible<br />

to reflect foreign key constraints on database tables, hierarchies and other relations betwe<strong>en</strong> database<br />

objects.<br />

● Key Specification<br />

166<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


The OData specification requires an EntityType to d<strong>en</strong>ote a set of properties forming a unique key. In SAP<br />

HANA, only tables can have a unique key, the primary key. All other (mostly view) objects require you to<br />

specify a key for the <strong>en</strong>tity. The OData service definition language (OSDL) <strong>en</strong>ables you to do this by d<strong>en</strong>oting a<br />

set of existing columns or by g<strong>en</strong>erating a local key. Bear in mind that local keys are transi<strong>en</strong>t; they exist only<br />

for the duration of the curr<strong>en</strong>t session and cannot be derefer<strong>en</strong>ced.<br />

Note: OSDL is the language used to define a service definition; the language includes a list of keywords<br />

that you use in the OData service-definition file to <strong>en</strong>able the required features.<br />

● Parameter Entity Sets<br />

You can use a special parameter <strong>en</strong>tity set to <strong>en</strong>ter input parameters for SAP HANA calculation views and<br />

analytic views. During activation of the <strong>en</strong>tity set, the specified parameters are retrieved from the metadata of<br />

the calculation (or analytical) view and exposed as a new EntitySet with the name suffix "Parameters", for<br />

example "CalcViewParameters".<br />

● Projection<br />

If the object you want to expose with an OData service has more columns than you actually want to expose,<br />

you can use SQL views to restrict the number of selected columns in the SELECT. However, for those cases<br />

where SQL views are not appropriate, you can use the with or without keywords in the OData service<br />

definition to include or exclude a list of columns.<br />

8.1.3 OData URI Parameters, Query Options, and Features<br />

Since OData fully embraces Web technologies, and more specifically URI concepts, all the actions that manage<br />

the interaction with the service at runtime are controlled by HTTP methods, the URI structure, or URI query<br />

parameters.<br />

The examples listed here illustrate how to use the OData service-definition file to specify what data to extract and<br />

what to do with it. You can find examples of the following features:<br />

● HTTP Methods<br />

For example, HTTPGET<br />

● Resource types<br />

For example: Service docum<strong>en</strong>ts, <strong>en</strong>tity sets, $metadata, and so on<br />

● Query options<br />

For example, $format, $filter, $select, and so on<br />

HTTP Methods<br />

Since the curr<strong>en</strong>t OData Infrastructure only supports read services (no Create/Update/Delete), the only<br />

supported HTTP Method is GET and POST for $batch (containing only GET requests). The result is that only read<br />

requests are possible.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 167


Resource Types<br />

You can use the resource types (or constructs) described and explained here to define how the service definition<br />

exposes data. For example, the Service Docum<strong>en</strong>t, Resource Type, or Entity sets <strong>en</strong>able you to select and view<br />

the cont<strong>en</strong>ts of the <strong>en</strong>tity sets that are queried.<br />

Service Docum<strong>en</strong>t<br />

The most basic resource type is the call to the .xsodata resource itself. This supplies information about the<br />

<strong>en</strong>tity set within this resource; otherwise known as the Service Docum<strong>en</strong>t.<br />

● Sample XSODATA Service:<br />

service namespace "SAMPLE" {<br />

"sample.hello::hello_tbl" as "Entries";<br />

}<br />

● URI Construct:<br />

/.xsodata/<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/<br />

● Sample XML Output:<br />

● Sample JSON Output:<br />

168<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


Entity Sets<br />

This construct allows you to view the <strong>en</strong>tire cont<strong>en</strong>t of the queried Entity Set.<br />

● URI Construct<br />

/.xsodata/<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries<br />

● Sample ATOM Output:<br />

● Sample JSON Output:<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 169


Single Entity<br />

Any single <strong>en</strong>tity (record) can be accessed by supplying the key field values after the Entity Set.<br />

● URI Construct:<br />

○ Single Key: /.xsodata/()<br />

○ Multiple Keys: /.xsodata/(=,)/<br />

● Sample URI:<br />

○ Single Key: /.xsodata/()<br />

○ Multiple Keys: http://<strong>hana</strong>xs:8000/sap./sflight/spfli.xsodata/<br />

FLIGHTS(CARRID='AA',CONNID='0017')#<br />

● Sample ATOM Output:<br />

170<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


● Sample JSON Output:<br />

Single Property<br />

Likewise, any single property of an <strong>en</strong>try can be directly accessed as well.<br />

● URI Construct:<br />

○ Single Key: /.xsodata/()/<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 171


○ Multiple Keys: http://<strong>hana</strong>xs:8000/sap./sflight/spfli.xsodata/<br />

FLIGHTS(CARRID='AA',CONNID='0017')/CITYFROM<br />

● Sample URI:<br />

○ Single Key: http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries(1)/<br />

TEXT<br />

○ Multiple Key: http://<strong>hana</strong>xs:8000/sap./sflight/spfli.xsodata/<br />

FLIGHTS(CARRID='AA',CONNID='0017')/CITYFROM<br />

● Sample ATOM Output:<br />

● Sample JSON Output:<br />

$metadata<br />

This parameter requests that the OData service return a special docum<strong>en</strong>t that describes the structure of the<br />

service itself. All properties, their data types, and all associations and relationships are described in this<br />

docum<strong>en</strong>t.<br />

● URI Construct:<br />

/.xsodata/$metadata<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/$metadata<br />

● Sample Output:<br />

172<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


$count<br />

This request allows you to return the number of records in an Entity Set instead of the details of the Entity Set. It is<br />

basically the same as using a SELECT COUNT(*) in an SQL Statem<strong>en</strong>t without top limitation.<br />

● URI Construct:<br />

/.xsodata//$count<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries/$count<br />

● Sample Output:<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 173


$value<br />

By specifying this segm<strong>en</strong>t after a single property, the service returns the value of the property as plain text.<br />

● URI Construct:<br />

/.xsodata//$value<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries(1)/Text/$value<br />

● Sample Output:<br />

$batch<br />

The $batch resource allows you to s<strong>en</strong>d multiple requests in one multipart request by using the POST http<br />

method.<br />

● URI Construct:<br />

/.xsodata/$batch<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/$batch<br />

● Sample Request:<br />

174<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


● Sample ATOM and JSON Output:<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 175


Query Parameters<br />

$format<br />

This parameter controls the output format. The default format is ATOM. However, the other supported option is<br />

JSON, which can be triggered by setting the $format=json.<br />

● URI Construct:<br />

/.xsodata//$format=<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries/$format=json<br />

● Sample Output:<br />

$filter<br />

A parameter that allows you to restrict the <strong>en</strong>tities in the <strong>en</strong>tity set. This option builds a dynamic WHERE condition<br />

into the underlying query.<br />

● URI Construct:<br />

/.xsodata//$filter = ''<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries/?<br />

$filter=CREATED%20eq%20datetime'2012-05-14T08:28:44.405'<br />

● Sample ATOM Output:<br />

176<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


● Sample JSON Output:<br />

$orderby<br />

This is a parameter that controls how the <strong>en</strong>tities in the <strong>en</strong>tity set are sorted.<br />

● URI Construct:<br />

/.xsodata//$orderby= asc|desc<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries/?<br />

$orderby=CREATED%20desc<br />

● Sample ATOM Output:<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 177


● Sample JSON Output:<br />

$skip<br />

This is a parameter that allows you to skip ahead in an <strong>en</strong>tity set only. It is useful wh<strong>en</strong> creating "paging" through<br />

an <strong>en</strong>tity set.<br />

● URI Construct:<br />

/.xsodata//$skip=n<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries/?$skip=2<br />

● Sample ATOM Output:<br />

178<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


● Sample JSON Output:<br />

$top<br />

This option allows you to limit the number of records returned regardless of how many records exist in the Entity<br />

Set. It is basically the same as using a SELECT ... UP TO n ROWS in an SQL Statem<strong>en</strong>t.<br />

● URI Construct:<br />

/.xsodata//$top=n<br />

● Sample URI:<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 179


http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries/?$top=3<br />

● Sample ATOM Output:<br />

● Sample JSON Output:<br />

$inlinecount<br />

This parameter triggers the OData service to embed an extra property with the total count in the complete <strong>en</strong>tity<br />

set. This is the count of all <strong>en</strong>tities after the $filter option has be<strong>en</strong> applied.<br />

● URI Construct:<br />

180<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


.xsodata//$inlinecount=allpages<br />

● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries/?<br />

$inlinecount=allpages<br />

● Sample ATOM Output:<br />

● Sample JSON Output:<br />

$select<br />

This property allows you to control which properties for each <strong>en</strong>tity are returned in the <strong>en</strong>tity set.<br />

● URI Construct:<br />

/.xsodata//$select=,,<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 181


● Sample URI:<br />

http://<strong>hana</strong>xs:8000/sample/hello/hello_odata.xsodata/Entries/?$select=TEXT<br />

● Sample ATOM Output:<br />

● Sample JSON Output:<br />

182<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


8.1.4 OData Security Considerations<br />

Enabling access to data by means of OData can create some security-related issues that you need to consider and<br />

address, for example, the data you want to expose, who can start the OData service, and so on.<br />

If you want to use OData to expose data to users and cli<strong>en</strong>ts in SAP HANA application services, you need to bear<br />

in mind the security considerations described in the following list:<br />

● Data Access<br />

Restrict user select authorization for tables/views exposed by the OData service<br />

● OData Service<br />

Restrict authorization rights to start the OData service<br />

● OData Statistical cont<strong>en</strong>t<br />

Restrict access to the URL/Path used to expose OData cont<strong>en</strong>t in the Web browser<br />

8.1.5 Defining the Data an OData Service Exposes<br />

An OData service exposes data stored in database tables or views as OData collections for analysis and display by<br />

cli<strong>en</strong>t applications. However, first of all, you need to <strong>en</strong>sure that the tables and views to expose as an OData<br />

collection actually exist.<br />

To define the data to expose using an OData service, you must perform at least the following tasks:<br />

1. Create a database schema.<br />

2. Create a simple database table to expose with an OData service.<br />

3. Create a simple database view to expose with an OData service.<br />

This step is optional; you can expose tables directly. In addition, you can create a repository view (for<br />

example, Analytic, Attribute, Calculation).<br />

4. Grant select privileges to the tables and views to be exposed with the OData service.<br />

8.1.6 Creating an OData Service Definition<br />

The OData service definition is a configuration file you use to specify which data (for example, views or tables) is<br />

exposed as an OData collection for analysis and display by cli<strong>en</strong>t applications.<br />

An OData service for SAP HANA XS is defined in a text file with the file suffix .xsodata, for example,<br />

OdataSrvDef.xsodata. The file resides in the package hierarchy of the OData application and must contain at<br />

least the <strong>en</strong>try service {}, which would g<strong>en</strong>erate an operational OData service with an empty service catalog and<br />

an empty metadata file.<br />

Prerequisites for the creation of an OData service definition:<br />

● SAP HANA studio/cli<strong>en</strong>t installed and configured<br />

● SAP HANA database user available with repository privileges (for example, to add packages)<br />

● A SAP HANA <strong>dev</strong>elopm<strong>en</strong>t system added to (and available in) SAP HANA studio, for example, in either the<br />

Navigator view or the SAP HANA Repositories view<br />

● A working <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t including a repository workspace, a package structure for your OData<br />

application, and a shared project to <strong>en</strong>able you to synchronize changes to the OData project files in the local<br />

file system with the repository<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 183


● Defined data to expose with the OData application, for example, at least the following:<br />

○ A database schema<br />

○ A database table<br />

1. In the shared project you are using for your OData application, use the Project Explorer view to locate the<br />

package where you want to create the new OData service definition.<br />

Note: The file containing the OData service definition must be placed in the root package of the OData<br />

application for which the service is int<strong>en</strong>ded.<br />

2. Create the file that will contain your OData service definition.<br />

In the Project Explorer view, right-click the folder where you want to create the new OData service-definition<br />

file and choose New File in the context-s<strong>en</strong>sitive popup m<strong>en</strong>u.<br />

3. Define the OData service.<br />

The OData service definition uses the OData Service Definition Language (OSDL), which includes a list of<br />

keywords that you specify in the OData service-definition file to <strong>en</strong>able important features.<br />

The following example shows a simple OData service definition exposing a simple table:<br />

service namespace "my.namespace" {<br />

"sample.odata:table.hdbtable" as "MyTable";<br />

}<br />

This service definition exposes a table defined in the file sample.odata:table.hdbtable and creates an<br />

EntitySet for this <strong>en</strong>tity named MyTable. The specification of an alias is optional. If omitted, the default name<br />

of the EntitySet is the name of the repository object file, in this example, table.<br />

4. Place the valid OData service definition in the root package of the OData application to which it applies.<br />

5. Save, commit, and activate the OData service definition in the SAP HANA repository.<br />

Related Links<br />

OData Service Definitions [page 165]<br />

The OData service definition is the mechanism you use to define what data to expose with OData, how, and to<br />

whom. Data exposed as an OData collection is available for analysis and display by cli<strong>en</strong>t applications, for<br />

example, a browser that uses functions provided by an OData cli<strong>en</strong>t library running on the cli<strong>en</strong>t system.<br />

8.1.7 OData Service Definition Language Syntax<br />

The OData Service Definition Language (OSDL) provides a set of keywords that <strong>en</strong>able you to set up an ODATA<br />

service definition file that specifies what data to expose, in what way, and to whom.<br />

The following list shows the syntax of the OData Service Definition Language (OSDL) in an EBNF-like format;<br />

conditions that apply for usage are listed after the table.<br />

definition :='service' [namespace] body<br />

namespace :='namespace' quotedstring<br />

quotedstring :=quote string quote<br />

string :=UTF8<br />

quote :='"'<br />

body :='{' cont<strong>en</strong>t '}'<br />

cont<strong>en</strong>t :=<strong>en</strong>try [cont<strong>en</strong>t]<br />

<strong>en</strong>try :=( <strong>en</strong>tity | association ) ';'<br />

<strong>en</strong>tity :=object [<strong>en</strong>tityset] [with] [keys] [navigates]<br />

[aggregates] [parameters]<br />

184<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


object :=['<strong>en</strong>tity'] ( repoobject | catalogobject )<br />

repoobject :=quote repopackage '/' reponame '.' repoext<strong>en</strong>sion<br />

quote<br />

repopackage :=string<br />

reponame :=string<br />

repoext<strong>en</strong>sion :=string<br />

catalogobject :=catalogobjectschema '.' catalogobjectname<br />

catalogobjectschema :=quotedstring<br />

catalogobjectname :=quotedstring<br />

<strong>en</strong>tityset :='as' <strong>en</strong>titysetname<br />

<strong>en</strong>titysetname :=quotedstring<br />

with :=( 'with' | 'without' ) propertylist<br />

propertylist :='(' columnlist ')'<br />

columnlist :=columnname [',' columnlist]<br />

columnname :=quotedstring<br />

keys :='keys' ( keylist | keyg<strong>en</strong>erated )<br />

keylist :=propertylist<br />

keyg<strong>en</strong>erated :='g<strong>en</strong>erate' ( keyg<strong>en</strong>local )<br />

keyg<strong>en</strong>local :='local' columnname<br />

navigates :='navigates' '(' navlist ')'<br />

navlist :=nav<strong>en</strong>try [',' navlist]<br />

nav<strong>en</strong>try :=assocname 'as' navpropname [from<strong>en</strong>d]<br />

assocname :=quotedstring<br />

navpropname :=quotedstring<br />

from<strong>en</strong>d :='from' ( 'principal' | 'dep<strong>en</strong>d<strong>en</strong>t' )<br />

aggregates :='aggregates' 'always' [aggregatestuple]<br />

aggregatestuple :='(' aggregateslist ')'<br />

aggregateslist :=aggregate [',' aggregateslist]<br />

aggregate :=aggregatefunction 'of' columnname<br />

aggregatefunction :=( 'SUM' | 'AVG' | 'MIN' | 'MAX' )<br />

parameters :='parameters' 'via' '<strong>en</strong>tity'<br />

[parameter<strong>en</strong>titysetname] [parametersresultsprop]<br />

parameter<strong>en</strong>titysetname :=quotedstring<br />

parametersresultsprop :='results' 'property' quotedstring<br />

association :=associationdef principal<strong>en</strong>d dep<strong>en</strong>d<strong>en</strong>t<strong>en</strong>d<br />

[assoctable]<br />

associationdef :='association' assocname<br />

principal<strong>en</strong>d :='principal' <strong>en</strong>d<br />

dep<strong>en</strong>d<strong>en</strong>t<strong>en</strong>d :='dep<strong>en</strong>d<strong>en</strong>t' <strong>en</strong>d<br />

<strong>en</strong>d :=<strong>en</strong>dref multiplicity<br />

<strong>en</strong>dref :=<strong>en</strong>dtype '(' joinproperties ')'<br />

<strong>en</strong>dtype :=<strong>en</strong>titysetname<br />

joinproperties :=columnlist<br />

multiplicity :='multiplicity' quote multiplicityvalue quote<br />

multiplicityvalue :=( '1' | '0..1' | '1..*' | '*' )<br />

assoctable :='over' repoobject overprincipal<strong>en</strong>d<br />

overdep<strong>en</strong>d<strong>en</strong>t<strong>en</strong>d<br />

overprincipal<strong>en</strong>d :='principal' over<strong>en</strong>d<br />

overdep<strong>en</strong>d<strong>en</strong>t<strong>en</strong>d :='dep<strong>en</strong>d<strong>en</strong>t' over<strong>en</strong>d<br />

over<strong>en</strong>d :=propertylist<br />

Conditions<br />

The following conditions apply wh<strong>en</strong> using the listed keywords:<br />

1. If the namespace is not specified, the schema namespace in the EDMX metadata docum<strong>en</strong>t will be the<br />

repository package of the service definition file concat<strong>en</strong>ated with the repository object name. E.g. if the<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 185


epository design time name of the .xsodata file is sap.<strong>hana</strong>.xs.doc/hello.xsodata the<br />

namespace will implicitly be sap.<strong>hana</strong>.xs.doc.hello.<br />

2. keyslist must not be specified for objects of type 'table'. They must only be applied to objects referring a<br />

view type. keyg<strong>en</strong>erated in turn, can be applied to table objects.<br />

3. If the <strong>en</strong>tityset is not specified in an <strong>en</strong>tity, the EntitySet for this object is named after the repository<br />

object name or the catalogobjectname. E.g. if object is "sap.<strong>hana</strong>.xs.doc/odata_docu" the<br />

<strong>en</strong>titysetname is implicitly set to odata_docu which th<strong>en</strong> can also be refer<strong>en</strong>ced in associations.<br />

4. The from<strong>en</strong>d in a nav<strong>en</strong>try must be specified if the <strong>en</strong>dtype is the same for both the principal<strong>en</strong>d<br />

and the dep<strong>en</strong>d<strong>en</strong>t<strong>en</strong>d of an association.<br />

5. The number of joinproperties in the principal<strong>en</strong>d must be the same as in the dep<strong>en</strong>d<strong>en</strong>t<strong>en</strong>d.<br />

6. Ordering in the joinproperties of <strong>en</strong>ds is relevant. The first columnname in the joinproperties of<br />

the principal<strong>en</strong>d is compared with the first columnname of the dep<strong>en</strong>d<strong>en</strong>t<strong>en</strong>d, the second with the<br />

second, and so on.<br />

7. The overprincipal<strong>en</strong>d corresponds to the principal<strong>en</strong>d. The number of properties in the<br />

joinproperties and the overproperties must be the same and their ordering is relevant. The same<br />

holds for the dep<strong>en</strong>d<strong>en</strong>t <strong>en</strong>d.<br />

8. aggregates can only be applied in combination with keyg<strong>en</strong>erated.<br />

9. If aggregatestuple is omitted, the aggregation functions are derived from the database. This is only<br />

possible for calculation views and analytic views.<br />

10. Specifying parameters is only possible for calculation views and analytic views.<br />

11. The default parameter<strong>en</strong>titysetname is the <strong>en</strong>titysetname of the <strong>en</strong>tity concat<strong>en</strong>ated with the<br />

suffix "Parameters".<br />

12. If the parametersresultsprop is omitted, the navigation property from the parameter <strong>en</strong>tity set to the<br />

<strong>en</strong>tity is called "Results".<br />

8.1.8 OData Service Definition: SQL-EDM Type Mapping<br />

During the activation of the OData service definition, the SAP HANA SQL types are mapped to the required OData<br />

EDM types according to the rules specified in a mapping table.<br />

The following mapping table lists how SAP HANA SQL types are mapped to OData EDM types during the<br />

activation of an OData service definition.<br />

Note: The OData implem<strong>en</strong>tation in SAP HANA XS supports only those SQL types listed in the following<br />

table.<br />

Table 8: SAP HANA SQL to OData EDM Type Mapping<br />

SAP HANA SQL Type OData EDM Type<br />

Time Edm.Time<br />

Date Edm.DateTime<br />

186<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


SAP HANA SQL Type OData EDM Type<br />

SecondDate Edm.DateTime<br />

LongDate Edm.DateTime<br />

Timestamp Edm.DateTime<br />

TinyInt Edm.Byte<br />

SmallInt Edm.Int16<br />

Integer Edm.Int32<br />

BigInt Edm.Int64<br />

SmallDecimal Edm.Decimal<br />

Decimal Edm.Decimal<br />

Real Edm.Single<br />

Float Edm.Single<br />

Double Edm.Double<br />

Varchar Edm.String<br />

NVarchar Edm.String<br />

Char Edm.String<br />

NChar Edm.String<br />

Binary Edm.Binary<br />

Varbinary Edm.Binary<br />

Example SQL Type Mapping<br />

The following examples shows how SAP HANA SQL types (name, integer, Varchar) of columns in a table are<br />

mapped to the OData EDM types in the properties of an <strong>en</strong>tity type.<br />

SAP HANA SQL:<br />

{name = "ID"; sqlType = INTEGER; nullable = false;},<br />

{name = "RefereeID"; sqlType = VARCHAR; nullable = true;}<br />

The following example illustrates how the SAP HANA SQL types illustrated in the previous example are mapped to<br />

EDM types:<br />

<br />

<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 187


8.1.9 OData Service-Definition Examples<br />

The OData service definition describes how data exposed in an <strong>en</strong>d point can be accessed by cli<strong>en</strong>ts using the<br />

OData protocol.<br />

Each of the examples listed below is explained in a separate section. The examples show how to use the OData<br />

Service Definition Language (OSDL) in the OData service-definition file to g<strong>en</strong>erate an operational OData service<br />

that <strong>en</strong>ables cli<strong>en</strong>ts to use SAP HANA XS to access the OData <strong>en</strong>d point you set up.<br />

● Empty Service<br />

● Namespace Definition<br />

● Object Exposure<br />

● Property Projection<br />

● Key Specification<br />

● Associations<br />

● Aggregation<br />

● Parameter Entity Sets<br />

OData Empty Service<br />

An OData service for SAP HANA XS is defined by a text file containing at least the following line:<br />

Service definition sample.odata:empty.xsodata<br />

service {}<br />

A service file with the minimal cont<strong>en</strong>t g<strong>en</strong>erates an empty, completely operational OData service with an empty<br />

service catalog and an empty metadata file:<br />

http://localhost:8002/sample/odata/empty.xsodata<br />

http://localhost:8002/sample/odata/empty.xsodata/$metadata<br />

188<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


An empty service metadata docum<strong>en</strong>t consists of one Schema containing an empty EntityContainer. The<br />

name of the EntityContainer is the name of the .xsodata file, in this example "empty".<br />

OData Namespace Definition<br />

By default, as shown in the metadata file of an empty OData service, the namespace of the g<strong>en</strong>erated Schema is<br />

created by concat<strong>en</strong>ating the package name of the .xsodata file with the file name, and separating the<br />

concat<strong>en</strong>ated names with a dot. You can specify your own namespace by using the namespace keyword:<br />

Service definition sample.odata:namespace.xsodata<br />

service namespace "my.namespace" {}<br />

The resulting service metadata docum<strong>en</strong>t has the specified schema namespace:<br />

http://localhost:8002/sample/odata/namespace.xsodata/$metadata<br />

OData Object Exposure<br />

There are two ways of exposing SAP HANA objects. You can either specify the repository design-time name or the<br />

database-object runtime name (with database schema). Although both variants are supported, the preferred<br />

method is the exposure via the repository design-time name. It has the advantage that the OData service is<br />

automatically updated, if the underlying repository object changes. The support for database objects is mainly<br />

int<strong>en</strong>ded for existing or replicated objects that do not have a related repository design-time object.<br />

In the examples provided to illustrate object exposure, the following definition of a table applies:<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 189


Table definition sample.odata:table.hdbtable<br />

table.schemaName = "ODATASAMPLES";<br />

table.tableType = COLUMNSTORE;<br />

table.columns = [<br />

{name = "ID"; sqlType = INTEGER;},<br />

{name = "Text"; sqlType = NVARCHAR; l<strong>en</strong>gth=1000;},<br />

{name = "Time"; sqlType = TIMESTAMP;}<br />

];<br />

table.primaryKey.pkcolumns = ["ID"];<br />

Repository Objects<br />

If the object to expose via an OData service is created during an activation in the repository, th<strong>en</strong> it has a<br />

repository design-time repres<strong>en</strong>tation. Examples for those objects are tables, SQL views and calculation views. An<br />

example for exposing the table above is shown in the next listing.<br />

Service definition sample.odata:repo.xsodata<br />

service {<br />

"sample.odata:table.hdbtable" as "MyTable";<br />

}<br />

This service definition exposes a table defined in the .hdbtable file sample.odata:table.hdbtable and<br />

creates an EntitySet for this <strong>en</strong>tity named "MyTable". The specification of an alias is optional. If omitted the<br />

default name of the EntitySet is the name of the repository object file, here "table".<br />

http://localhost:8002/sample/odata/repo.xsodata<br />

http://localhost:8002/sample/odata/repo.xsodata/$metadata<br />

190<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


All information about the table, for example, the properties, the data types, and the primary key, is gathered from<br />

the database catalog.<br />

Database Objects<br />

Caution: Do not use catalog objects if a repository design-time object is available, as changes in the<br />

catalog object are not automatically reflected in the OData service.<br />

Similar to the exposure of an object by using the repository design-time name is the exposure by the database<br />

name:<br />

Service definition sample.odata:db.xsodata<br />

service {<br />

"ODATASAMPLES"."sample.odata:table.hdbtable" as "MyTable";<br />

}<br />

The service exposes the same table by using the database catalog name of the object and the name of the<br />

schema where the table is created in. The collection in the service catalog and the EntityType that is created in the<br />

metadata docum<strong>en</strong>t is exactly the same as for repository objects.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 191


OData Property Projection<br />

If the object you want to expose with an OData service has more columns than you actually want to expose, you<br />

can use SQL views to restrict the number of selected columns in the SELECT.<br />

Nevertheless, SQL views are sometimes not appropriate, for example with calculation views, and for these cases<br />

we provide the possibility to restrict the properties in the OData service definition in two ways. By providing an<br />

including or an excluding list of columns.<br />

Including Properties<br />

You can specify the columns of an object that have to be exposed in the OData service by using the with keyword.<br />

Key fields of tables must not be omitted.<br />

Service definition sample.odata:with.xsodata<br />

service {<br />

"sample.odata:table.hdbtable" as "MyTable" with ("ID","Text");<br />

}<br />

The resulting EntityType th<strong>en</strong> contains only the properties derived from the specified columns:<br />

http://localhost:8002/sample/odata/with.xsodata/$metadata<br />

Excluding Properties<br />

The opposite of the with keyword is the without keyword, which <strong>en</strong>ables you to specify which columns you do<br />

NOT want to expose in the OData service:<br />

Service definition sample.odata::without.xsodata<br />

service {<br />

"sample.odata:table.hdbtable" as "MyTable" without ("Text","Time");<br />

}<br />

The g<strong>en</strong>erated EntityType th<strong>en</strong> does NOT contain the properties derived from the specified columns:<br />

http://localhost:8002/sample/odata/without.xsodata/$metadata<br />

192<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


OData Key Specification<br />

The OData specification requires an EntityType to d<strong>en</strong>ote a set properties forming a unique key. In HANA only<br />

tables may have a unique key, the primary key. For all other (mostly view) objects you need to specify a key for the<br />

<strong>en</strong>tity. In OSDL you can do this by d<strong>en</strong>oting a set of existing columns or by g<strong>en</strong>erating a key.<br />

For the examples illustrating key specification, we use the following SQL view, which selects all data from the<br />

specified table.<br />

View definition sample.odata:view.hdbview<br />

{<br />

}<br />

"name": "view",<br />

"schema": "ODATASAMPLES",<br />

"query": "SELECT * FROM \"ODATASAMPLES\".\"sample.odata::table\""<br />

Existing Key Properties<br />

If the object has set of columns that may form a unique key, you can specify them as key for the <strong>en</strong>tity. These key<br />

properties are always selected from the database, no matter if they are omitted in the $select query option.<br />

Therefore explicit keys are not suitable for calculation views and analytic views as the selection has an impact on<br />

the result.<br />

Service definition sample.odata:explicitkeys.xsodata/$metadata<br />

service {<br />

"sample.odata:view.hdbview" as "MyView" keys ("ID","Text");<br />

}<br />

The created metadata docum<strong>en</strong>t for the exposure of the view above is almost equal to the metadata docum<strong>en</strong>t for<br />

repository objects. Only the key is differ<strong>en</strong>t and consists now of two columns:<br />

http://localhost:8002/sample/odata/explicitkeys.xsodata/$metadata<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 193


Caution: The OData infrastructure cannot check whether your specified keys are unique. So be careful<br />

wh<strong>en</strong> choosing keys.<br />

G<strong>en</strong>erated Local Key<br />

For objects that do not have a unique key in their results, for example, calculation views or aggregated tables, you<br />

can g<strong>en</strong>erate a locally valid key. This key value numbers the results starting with 1 and is not meant for<br />

derefer<strong>en</strong>cing the <strong>en</strong>tity; you cannot use this key to retrieve the <strong>en</strong>tity. The key is valid only for the duration of the<br />

curr<strong>en</strong>t session and is used only to satisfy OData's need for a unique ID in the results. The property type of a<br />

g<strong>en</strong>erated local key is Edm.String and cannot be changed.<br />

Service definition sample.odata:g<strong>en</strong>eratedkeys.xsodata<br />

http://localhost:8002/sample/odata/g<strong>en</strong>eratedkeys.xsodata/$metadata<br />

194<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


As a consequ<strong>en</strong>ce of the transi<strong>en</strong>t nature of g<strong>en</strong>erated local keys, it is not possible to define navigation properties<br />

on these <strong>en</strong>tities or use them in filter or order by conditions.<br />

OData Associations<br />

You can define associations betwe<strong>en</strong> <strong>en</strong>tities to express relationships betwe<strong>en</strong> <strong>en</strong>tities. With associations it is<br />

possible to reflect foreign key constraints on database tables, hierarchies and other relations betwe<strong>en</strong> database<br />

objects. OSDL supports simple associations, where the information about the relationship is stored in one of the<br />

participating <strong>en</strong>tities, and complex associations, where the relationship information is stored in a separate<br />

association table.<br />

Associations themselves are freestanding. On top of them you can specify which of the <strong>en</strong>tities participating in the<br />

relationship can navigate over the association to the other <strong>en</strong>tity by creating NavigationPropertys.<br />

For the examples used to illustrate OData associations, we use the tables customer and order:<br />

Table definition: sample.odata:customer.hdbtable<br />

table.schemaName = "ODATASAMPLES";<br />

table.tableType = COLUMNSTORE;<br />

table.columns = [<br />

{name = "ID"; sqlType = INTEGER; nullable = false;},<br />

{name = "RecruitID"; sqlType = VARCHAR; nullable = true;}<br />

];<br />

table.primaryKey.pkcolumns = ["ID"];<br />

Table definition: sample.odata:order.hdbtable<br />

table.schemaName = "ODATASAMPLES";<br />

table.tableType = COLUMNSTORE;<br />

table.columns = [<br />

{name = "ID"; sqlType = INTEGER; nullable = false;},<br />

{name = "CustomerID"; sqlType = INTEGER; nullable = false;}<br />

];<br />

table.primaryKey.pkcolumns = ["ID"];<br />

There is one relationship order.CustomerID to customer.ID and one relationship<br />

customer.RecruitID to customer.ID.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 195


Simple Associations<br />

The definition of an association requires you to specify a name, which refer<strong>en</strong>ces two exposed <strong>en</strong>tities and whose<br />

columns keep the relationship information. To distinguish the <strong>en</strong>ds of the association, you must use the keywords<br />

principal and dep<strong>en</strong>d<strong>en</strong>t. In addition, it is necessary to d<strong>en</strong>ote the multiplicity for each <strong>en</strong>d of the<br />

association.<br />

Service definition: sample.odata:assocsimple.xsodata<br />

service {<br />

"sample.odata:customer.hdbtable" as "Customers";<br />

"sample.odata:order.hdbtable" as "Orders";<br />

association "Customer_Orders" principal "Customers"("ID") multiplicity<br />

"1" dep<strong>en</strong>d<strong>en</strong>t "Orders"("CustomerID") multiplicity "*";<br />

}<br />

The association in the example above with the name Customer_Orders defines a relationship betwe<strong>en</strong> the<br />

table customer, id<strong>en</strong>tified by its EntitySet name Customers, on the principal <strong>en</strong>d, and the table<br />

order, id<strong>en</strong>tified by its <strong>en</strong>tity set name Orders, on the dep<strong>en</strong>d<strong>en</strong>t <strong>en</strong>d. Involved columns of both tables are<br />

d<strong>en</strong>oted in braces ({}) after the name of the corresponding <strong>en</strong>tity set. The multiplicity keyword on each <strong>en</strong>d<br />

of the association specifies their cardinality - in this example, one-to-many.<br />

The number of columns involved in the relationship must be equal for both <strong>en</strong>ds of the association, and their order<br />

in the list is important. The order specifies which column in one table is compared to which column in the other<br />

table. In this simple example, the column customer.ID is compared to order.CustomerID in the g<strong>en</strong>erated<br />

table join.<br />

As a result of the g<strong>en</strong>eration of the service definition above, an AssociationSet named Customer_Orders<br />

and an Association with name Customer_OrdersType are g<strong>en</strong>erated:<br />

http://localhost:8002/sample/odata/assocsimple.xsodata/$metadata<br />

196<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


The second association is similar to the first one and is shown in the following listing:<br />

association "Customer_Recruit" principal "Customers"("ID") multiplicity<br />

"1" dep<strong>en</strong>d<strong>en</strong>t "Customers"("RecruitID") multiplicity "*";<br />

Complex Associations<br />

For the following example of a complex association, an additional table named knows is introduced that contains a<br />

relationship betwe<strong>en</strong> customers.<br />

Table definition: sample.odata:knows.hdbtable<br />

table.schemaName = "ODATASAMPLES";<br />

table.tableType = COLUMNSTORE;<br />

table.columns = [<br />

{name = "KnowingCustomerID"; sqlType = INTEGER; nullable = false;},<br />

{name = "KnownCustomerID"; sqlType = INTEGER; nullable = false;}<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 197


];<br />

table.primaryKey.pkcolumns = ["KnowingCustomerID","KnownCustomerID"];<br />

Relationships that are stored in association tables such as knows can be similarly defined as simple associations.<br />

Use the keyword over to specify the additional table and any required columns.<br />

Service definition: sample.odata:assoccomplex.xsodata<br />

service {<br />

"sample.odata:customer.hdbtable" as "Customers";<br />

"sample.odata:order.hdbtable" as "Orders";<br />

association "Customer_Orders"<br />

principal "Customers"("ID") multiplicity "*"<br />

dep<strong>en</strong>d<strong>en</strong>t "Customers"("ID") multiplicity "*"<br />

over "sample.odata:knows.hdbtable" principal ("KnowingCustomerID")<br />

dep<strong>en</strong>d<strong>en</strong>t ("KnownCustomerID");<br />

}<br />

With the keywords principal and dep<strong>en</strong>d<strong>en</strong>t after over you can specify which columns from the<br />

association table are joined with the principal respectively dep<strong>en</strong>d<strong>en</strong>t columns of the related <strong>en</strong>tities. The<br />

number of columns must be equal in pairs, and their order in the list is important.<br />

The g<strong>en</strong>erated Association in the metadata docum<strong>en</strong>t is similar to the one created for a simple association<br />

except that the Refer<strong>en</strong>tialConstraint is missing:<br />

tp://localhost:8002/sample/odata/assoccomplex.xsodata/$metadata<br />

Navigation Properties<br />

By only defining an association, it is not possible to navigate from one <strong>en</strong>tity to another. Associations need to be<br />

bound to <strong>en</strong>tities by an NavigationProperty. You can create them by using the keyword navigates:<br />

Service definition: sample.odata:assocnav.xsodata<br />

service {<br />

"sample.odata:customer.hdbtable" as "Customers" navigates<br />

("Customer_Orders" as "HisOrders");<br />

"sample.odata:order.hdbtable" as "Orders";<br />

association "Customer_Orders" principal "Customers"("ID") multiplicity<br />

198<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


"1" dep<strong>en</strong>d<strong>en</strong>t "Orders"("CustomerID") multiplicity "*";<br />

}<br />

The example above says that it is possible to navigate from Customers over the association<br />

Customer_Order via the NavigationProperty named "HisOrders".<br />

The right association <strong>en</strong>d is determined automatically by the <strong>en</strong>tity set name. But if both <strong>en</strong>ds are bound to the<br />

same <strong>en</strong>tity, it is necessary to specify the starting <strong>en</strong>d for the navigation. This is done by specifying either from<br />

principal or from dep<strong>en</strong>d<strong>en</strong>t which refer to the principal and dep<strong>en</strong>d<strong>en</strong>t <strong>en</strong>ds in the association.<br />

Service definition: sample.odata:assocnavself.xsodata<br />

service {<br />

"sample.odata:customer.hdbtable" as "Customers"<br />

navigates ("Customer_Orders" as "HisOrders","Customer_Recruit" as<br />

"Recruit" from principal);<br />

"sample.odata:order.hdbtable" as "Orders";<br />

association "Customer_Orders" principal "Customers"("ID") multiplicity<br />

"1" dep<strong>en</strong>d<strong>en</strong>t "Orders"("CustomerID") multiplicity "*";<br />

association "Customer_Recruit" principal "Customers"("ID")<br />

multiplicity "1" dep<strong>en</strong>d<strong>en</strong>t "Customers"("RecruitID") multiplicity "*";<br />

}<br />

In both cases a NavigationProperty is added to the EntityType.<br />

http://localhost:8002/sample/odata/assocnavself.xsodata/$metadata<br />

OData Aggregation<br />

The results of aggregations on columns change dynamically dep<strong>en</strong>ding on the grouping conditions. This means<br />

that aggregation cannot be performed in SQL views; it needs to be specified in the OData service definition itself.<br />

Dep<strong>en</strong>ding on the type of object to expose, you need to explicitly specify the columns to aggregate and the<br />

function to use or derived them from metadata in the database.<br />

In g<strong>en</strong>eral, aggregations do not have consequ<strong>en</strong>ces for the metadata docum<strong>en</strong>t. It just effects the semantics of<br />

the concerning properties during runtime. The grouping condition for the aggregation contain all selected nonaggregated<br />

properties. Furthermore, aggregated columns cannot be used in $filter, and aggregation is only<br />

possible with g<strong>en</strong>erated keys.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 199


Derived Aggregation<br />

The simplest way to define aggregations of columns in an object is to derive this information from metadata in the<br />

database. The only objects with this information are calculation views and analytic views. For all other object<br />

types, for example, tables and SQL views, the activation will not work. To cause the service to use derived<br />

information, you must specify the keywords aggregates always, as illustrated in the following example:<br />

service {<br />

"sample.odata:calc.calculationview" as "CalcView"<br />

keys g<strong>en</strong>erate local "ID"<br />

aggregates always;<br />

}<br />

Explicit Aggregation<br />

The example for the explicit aggregation is based on the following table definition:<br />

sample.odata:rev<strong>en</strong>ues.hdbtable<br />

table.schemaName = "ODATASAMPLES";<br />

table.tableType = COLUMNSTORE;<br />

table.columns = [<br />

{name = "Month"; sqlType = INTEGER; nullable = false;},<br />

{name = "Year"; sqlType = INTEGER; nullable = false;},<br />

{name = "Amount"; sqlType = INTEGER; nullable = true;}<br />

];<br />

table.primaryKey.pkcolumns = ["Month","Year"];<br />

You can aggregate the columns of objects (without metadata) that are necessary for the derivation of aggregation<br />

by explicitly d<strong>en</strong>oting the column names and the functions to use, as illustrated in the following example of a<br />

service definition: sample.odata:aggrexpl.xsodata<br />

service {<br />

"sample.odata:rev<strong>en</strong>ues.hdbtable" as "Rev<strong>en</strong>ues"<br />

keys g<strong>en</strong>erate local "ID"<br />

aggregates always (SUM of "Amount");<br />

}<br />

The results of the <strong>en</strong>tity set Rev<strong>en</strong>ues always contain the aggregated value of the column Amount. To extract<br />

the aggregated rev<strong>en</strong>ue amount per year, add $select=Year,Amount to your requested URI.<br />

OData Parameter Entity Sets<br />

SAP HANA calculation views and analytic views can interpret input parameters. For OData, these parameters can<br />

be <strong>en</strong>tered by using a special parameter <strong>en</strong>tity set.<br />

Parameter <strong>en</strong>tity sets can be g<strong>en</strong>erated for both calculation views and analytic views by adding parameters via<br />

<strong>en</strong>tity to the <strong>en</strong>tity:<br />

service {<br />

"sample.odata:calc.calculationview" as "CalcView"<br />

keys g<strong>en</strong>erate local "ID"<br />

200<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


}<br />

parameters via <strong>en</strong>tity;<br />

During activation, the parameters specified in sample.odata:calc.calculationview are retrieved from<br />

the metadata of the calculation view and exposed as a new EntitySet named after the <strong>en</strong>tity set name and the<br />

suffix Parameters, for example, CalcViewParameters. A NavigationProperty named Results is<br />

g<strong>en</strong>erated to retrieve the results from the parameterized call.<br />

The name of the g<strong>en</strong>erated parameter <strong>en</strong>tity set and the navigation property can be customized, as illustrated in<br />

the following example:<br />

service {<br />

"sample.odata:calc.calculationview" as "CalcView"<br />

keys g<strong>en</strong>erate local "ID"<br />

parameters via <strong>en</strong>tity "CVParams" results property "Execute";<br />

}<br />

With the definition above, the name of the parameter <strong>en</strong>tity set is CVParams, and the name of the<br />

NavigationProperty for the results is Execute.<br />

8.2 Data Access with XMLA in SAP HANA XS<br />

In SAP HANA Ext<strong>en</strong>ded Application Services, the persist<strong>en</strong>ce model (for example, tables, views and stored<br />

procedures) is mapped to the consumption model that is exposed to cli<strong>en</strong>ts - the applications you write to extract<br />

data from the SAP HANA database.<br />

You can map the persist<strong>en</strong>ce and consumption models with XML for Analysis (XMLA). With XMLA, you write<br />

multi-dim<strong>en</strong>sional -expressions (MDX) queries wrapped in an XMLA docum<strong>en</strong>t. An XML for Analysis (XMLA)<br />

application running in SAP HANA application services is used to provide the consumption model for cli<strong>en</strong>t<br />

applications exchanging MDX queries (wrapped in XMLA docum<strong>en</strong>ts) with the SAP HANA database.<br />

XMLA uses Web-based services to <strong>en</strong>able platform-indep<strong>en</strong>d<strong>en</strong>t access to XMLA-compliant data sources for<br />

Online Analytical Processing (OLAP). XMLA <strong>en</strong>ables the exchange of analytical data betwe<strong>en</strong> a cli<strong>en</strong>t application<br />

and a multi-dim<strong>en</strong>sional data provider working over the Web, using a Simple Object Access Protocol (SOAP)based<br />

XML communication application-programming interface (API).<br />

Applications running in SAP HANA XS <strong>en</strong>able very accurate control of the flow of data betwe<strong>en</strong> the pres<strong>en</strong>tational<br />

layer, for example, in the Browser, and the data-processing layer in SAP HANA itself, where the calculations are<br />

performed, for example in SQL or SqlScript. If you <strong>dev</strong>elop and deploy an XMLA service running in SAP HANA XS,<br />

you can take advantage of the embedded access to SAP HANA that SAP HANA XS provides; the embedded<br />

access greatly improves <strong>en</strong>d-to-<strong>en</strong>d performance.<br />

8.2.1 XML for Analysis (XMLA)<br />

XML for Analysis (XMLA) uses Web-based services to <strong>en</strong>able platform-indep<strong>en</strong>d<strong>en</strong>t access to XMLA-compliant<br />

data sources for Online Analytical Processing (OLAP).<br />

XMLA <strong>en</strong>ables the exchange of analytical data betwe<strong>en</strong> a cli<strong>en</strong>t application and a multi-dim<strong>en</strong>sional data provider<br />

working over the Web, using a Simple Object Access Protocol (SOAP)-based XML communication applicationprogramming<br />

interface (API).<br />

Implem<strong>en</strong>ting XMLA in SAP HANA <strong>en</strong>ables third-party reporting tools that are connected to the SAP HANA<br />

database to communicate directly with the MDX interface. The XMLA API provides universal data access to a<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 201


particular source over the Internet, without the cli<strong>en</strong>t having to set up a special compon<strong>en</strong>t. XML for Analysis is<br />

optimized for the Internet in the following ways:<br />

● Query performance<br />

Time sp<strong>en</strong>t on queries to the server is kept to a minimum<br />

● Query type<br />

Cli<strong>en</strong>t queries are stateless by default; after the cli<strong>en</strong>t has received the requested data, the cli<strong>en</strong>t is<br />

disconnected from the Web server.<br />

In this way, tolerance to errors and the scalability of a source (the maximum permitted number of users) is<br />

maximized.<br />

XMLA Methods<br />

The specification defined in XML for Analysis Version 1.1 from Microsoft forms the basis for the implem<strong>en</strong>tation of<br />

XML for Analysis in SAP HANA.<br />

The following list describes the methods that determine the specification for a stateless data request and<br />

provides a brief explanation of the method's scope:<br />

● Discover<br />

Use this method to query metadata and master data; the result of the discover method is a rowset. You can<br />

specify options, for example, to define the query type, any data-filtering restrictions, and any required XMLA<br />

properties for data formatting.<br />

● Execute<br />

Use this method to execute MDX commands and receive the corresponding result set; the result of the<br />

Execute command could be a mult-idim<strong>en</strong>sional dataset or a tabular rowset. You can set options to specify<br />

any required XMLA properties, for example, to define the format of the returned result set or any local<br />

properties to use to determine how to format the returned data.<br />

8.2.2 XMLA Service Definition<br />

The XMLA service definition is a file you use to specify which data is exposed as XMLA collections. Exposed data is<br />

available for analysis and display by cli<strong>en</strong>t applications, for example, a browser that uses functions provided either<br />

by the XMLA service running in SAP HANA XS or by an XMLA cli<strong>en</strong>t library running on the cli<strong>en</strong>t system.<br />

To expose information via XMLA to applications using SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS),<br />

you define database views that provide the data with the required granularity and you use the XMLA service<br />

definition to control access to the exposed data.<br />

Note: SAP HANA XS supports XMLA version 1.1, which you can use to s<strong>en</strong>d MDX queries.<br />

An XMLA service for SAP HANA XS is defined in a text file with the file suffix .xsxmla, for example,<br />

XMLASrvDef.xsxmla. The file must contain only the <strong>en</strong>try {*}, which would g<strong>en</strong>erate a completely<br />

operational XMLA service.<br />

202<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


XMLA Service-Definition Keywords<br />

Curr<strong>en</strong>tly, the XMLA service-definition file <strong>en</strong>ables you to specify only that all authorized data is exposed to XMLA<br />

requests, as illustrated in the following example:<br />

Service {*}<br />

8.2.3 XMLA Security Considerations<br />

Enabling access to data by means of XMLA op<strong>en</strong>s up some security considerations that you need to address, for<br />

example, the data you want to expose, who can start the XMLA service, and so on.<br />

If you want to use XMLA to expose data to users and cli<strong>en</strong>ts in SAP HANA XS, you need to bear in mind the<br />

security considerations described in the following list:<br />

● Data Access<br />

●<br />

Restrict user select authorization for data exposed by the XMLA service<br />

● XMLA Statistical cont<strong>en</strong>t<br />

Restrict access to the URL/Path used to expose XMLA cont<strong>en</strong>t in the Web browser, for example, using the<br />

application-access file (.xsaccess)<br />

8.2.4 Multidim<strong>en</strong>sional Expressions (MDX)<br />

Multidim<strong>en</strong>sional Expressions (MDX) is a language you can use to query multidim<strong>en</strong>sional data stored in OLAP<br />

cubes.<br />

MDX uses a multidim<strong>en</strong>sional data model to <strong>en</strong>able navigation in multiple dim<strong>en</strong>sions, levels, and up and down a<br />

hierarchy. With MDX, you can access pre-computed aggregates at specified positions (levels or members) in a<br />

hierarchy.<br />

Note: MDX is an op<strong>en</strong> standard. However, SAP has <strong>dev</strong>eloped ext<strong>en</strong>sions to MDX that are designed to<br />

<strong>en</strong>able faster and more effici<strong>en</strong>t access to multidim<strong>en</strong>sional data, for example, to serve specific SAP<br />

HANA application requirem<strong>en</strong>ts and to optimize the resultset for SAP HANA cli<strong>en</strong>ts.<br />

MDX is implicitly a hierarchy-based paradigm. All members of all dim<strong>en</strong>sions must belong to a hierarchy. Ev<strong>en</strong> if<br />

you do not explicitly create hierarchies in your SAP HANA data model, the SAP HANA modeler implicitly<br />

g<strong>en</strong>erates default hierarchies for each dim<strong>en</strong>sion. All id<strong>en</strong>tifiers that are used to uniquely id<strong>en</strong>tify hierarchies,<br />

levels and members in MDX statem<strong>en</strong>ts (and metadata requests) embed the hierarchy name within the id<strong>en</strong>tifier.<br />

In SAP HANA, the standard use of MDX is to access SAP HANA models (for example, analytical and attribute<br />

views) that have be<strong>en</strong> designed, validated and activated in the modeler in the SAP HANA studio. The studio<br />

provides a graphical design <strong>en</strong>vironm<strong>en</strong>t that <strong>en</strong>ables detailed control over all aspects of the model and its<br />

language-context-s<strong>en</strong>sitive runtime repres<strong>en</strong>tation to users.<br />

MDX in SAP HANA uses a runtime cube model, which usually consists of an analytical (or calculation) view that<br />

repres<strong>en</strong>ts data in which dim<strong>en</strong>sions are modeled as attribute views. You can use the analytical view to specify<br />

whether a giv<strong>en</strong> attribute is int<strong>en</strong>ded for display purposes only or for aggregation. The key attributes of attribute<br />

views are linked to private attributes in an analytical view in order to connect the <strong>en</strong>tities. One b<strong>en</strong>efit of MDX in<br />

SAP HANA is the native support of hierarchies defined for attribute views.<br />

Note: MDX in SAP HANA includes native support of hierarchies defined for attribute views. SAP HANA<br />

supports level-based and par<strong>en</strong>t-child hierarchies and both types of hierarchies are accessible with MDX.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 203


SAP HANA supports the use of variables in MDX queries; the variables are a SAP-specific <strong>en</strong>hancem<strong>en</strong>t to<br />

standard MDX syntax. You can specify values for all mandatory variables that are defined in SAP HANA studio to<br />

various modeling <strong>en</strong>tities. The following example illustrates how to declare SAP HANA variables and their values:<br />

MDX<br />

Select<br />

From [MINI_C1_VAR]<br />

Where [Measures].[M2_1_M3_CONV]<br />

SAP VARIABLES [VAR_VAT] including 10,<br />

[VAR_K2] including 112,<br />

[VAR_TARGET_CURRENCY] including 'EUR',<br />

8.2.5 MDX Functions<br />

MDX in SAP HANA supports a variety of standard MDX functions.<br />

Table 9: Supported MDX Functions<br />

Function Description<br />

Aggregate Returns a calculated value using the appropriate aggregate function, based on the<br />

aggregation type of the member.<br />

Ancestor Returns the ancestor of a member at a specified level or at a specific distance away<br />

in the hierarchy.<br />

Ancestors Returns a set of all ancestors of a member at a specified level or at a specific<br />

distance away in the hierarchy.<br />

Asc<strong>en</strong>dants Returns the set of the asc<strong>en</strong>dants of the member.<br />

Avg Returns the average value of a numeric expression evaluated over a set.<br />

BottomCount Returns a specified number of items from the bottom of a set, optionally sorting<br />

the set first.<br />

Childr<strong>en</strong> Returns the childr<strong>en</strong> of a member.<br />

ClosingPeriod Returns the last sibling among the desc<strong>en</strong>dants of a member at a specified level.<br />

Count Counts the number of members in the tuple.<br />

Cousin Returns the child member with the same relative position under a par<strong>en</strong>t member<br />

as the specified child member.<br />

Crossjoin Returns the cross product of two sets.<br />

Curr<strong>en</strong>tMember Returns the curr<strong>en</strong>t member along a hierarchy.<br />

DefaultMember Returns the default member of a hierarchy.<br />

Desc<strong>en</strong>dants Returns the set of desc<strong>en</strong>dants of a member at a specified level or at a specific<br />

distance away in the hierarchy.<br />

Dim<strong>en</strong>sion Returns the hierarchy that contains a specified member or level.<br />

Dim<strong>en</strong>sions Returns a hierarchy specified by a numeric or string expression.<br />

Distinct Returns a set, removing duplicate tuples from a specified set.<br />

DistinctCount Returns the number of distinct tuples in a set.<br />

204<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


Function Description<br />

DrillDownLevel Drills down the members of a set one level below the lowest level repres<strong>en</strong>ted in the<br />

set, or to one level below an optional level of a member repres<strong>en</strong>ted in the set.<br />

DrillDownLevelBottom Drills down the members of a specified count of bottom members of a set, at a<br />

specified level, to one level below.<br />

DrillDownLevelTop Drills down a specified count of top members of a set, at a specified level, to one<br />

level below.<br />

DrillDownMember Drills down the members in a specified set that are pres<strong>en</strong>t in a second specified<br />

set.<br />

DrillDownMemberBottom Drills down the members in a specified set that are pres<strong>en</strong>t in a second specified<br />

set, limiting the result set to a specified number of bottommost members.<br />

DrillDownMemberTop Drills down the members in a specified set that are pres<strong>en</strong>t in a second specified<br />

set, limiting the result set to a specified number of topmost members.<br />

DrillUpLevel Drills up the members of a set that are below a specified level.<br />

DrillUpmember Drills up the members in a specified set that are pres<strong>en</strong>t in a second specified set.<br />

Except Finds the differ<strong>en</strong>ce betwe<strong>en</strong> two sets, optionally retaining duplicates.<br />

Filter Returns the set resulting from filtering a set based on a search condition.<br />

FirstChild Returns the first child of a specified member.<br />

FirstSibling Returns the first child of the par<strong>en</strong>t of a specified member.<br />

G<strong>en</strong>erate Applies a set to each member of another set, and th<strong>en</strong> joins the resulting sets by<br />

union. Alternatively, this function returns a concat<strong>en</strong>ated string created by<br />

evaluating a string expression over a set.<br />

Head Returns the first specified number of elem<strong>en</strong>ts in a set.<br />

Hierarchize Orders the members of a specified set in a hierarchy in natural or, optionally, postnatural<br />

order.<br />

Hierarchy<br />

Instr The InStr function finds the starting location of a substring within a specified string.<br />

Intersect Returns the intersection of two sets, optionally retaining duplicates.<br />

IsAncestor Returns true if the first member specified is an ancestor of the second member<br />

specified, else returns false.<br />

IsG<strong>en</strong>eration Returns true if the member specified is a leaf, else returns false.<br />

IsLeaf Returns true if the first member specified is an ancestor of the second member<br />

specified, else returns false.<br />

IsSibling Returns true if the first member specified is an sibling of the second member<br />

specified, else returns false.<br />

Item If an integer is specified, the Item function returns the tuple that is in the zerobased<br />

position specified by Index.<br />

IIF Returns one of values determined by a logical test.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 205


Function Description<br />

Lag Returns the member that is a specified number of positions prior to a specified<br />

member along the dim<strong>en</strong>sion of the member.<br />

LastChild Returns the last child of a specified member.<br />

LastPeriods Returns a set of members prior to and including a specified member.<br />

LastSibling Returns the last child of the par<strong>en</strong>t of a specified member.<br />

Lead Returns the member that is a specified number of positions following a specified<br />

member along the dim<strong>en</strong>sion of the member.<br />

Leaves If a dim<strong>en</strong>sion name is specified, returns a set that contains the leaf members of<br />

the key attribute for the specified dim<strong>en</strong>sion.If a dim<strong>en</strong>sion name is not specified,<br />

the function returns a set that contains the leaf members of the <strong>en</strong>tire cube.<br />

Left The Left function returns a string of a specified number of characters from the left<br />

side (beginning) of a specified string.<br />

Level Returns the level of a member.<br />

Levels Returns the level whose zero-based position in a dim<strong>en</strong>sion is specified by a<br />

numeric expression.<br />

Max Returns the maximum value of a numeric expression evaluated over a set.<br />

Member_caption Returns the caption of a member<br />

Members Returns the set of all members in a specified hierarchy.<br />

MembersAsc<strong>en</strong>dantsDesc<br />

<strong>en</strong>dants<br />

Returns the set of specified members in a giv<strong>en</strong> hierarchy.<br />

Mid The Mid function returns a substring of a string argum<strong>en</strong>t.<br />

Min Returns the minimum value of a numeric expression evaluated over a set<br />

MTD Returns a set of members from the Month level in a Time dim<strong>en</strong>sion starting with<br />

the first period and <strong>en</strong>ding with a specified member.<br />

Name Returns the name of a specified hierarchy or member.<br />

NextMember Returns the next member in the level that contains a specified member.<br />

NOT Performs a logical negation on a numeric expression.<br />

Op<strong>en</strong>ingPeriod Returns the first sibling among the desc<strong>en</strong>dants of a specified level, optionally at a<br />

specified member.<br />

OR Performs a logical disjunction on two numeric expressions.<br />

Ordinal Returns the zero-based ordinal value associated with a specified level.<br />

ParallelPeriod Returns a member from a prior period in the same relative position as a specified<br />

member.<br />

Par<strong>en</strong>t Returns the par<strong>en</strong>t of a specified member.<br />

PeriodsToDate Returns a set of members (periods) from a specified level starting with the first<br />

member and <strong>en</strong>ding with a specified member.<br />

206<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


Function Description<br />

PrevMember Returns the previous member in the level that contains a specified member.<br />

Properties Returns a string containing the value of the specified member property.<br />

QTD Returns a set of members from the Quarter level in a Time dim<strong>en</strong>sion starting with<br />

the first period and <strong>en</strong>ding with a specified member.<br />

Range Performs a set operation that returns a naturally ordered set, with the two<br />

specified members as <strong>en</strong>dpoints, and all members betwe<strong>en</strong> the two specified<br />

members included as members of the set<br />

Right The Right function returns a string of a specified number of characters from the<br />

right side (<strong>en</strong>d) of a specified string.<br />

Siblings Returns the set of siblings of a specified member, including the member itself.<br />

StrToMember Returns a member from a string expression in MDX format.<br />

StrToSet Constructs a set from a specified string expression in MDX format.<br />

StrToTuple Constructs a tuple from a specified string expression in MDX format.<br />

StrToValue Returns a value from a string expression<br />

Subset Returns a subset of tuples from a specified set.<br />

Sum Returns the sum of a numeric expression evaluated over a specified set.<br />

Tail Returns the last specified number of elem<strong>en</strong>ts in a set.<br />

TopCount Returns a specified number of items from the topmost members of a specified set,<br />

optionally ordering the set first.<br />

Union Performs a set operation that returns a union of two sets, removing duplicate<br />

members.<br />

UniqueName Returns the unique name of a specified hierarchy.<br />

WTD Returns a set of members from the Week level in a Time dim<strong>en</strong>sion starting with<br />

the first period and <strong>en</strong>ding with a specified member.<br />

YTD Returns a set of members from the Year level in a Time dim<strong>en</strong>sion starting with the<br />

first period and <strong>en</strong>ding with a specified member.<br />

8.2.6 MDX Ext<strong>en</strong>sions<br />

SAP HANA supports several ext<strong>en</strong>sions to the MDX language, for example, additional predefined functions and<br />

support for variables.<br />

Sibling_Ordinal Intrinsic Property<br />

The object Member includes a property called Sibling_Ordinal, that is equal to the 0-based position of the<br />

member within its siblings.<br />

WITH<br />

MEMBER [Measures].[Termination Rate] AS<br />

[Measures].[NET_SALES] / [Measures].[BILLED_QUANTITY]<br />

SELECT<br />

{<br />

[Measures].[NET_SALES],<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 207


[Measures].[BILLED_QUANTITY],<br />

[Measures].[Termination Rate]<br />

} ON COLUMNS,<br />

Desc<strong>en</strong>dants<br />

(<br />

[MDX_TEST_10_DISTRIBUTION_CHANNEL].<br />

[MDX_TEST_10_DISTRIBUTION_CHANNEL].[All].[(all)],<br />

1,<br />

SELF_AND_BEFORE<br />

)<br />

DIMENSION PROPERTIES SIBLING_ORDINAL ON ROWS<br />

FROM MDX_TEST_10_ITELO_SALES_DATA<br />

MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants Function<br />

SAP HANA includes a new function called MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants that <strong>en</strong>ables you to get, for<br />

example, all asc<strong>en</strong>dants and desc<strong>en</strong>dants of a specific member. This function improves on the standard MDX<br />

functions Asc<strong>en</strong>dants and Desc<strong>en</strong>dants.<br />

The function can be called as follows:<br />

MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants (, )<br />

● set: A set of members from a single hierarchy<br />

● flag: Indicates which related members to return, and can be one of the following:<br />

○ MEMBERS_AND_ASCENDANTS_AND_DESCENDANTS<br />

○ MEMBERS_AND_ASCENDANTS<br />

○ MEMBERS_AND_DESCENDANTS<br />

○ ASCENDANTS_AND_DESCENDANTS<br />

○ ONLY_ASCENDANTS<br />

○ ONLY_DESCENDANTS<br />

SELECT<br />

{ [Measures].[SALES] }<br />

ON COLUMNS,<br />

NON EMPTY<br />

{ Hierarchize( MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants([JUICE_TIME].[TimeHier].<br />

[QUARTER].[3]:[JUICE_TIME].[TimeHier].[QUARTER].[4],<br />

MEMBERS_AND_ASCENDANTS_AND_DESCENDANTS )) }<br />

ON ROWS<br />

FROM [JUICE]<br />

SELECT<br />

{ [Measures].[SALES] }<br />

ON COLUMNS,<br />

NON EMPTY<br />

{ Hierarchize( MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants([JUICE_TIME].[TimeHier].<br />

[QUARTER].[3]:[JUICE_TIME].[TimeHier].[QUARTER].[4],<br />

ONLY_ASCENDANTS )) }<br />

ON ROWS<br />

FROM [JUICE]<br />

Variables<br />

An MDX SELECT statem<strong>en</strong>t in SAP HANA <strong>en</strong>ables you to s<strong>en</strong>d values for variables defined within modeling views.<br />

208<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


Analytic and calculation views can contain variables, that can be bound to specific attributes. Wh<strong>en</strong> calling the<br />

view, you can s<strong>en</strong>d values for those variables. These variables can be used, for example, to filter the results.<br />

SAP HANA supports an ext<strong>en</strong>sion to MDX whereby you can pass values for variables defined in views by adding a<br />

SAP Variables clause in your select statem<strong>en</strong>t. Here is the syntax for a Select statem<strong>en</strong>t:<br />

: [WITH ]<br />

SELECT [[,...]]<br />

FROM <br />

[WHERE <br />

SAP VARIABLES: [[,] …]]<br />

: [] <br />

: INCLUDING | EXCLUDING<br />

: = | > | >= | < |


8.2.7 Defining the Data an XMLA Service Exposes<br />

An XMLA service exposes data stored in database tables for analysis and display by cli<strong>en</strong>t applications. However,<br />

first of all, you need to <strong>en</strong>sure that the tables and views to expose as an XMLA service actually exist and are<br />

accessible.<br />

To define the data to expose using an XMLA service, you must perform at least the following tasks:<br />

1. Create a simple database schema.<br />

2. Create a simple database table to expose with an XMLA service.<br />

3. If required, create a simple database view to expose with an XMLA service.<br />

4. Grant select privileges to the tables and views to be exposed with the XMLA service.<br />

8.2.8 Creating an XMLA Service Definition<br />

The XMLA service definition is a file you use to specify which data is exposed as XMLA/MDX collections for<br />

analysis and display by cli<strong>en</strong>t applications.<br />

An XMLA service for SAP HANA XS is defined in a text file with the file suffix .xsxmla, for example,<br />

XMLASrvDef.xsxmla. The file resides in the package hierarchy of the XMLA application and must contain the<br />

<strong>en</strong>try service {*}, which g<strong>en</strong>erates an operational XMLA service.<br />

Prerequisities for the creation of an XMLA service definition:<br />

● SAP HANA studio and cli<strong>en</strong>t installed and configured<br />

● SAP HANA database user available with repository privileges (for example, to add packages)<br />

● A SAP HANA <strong>dev</strong>elopm<strong>en</strong>t system added to (and available in) SAP HANA studio, for example, in either the<br />

Navigator view or the SAP HANA Repositories view<br />

● A working <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t including a repository workspace, a package structure for your XMLA<br />

application, and a shared project to <strong>en</strong>able you to synchronize changes to the XMLA project files in the local<br />

file system with the repository<br />

● Data is available to expose using the XMLA interface<br />

1. In the shared project you are using for your XMLA application, use the Project Explorer view to locate the<br />

package where you want to create the new XMLA service definition.<br />

Note: The file containing the XMLA service definition must be placed in the root package of the XMLA<br />

application for which the service is int<strong>en</strong>ded.<br />

2. Create the file that will contain your XMLA service definition.<br />

In the Project Explorer view, right-click the folder where you want to create the new XMLA service-definition<br />

file and choose New File in the context-s<strong>en</strong>sitive popup m<strong>en</strong>u displayed.<br />

3. Create the XMLA service definition.<br />

210<br />

The XMLA service definition is a configuration file that you use to specify which data is to be exposed as an<br />

XMLA collection.<br />

The following code is an example of a valid XMLA service definition, which exposes all authorized data to<br />

XMLA requests:<br />

{*}<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access


4. Place the valid XMLA service definition in the root package of the XMLA application.<br />

5. Save, commit, and activate the XMLA service definition in the SAP HANA repository.<br />

SAP HANA Developer Guide<br />

Defining Web-based Data Access<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 211


9 Writing Server-Side JavaScript<br />

Applications<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) provide applications and application <strong>dev</strong>elopers with<br />

access to the SAP HANA database using a consumption model that is exposed via HTTP.<br />

In addition to providing application-specific consumption models, SAP HANA XS also host system services that<br />

are part of the SAP HANA database, for example: search services and a built-in Web server that provides access<br />

to static cont<strong>en</strong>t stored in the SAP HANA repository.<br />

The consumption model provided by SAP HANA XS focuses on server-side applications writt<strong>en</strong> in JavaScript. The<br />

server-side JavaScript applications can make use of a powerful set of specially <strong>dev</strong>eloped API functions, for<br />

example, to <strong>en</strong>able access to the curr<strong>en</strong>t request session or the database. This section describes how to write a<br />

server-side JavaScript application that <strong>en</strong>ables you to expose data, for example, using a Web Browser or any<br />

other HTTP cli<strong>en</strong>t.<br />

9.1 Data Access with JavaScript in SAP HANA XS<br />

In SAP HANA Ext<strong>en</strong>ded Application Services, the persist<strong>en</strong>ce model (for example, tables, views and stored<br />

procedures) is mapped to the consumption model that is exposed via HTTP to cli<strong>en</strong>ts - the applications you write<br />

to extract data from SAP HANA.<br />

You can map the persist<strong>en</strong>ce and consumption models in the following way:<br />

● Application-specific code<br />

Write code that runs in SAP HANA application services. Application-specific code (for example, server-side<br />

JavaScript) is used in SAP HANA application services to provide the consumption model for cli<strong>en</strong>t<br />

applications.<br />

Applications running in SAP HANA XS <strong>en</strong>able you to accurately control the flow of data betwe<strong>en</strong> the<br />

pres<strong>en</strong>tational layer, for example, in the Browser, and the data-processing layer in SAP HANA itself, where the<br />

calculations are performed, for example in SQL or SQLScript. If you <strong>dev</strong>elop and deploy a server-side JavaScript<br />

application running in SAP HANA XS, you can take advantage of the embedded access to SAP HANA that SAP<br />

HANA XS provides; the embedded access greatly improves <strong>en</strong>d-to-<strong>en</strong>d performance.<br />

9.2 Writing JavaScript Code<br />

9.2.1 Server-Side JavaScript in SAP HANA XS<br />

SAP HANA application services (XS server) supports server-side application programming in JavaScript. The<br />

server-side application you <strong>dev</strong>elop can use a collection of JavaScript APIs to expose authorized data to cli<strong>en</strong>t<br />

requests, for example, to be consumed by a cli<strong>en</strong>t GUI such as a Web browser or any other HTTP cli<strong>en</strong>t.<br />

212<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications


The functions provided by the JavaScript APIs <strong>en</strong>able server-side JavaScript applications to perform the following<br />

actions:<br />

● Interact with the SAP HANA XS runtime <strong>en</strong>vironm<strong>en</strong>t<br />

● Directly access SAP HANA database capabilities<br />

Note: Unlike OData and XMLA, the JavaScript API <strong>en</strong>ables you not only to expose data but to update,<br />

insert, and delete data, too.<br />

JavaScript programs are stored in the repository along with all the other <strong>dev</strong>elopm<strong>en</strong>t resources. Wh<strong>en</strong> the<br />

programs are activated, the code is stored in the repository as a runtime object.<br />

9.2.2 JavaScript Editor<br />

You can write server-side JavaScript using the SAP HANA studio JavaScript editor, which provides syntax<br />

validation, code highlighting and code completion.<br />

Wh<strong>en</strong> you edit a JavaScript file within an XS JavaScript project, the editor automatically has a refer<strong>en</strong>ce to the XS<br />

JavaScript API. You can access the API’s objects by <strong>en</strong>tering $, following by a period (.), and the objects are<br />

available, as in the following example.<br />

JSLint Validations<br />

The JavaScript editor includes the JSLint op<strong>en</strong>-source library, which helps to validate JavaScript code. The editor<br />

highlights any code that does not conform to the JSLint standards.<br />

To configure the JSLint library and determine which validations are performed, go to:<br />

Windows Prefer<strong>en</strong>ces JSLint<br />

In the prefer<strong>en</strong>ces window, each JSLint setting is followed by the corresponding JSLint command name, which<br />

you can use to lookup more information on the JSLint Web site.<br />

Related Links<br />

JSLint Web Site<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 213


9.2.3 Writing Server-Side JavaScript Applications<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) supports server-side application programming in<br />

JavaScript. The server-side application you <strong>dev</strong>elop can use a collection of JavaScript APIs to expose authorized<br />

data to cli<strong>en</strong>t requests, for example, to be consumed by a cli<strong>en</strong>t GUI such as a Web browser including SAPUI5<br />

applications and mobile cli<strong>en</strong>ts.<br />

Since JavaScript programs are stored in the SAP HANA repository, the steps in this task description assume that<br />

you have already created a workspace and a project (of type XS Project), and that you have shared the project<br />

with other members of the <strong>dev</strong>elopm<strong>en</strong>t team. To write a server-side JavaScript application, you must perform<br />

the following high-level steps.<br />

1. Create a root package for your application, for example, helloxsjs.<br />

2. Create an application descriptor for your application and place it in the root package you created in the<br />

previous step.<br />

The application descriptor is the core file that you use to describe an application's availability within SAP<br />

HANA Ext<strong>en</strong>ded Application Services. The application-descriptor file has no cont<strong>en</strong>ts and no name; it only has<br />

the file ext<strong>en</strong>sion .xsapp.<br />

Note: For backward compatibility, cont<strong>en</strong>t is allowed in the .xsapp file but ignored.<br />

3. Create an application-access file and place it in the package to which you want to grant access.<br />

The application-access file does not have a name; it only has the file ext<strong>en</strong>sion .xsaccess. The cont<strong>en</strong>ts of<br />

the .xsaccess file must be formatted according to JavaScript Object Notation (JSON) rules and associated<br />

with the package the file belongs to. The rules defined in the .xsaccess file apply to the package it resides in<br />

as well as any subpackages lower in the package hierarchy.<br />

4. If you used the authorization keyword in the application-access file (.xsaccess) file for your application,<br />

create an application-privileges file for the application and define the application privileges.<br />

The application-privileges file does not have a name; it only has the file ext<strong>en</strong>sion .xsprivileges. The<br />

cont<strong>en</strong>ts of the .xsprivileges file must be formatted according to JavaScript Object Notation (JSON)<br />

rules. Multiple .xsprivileges files are allowed, but only at differ<strong>en</strong>t levels in the package hierarchy; you<br />

cannot place two .xsprivileges files in the same application package. The privileges defined in<br />

a .xsprivileges file are bound to the package to which the file belongs and can only be applied to this<br />

package and its subpackages.<br />

Note: The .xsprivileges file lists the authorization levels available for granting to an application<br />

package; the .xsaccess file defines which authorization level is assigned to which application<br />

package.<br />

5. Create the server-side JavaScript files that contain the application logic.<br />

214<br />

You can use the available JavaScript APIs (for example, the database or request-processing API) to expose<br />

authorized data to cli<strong>en</strong>t requests.<br />

Server-side JavaScript files have the file suffix .xsjs, for example, hello.xsjs and contain the code that is<br />

executed wh<strong>en</strong> SAP HANA XS handles a URL request.<br />

$.response.cont<strong>en</strong>tType = "text/plain";<br />

$.response.setBody( "Hello, World!");<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications


6. Check the layout workspace.<br />

Your application package structure should have a structure that looks like the following example:<br />

.<br />

\<br />

helloxsjs<br />

\.xsapp<br />

.xsaccess<br />

hello.xsjs<br />

7. Save and activate your changes and additions.<br />

8. View the results.<br />

The SAP HANA XS Web server <strong>en</strong>ables you to view the results immediately after activation in the repository,<br />

for example: http://dbhost:80/helloxsjs/hello.xsjs<br />

9.3 Writing JavaScript Libraries<br />

9.3.1 Server-Side JavaScript Libraries<br />

The elem<strong>en</strong>ts defined in normal server-side JavaScript programs cannot be accessed from other JavaScript<br />

programs. To <strong>en</strong>able the reuse of program elem<strong>en</strong>ts, SAP HANA Ext<strong>en</strong>ded Application Services support serverside<br />

JavaScript libraries.<br />

Server-side JavaScript libraries are a special type of JavaScript program that can be imported and called in other<br />

JavaScript programs. You can use JavaScript libraries to perform simple, repetitive tasks, for example, to handle<br />

forms and form date, to manipulate date and time strings, to parse URLs, and so on.<br />

Note: JavaScript libraries are internally <strong>dev</strong>eloped ext<strong>en</strong>sions for SAP HANA.<br />

The following example shows how to import a JavaScript mathematics library using the import function:<br />

// import math lib<br />

$.import("sap.myapp.lib","math");<br />

// use math lib<br />

var max_res = $.sap.myapp.lib.math.max(3, 7);<br />

The import function requires the following parameters:<br />

● Package name<br />

Full name of the package containing the library object you want to import, for example, sap.myapp.lib<br />

● Library name<br />

Name of the library object you want to import, for example, math<br />

9.3.2 Writing Server-Side JavaScript Libraries<br />

Server-side JavaScript libraries are a special type of JavaScript program that can be imported and called in other<br />

JavaScript programs. You can use JavaScript libraries to perform simple, repetitive tasks, for example, to handle<br />

forms and form date, to manipulate date and time strings, to parse URLs, and so on.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 215


JavaScript libraries are internally <strong>dev</strong>eloped ext<strong>en</strong>sions for SAP HANA. However, you can write your own libraries,<br />

too. JavaScript libraries exist in the context of a package, which is refer<strong>en</strong>ced wh<strong>en</strong> you import the library. To<br />

write a JavaScript library to use in your server-side JavaScript application, perform the following steps:<br />

1. Create the file that contains the JavaScript library you want to add to the package and make available for<br />

import.<br />

In SAP HANA XS, server-side JavaScript libraries have the file ext<strong>en</strong>sion .xsjslib, for example<br />

greetLib.xsjslib.<br />

The following example creates a simple library that displays the word “Hello” along with a supplied name and<br />

adds an exclamation point (!) as a suffix.<br />

var greetingPrefix = "Hello, ";<br />

var greetingSuffix = "!";<br />

function greet (name) {<br />

return greetingPrefix + name + greetingSuffix;<br />

}<br />

2. Save the new JavaScript library.<br />

It is important to remember where the JavaScript library is located; you have to refer<strong>en</strong>ce the package path<br />

wh<strong>en</strong> you import the library.<br />

3. Activate your new library in the repository so that it is available for import by other JavaScript applications.<br />

9.3.3 Importing Server-Side JavaScript Libraries<br />

Server-side JavaScript libraries are a special type of JavaScript program that can be imported and called in other<br />

JavaScript programs. You can use JavaScript libraries to perform simple, repetitive tasks, for example: handle<br />

forms and form date, manipulate date and time strings, parse URLs, and so on.<br />

JavaScript libraries are internally <strong>dev</strong>eloped ext<strong>en</strong>sions for SAP HANA. The libraries exist in the context of a<br />

package, which is refer<strong>en</strong>ced wh<strong>en</strong> you import the library. The following example of a JavaScript library displays<br />

the word "Hello" along with a name and an exclamation mark as a suffix.<br />

var greetingPrefix = "Hello, ";<br />

var greetingSuffix = "!";<br />

function greet (name) {<br />

return greetingPrefix + name + greetingSuffix;<br />

}<br />

Note: This procedure uses the illustrated example JavaScript library to explain what happ<strong>en</strong>s wh<strong>en</strong> you<br />

import a JavaScript library, for example, which objects are created, wh<strong>en</strong>, and where. If you have your own<br />

library to import, substitute the library names and paths shown in the steps below as required.<br />

To import a JavaScript library for use in your server-side JavaScript application, perform the following tasks<br />

1. Import the JavaScript library into a JavaScript application.<br />

216<br />

Op<strong>en</strong> the server-side JavaScript file into which you want to import the JavaScript library.<br />

Use the $.import function, as follows:<br />

$.import("","greetLib");<br />

var greeting = $.path.to.your.library.fil<strong>en</strong>ame.greet("World");<br />

$.response.setBody(greeting);<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications


2. Save and activate the changes to the JavaScript file.<br />

Although the operation is simple, bear in mind the following points:<br />

○ Additional objects in the package hierarchy<br />

The import operation g<strong>en</strong>erates a hierarchy of objects below $ that resemble the library's location in the<br />

repository, for example, for the library path/to/your/library/greetLib.xsjslib, you would see<br />

the following additional object:<br />

$.path.to.your.library.greetLib<br />

○ Additional properties for the newly g<strong>en</strong>erated library object:<br />

$.path.to.your.library.greetLib.greet()<br />

$.path.to.your.library.greetLib.greetingSuffix<br />

$.path.to.your.library.greetLib.greetingPrefix<br />

○ Pre-import checks:<br />

○ It is not possible to import the refer<strong>en</strong>ced library if the import operation would override any<br />

predefined runtime objects.<br />

○ Do not import the refer<strong>en</strong>ced library if it is already pres<strong>en</strong>t in the package.<br />

○ Library context<br />

Imported libraries exist in the context defined by their repository location.<br />

9.4 Server-Side JavaScript APIs<br />

SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS) provides a set of server-side JavaScript application<br />

programming interfaces (API) that <strong>en</strong>able you to configure your applications to interact with SAP HANA.<br />

The SAP HANA XS API Refer<strong>en</strong>ce lists all the functions that are available for use wh<strong>en</strong> programing interaction<br />

betwe<strong>en</strong> your application and SAP HANA. For example, you can use the database API to invoke SQL statem<strong>en</strong>ts<br />

from inside your application, or access details of the curr<strong>en</strong>t HTTP request for SAP HANA data with the requestprocessing<br />

API.SAP HANA XS includes the following set of server-side JavaScript APIs:<br />

● Request-Processing API<br />

Enables access to the context of the curr<strong>en</strong>t HTTP request, for example, for read requests and write<br />

responses. You can use the functions provided by this API to manipulate the cont<strong>en</strong>t of the request and the<br />

response.<br />

● Database API<br />

Enables access to the SAP HANA by means of SQL statem<strong>en</strong>ts. For example, you can op<strong>en</strong> a connection to<br />

commit or rollback changes in SAP HANA, to prepare stored procedures (or SQL statem<strong>en</strong>ts) for execution or<br />

to return details of a result set or a result set's metadata.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 217


Request-Processing API Example<br />

The following example shows how to use the request-processing API to display the message “Hello World” in a<br />

browser.<br />

$.response.cont<strong>en</strong>tType = "text/plain";<br />

$.response.setBody( "Hello, World !");<br />

Database API Example<br />

The following example shows how to use the database API to prepare and execute an SQL statem<strong>en</strong>t. The<br />

response to the SQL query is th<strong>en</strong> prepared and displayed in a Web browser.<br />

var conn = $.db.getConnection();<br />

var pstmt = conn.prepareStatem<strong>en</strong>t( "select * from DUMMY" );<br />

var rs = pstmt.executeQuery();<br />

$.response.cont<strong>en</strong>tType = "text/plain";<br />

if (!rs.next()) {<br />

$.response.setBody( "Failed to retreive data" );<br />

$.response.status = $.net.http.INTERNAL_SERVER_ERROR;<br />

} else {<br />

$.response.setBody("Response: " + rs.getString(1));<br />

}<br />

rs.close();<br />

pstmt.close();<br />

conn.close();<br />

Related Links<br />

SAP HANA XS JavaScript Refer<strong>en</strong>ce<br />

9.5 The SQL Connection Configuration File<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), you use the SQL-connection configuration file to<br />

<strong>en</strong>able the execution of SQL statem<strong>en</strong>ts from inside your server-side JavaScript application with cred<strong>en</strong>tials that<br />

are differ<strong>en</strong>t to the cred<strong>en</strong>tials of the requesting user.<br />

In cases where it is necessary to execute SQL statem<strong>en</strong>ts from inside your JavaScript application with cred<strong>en</strong>tials<br />

that are differ<strong>en</strong>t to the cred<strong>en</strong>tials of the requesting user, SAP HANA XS <strong>en</strong>ables you to define the configuration<br />

for individual SQL connections. Each connection configuration has a unique name, for example, Registration or<br />

AdminConn, which is g<strong>en</strong>erated from the name of the corresponding connection-configuration file<br />

(Registration.xssqlcc or AdminConn.xssqlcc) on activation in the repository. The administrator can<br />

assign specific, individual database users to this configuration, and you can use the configuration name to<br />

refer<strong>en</strong>ce the unique SQL connection configuration from inside your JavaScript application code.<br />

If you want to create an SQL connection configuration, you must create the configuration as a flat file and save the<br />

file with the suffix .xssqlcc, for example, MYSQLconnection.xssqlcc. The new configuration file must be<br />

located in the same package as the application that refer<strong>en</strong>ces it. You can activate repository files at any point in<br />

time.<br />

218<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications


Note: A SQL connection configuration can only be accessed from a SAP HANA XS JavaScript application<br />

(.xsjs) file that is in the same package as the SQL connection configuration itself. Neither subpackages<br />

nor sibling packages are allowed to access an SQL connection configuration.<br />

The following example shows the composition and structure of a configuration file AdminConn.xssqlcc for an<br />

SAP HANA XS SQL connection called AdminConn. On activation of the SQL connection configuration file<br />

AdminConn.xssqlcc (for example, in the package sap.<strong>hana</strong>.sqlcon), an SQL connection configuration with<br />

the name sap.<strong>hana</strong>.sqlcon::AdminConn is created, which can be refer<strong>en</strong>ced in your JavaScript application.<br />

sap.<strong>hana</strong>.sqlcon:AdminConn.xssqlcc<br />

{<br />

}<br />

"description" : "Admin SQL connection"<br />

To create a preconfigured SQL connection using the configuration object AdminConn, for example, from inside<br />

your JavaScript application code, you refer<strong>en</strong>ce the object using the object name and full package path, as<br />

illustrated in the following code example.<br />

Calling the SAP HANA XS SQL-Connection Configuration File<br />

function test() {<br />

var body;<br />

var conn;<br />

$.response.status = $.net.http.OK;<br />

try {<br />

conn = $.db.getConnection("sap.<strong>hana</strong>.sqlcon::AdminConn");<br />

var pStmt = conn.prepareStatem<strong>en</strong>t("select CURRENT_USER from<br />

dummy");<br />

var rs = pStmt.executeQuery();<br />

if (rs.next()) {<br />

body = rs.getNString(1);<br />

}<br />

rs.close();<br />

pStmt.close();<br />

} catch (e) {<br />

body = "Error: exception caught";<br />

$.response.status = $.net.http.BAD_REQUEST;<br />

}<br />

if (conn) {<br />

conn.close();<br />

}<br />

$.response.setBody( body );<br />

}<br />

test();<br />

To use the SQL connection from your application during runtime, you must bind the SQL connection configuration<br />

to a database user. To maintain this user mapping, SAP HANA XS provides a dedicated application (the SQL<br />

Connection Configuration Application), which is pre-installed and accessible under the URL http://<br />

:/sap/<strong>hana</strong>/xs/sqlcc/. You can grant one of the following roles for users who want to use the<br />

SQL Connection Configuration Application to view or maintain the available SQL connection configurations:<br />

● sap.<strong>hana</strong>.xs.sqlcc::Viewer<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 219


Required to display the available SQL Connections and the curr<strong>en</strong>t user mapping<br />

● sap.<strong>hana</strong>.xs.sqlcc::Administrator<br />

Required to change the user mapping<br />

9.6 Tracing JavaScript<br />

9.6.1 Server-Side JavaScript Tracing<br />

The SAP HANA XS server-side JavaScript API provides tracing functions that <strong>en</strong>able your application to write<br />

predefined messages in the form of application-specific trace output in the xs<strong>en</strong>gine trace files (xs<strong>en</strong>gine*.trc)<br />

according to the trace level you specify, for example, “info”(information) or “error”.<br />

If you use the server-side JavaScript API to <strong>en</strong>able your application to write trace output, you can choose from the<br />

following trace levels:<br />

● debug<br />

● info<br />

● warning<br />

● error<br />

● fatal<br />

For example, to <strong>en</strong>able debug-level tracing for your JavaScript application:<br />

$.trace.debug("request path: " + $.request.path);<br />

Note: You can view the xs<strong>en</strong>gine*.trace files in the Diagnosis Files tab page in the Administration<br />

perspective of the SAP HANA studio.<br />

9.6.2 Tracing Server-Side JavaScript Applications<br />

The server-side JavaScript API for SAP HANA XS <strong>en</strong>ables you to activate the writing of trace messages into an<br />

application-specific trace file; the following trace levels are available: debug, error, fatal, info, and warning.<br />

By default, applications write messages of severity level error to the xs<strong>en</strong>gine*.trc trace files; you can increase<br />

the trace level manually, for example, to fatal. In SAP HANA XS, the following steps are required to <strong>en</strong>able trace<br />

output for your server-side JavaScript application:<br />

1. Op<strong>en</strong> the SAP HANA studio.<br />

2. In the Navigator view, double-click the SAP HANA instance to op<strong>en</strong> the Administration view for the repository<br />

where your server-side JavaScript source files are located.<br />

3. Choose the Trace Configuration view.<br />

4. In the Global Database Trace scre<strong>en</strong> area, choose Edit Configuration.<br />

The Edit Configuration icon is only visible if you have the required privileges on the selected SAP HANA<br />

system.<br />

5. Select the Show All Compon<strong>en</strong>ts checkbox.<br />

6. Enter the partial or full name of your application into the search box.<br />

7. Expand the GLOBAL node, if necessary, to view registered traces for the application name returned by the<br />

search operation.<br />

220<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications


8. Find the trace matching your application name and select the trace level you want to use to g<strong>en</strong>erate output.<br />

The application name is the location (package) of the .xsapp file associated with the application you are<br />

tracing. The trace topic is named xsa: .<br />

9. Choose Finish to activate the trace level changes.<br />

9.6.3 Viewing Server-Side JavaScript Application Trace Files<br />

The server-side JavaScript API for SAP HANA XS <strong>en</strong>ables you to instruct your JavaScript applications to write<br />

application-specific trace messages in the xs<strong>en</strong>gine*.trc trace files, which you can view in the Diagnosis Files<br />

tab page of the Administration perspective in the SAP HANA studio. The following trace levels are available:<br />

debug, error, fatal, info, and warning.<br />

To view trace output for your server-side JavaScript application, perform the following steps:<br />

1. Op<strong>en</strong> the SAP HANA studio.<br />

2. In the Navigator view, double-click the SAP HANA instance to op<strong>en</strong> the Administration view for the repository<br />

where your server-side JavaScript source files are located.<br />

3. Choose the Diagnosis Files tab page.<br />

4. In the Filter box, <strong>en</strong>ter a string to filter the list of search files displayed, for example, xs<strong>en</strong>gine*.trc.<br />

The timestamp displayed in the Modified column does not always reflect the precise time at which the trace<br />

file was writt<strong>en</strong> or most rec<strong>en</strong>tly modified.<br />

5. Locate the trace file for your SAP HANA XS application and doubleclick the <strong>en</strong>try to display the cont<strong>en</strong>ts of<br />

the selected trace-file in a separate tab page.<br />

9.7 Debugging JavaScript<br />

SAP HANA studio <strong>en</strong>ables you to debug XS JavaScript files, including setting breakpoints and inspecting<br />

variables.<br />

Caution: A port must be op<strong>en</strong>ed to <strong>en</strong>able debugging. For security reasons, the debug port is turned off by<br />

default.<br />

1. In a browser, run the XS JavaScript source file that you want to debug.<br />

2. Create a debug configuration for debug sessions for a specific SAP HANA installation.<br />

a) Op<strong>en</strong> the Debug perspective.<br />

b) Choose and select Debug Configurations.<br />

c) Create a new XS JavaScript configuration by double-click XS JavaScript.<br />

d) Enter a name for the configuration.<br />

e) Enter the host and debug port for your SAP HANA system.<br />

f) Select Apply.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 221


g) Select Close.<br />

3. Set breakpoints in the JavaScript code by double-clicking on the left vertical ruler.<br />

4. Run your debug configuration for your server by choosing and selecting your debug configuration.<br />

5. In the Select Session window, select the SAP HANA XS session ID you are debugging, and th<strong>en</strong> click Select.<br />

222<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications


The session ID is the value of the xsSessionId cookie in your browser session.<br />

6. Refresh the browser. The XS JavaScript is now running in debug mode. Your cli<strong>en</strong>t is now attached to the<br />

session, and execution is susp<strong>en</strong>ded at the first breakpoint.<br />

You can now perform standard Eclipse debug tasks, such as resuming execution, stepping through execution, and<br />

adding breakpoints. The following debug views are available:<br />

● Debug<br />

● Breakpoints<br />

● Variables<br />

● Expressions, which you can use to inspect global variables, such as $.request and other SAP HANA XS<br />

JavaScript API objects<br />

Related Links<br />

Debug Perspective [page 30]<br />

The Debug perspective in the SAP HANA studio is the standard Eclipse Debug perspective, <strong>en</strong>abling you to<br />

start debug sessions, create breakpoints and watch variables.<br />

Op<strong>en</strong>ing a Port for JavaScript Debugging [page 223]<br />

9.7.1 Op<strong>en</strong>ing a Port for JavaScript Debugging<br />

To <strong>en</strong>able debugging of JavaScript code, you must op<strong>en</strong> a debug port on SAP HANA.<br />

The debug port is unsecured, as anyone can attach a debug cli<strong>en</strong>t without needing cred<strong>en</strong>tials. A connected cli<strong>en</strong>t<br />

can attach to and debug any HTTP session, and can possibly run their own code.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 223


Therefore, it is recomm<strong>en</strong>ded that you <strong>en</strong>able this feature only in non-production or <strong>dev</strong>elopm<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>ts<br />

that are accessible by a limited number of <strong>dev</strong>elopers and that do not contain s<strong>en</strong>sitive and confid<strong>en</strong>tial data. In<br />

production systems that contain s<strong>en</strong>sitive or confid<strong>en</strong>tial data, it is recomm<strong>en</strong>ded that you keep debugging<br />

disabled or <strong>en</strong>able it only temporarily.<br />

To increase security, customers should consider applying additional network-level security measures, for<br />

example, limiting network access to the debug port.<br />

1. In SAP HANA studio, op<strong>en</strong> the Navigator view.<br />

2. Right-click on your system, and selct Administration.<br />

3. In the Configuration tab, add a section called xs<strong>en</strong>gine.ini debugger (if it does not exist) and add the<br />

following parameters:<br />

224<br />

○ <strong>en</strong>abled = true<br />

○ list<strong>en</strong>port = <br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Writing Server-Side JavaScript Applications


10 Building UIs With SAPUI5<br />

This section provides introductory information about UI <strong>dev</strong>elopm<strong>en</strong>t toolkit for HTML5.<br />

UI <strong>dev</strong>elopm<strong>en</strong>t toolkit for HTML5 (SAPUI5) is a user interface technology that is used to build and adapt cli<strong>en</strong>t<br />

applications based on SAP HANA. You can install SAPUI5 in the SAP HANA studio to build user interfaces<br />

delivered by SAP HANA's Web server.<br />

SAPUI5 runtime is a cli<strong>en</strong>t-side HTML5 r<strong>en</strong>dering library with a rich set of standard and ext<strong>en</strong>sion controls and a<br />

lightweight programming model. To support you in <strong>dev</strong>eloping applications, SAPUI5 application <strong>dev</strong>elopm<strong>en</strong>t<br />

tools comes with a set of eclipse-based wizards and editors. SAPUI5 application <strong>dev</strong>elopm<strong>en</strong>t tools provides<br />

wizards to create application projects and views according to the model-view-controller concept and other<br />

features like JavaScript code completion, templates and snippets, and in-place application preview.<br />

SAPUI5 provides many features to <strong>en</strong>able you to easily create and ext<strong>en</strong>d state-of-the-art user interfaces. SAPUI5<br />

supports the following features:<br />

● RIA-like cli<strong>en</strong>t-side features based on JavaScript.<br />

● CSS3, which allows you to adapt themes to your company's branding in an effective manner<br />

● Ext<strong>en</strong>sibility concept regarding custom controls, meaning that you can ext<strong>en</strong>d existing SAPUI5 controls as<br />

well as <strong>dev</strong>elop your own controls<br />

● Op<strong>en</strong> source jQuery library used as foundation<br />

● Full support of the SAP product standard<br />

● Compliance to Op<strong>en</strong> Ajax; can be used together with standard JavaScript libraries<br />

● Produced in a release indep<strong>en</strong>d<strong>en</strong>t code line to <strong>en</strong>able short shipm<strong>en</strong>t cycles<br />

SAPUI5 SDK<br />

The SAPUI5 SDK (Demo Kit) provides the following sections:<br />

● Developer Guide with additional information about SAPUI5, the used programming languages, op<strong>en</strong> source<br />

technologies, <strong>dev</strong>elopm<strong>en</strong>t tools, and APIs<br />

● Controls containing running demo examples with descriptions and source codes<br />

● API refer<strong>en</strong>ce with JavaScript docum<strong>en</strong>tation of Framework and Control API<br />

● Test Suite, which shows all controls running with differ<strong>en</strong>t property settings where you can interactively adapt<br />

the controls you use for test purposes<br />

The Demo Kit is installed as a delivery unit. To directly access the Demo Kit, use the following link and replace the<br />

placeholders accordingly: ://:/sap/ui5/1/sdk/index.html.<br />

The following refer<strong>en</strong>ces to the sections of the Developer Guide in the Demo Kit base on this URL.<br />

SAP HANA Developer Guide<br />

Building UIs With SAPUI5<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 225


10.1 Installing SAPUI5 Application Developm<strong>en</strong>t Tools<br />

This section provides a short description how to install SAPUI5 tools for SAP HANA.<br />

Before you start the installation of SAPUI5 application <strong>dev</strong>elopm<strong>en</strong>t tools, make sure that you comply with the<br />

following requirem<strong>en</strong>ts:<br />

● SAP HANA studio is installed.<br />

● SAPUI5 application <strong>dev</strong>elopm<strong>en</strong>t tools are downloaded from the SAP Software Download C<strong>en</strong>ter on SAP<br />

Service Marketplace (http://service.sap.com/swdc) and search for SAPUI5 TOOLS IDE PLUGIN 1.00.<br />

For more information about the installation of SAPUI5 application <strong>dev</strong>elopm<strong>en</strong>t tools, see the SAPUI 5 Installation<br />

Guide for SAP HANA on SAP Service Marketplace or SAP Note 1747308.<br />

10.2 Creating an SAPUI5 Application<br />

This section provides an example how to create an SAPUI5 application.<br />

Prerequisites: You have installed the SAPUI5 application <strong>dev</strong>elopm<strong>en</strong>t tools in your SAP HANA studio.<br />

Using the tools SAPUI5 provides, you create application projects and views according to the model-view-<br />

controller concept with a clear separation betwe<strong>en</strong> the user interface and the controller logic.<br />

The following steps describe the g<strong>en</strong>eric procedure to create an SAPUI5 application for SAP HANA XS:<br />

1. Create an SAPUI5 application project using SAPUI5 application <strong>dev</strong>elopm<strong>en</strong>t tools in Eclipse.<br />

2. Develop the cli<strong>en</strong>t-side JavaScript script code.<br />

3. If the package that contains your SAPUI5 application project has not be<strong>en</strong> exposed via HTTP already, you<br />

need to create .xsapp and .xsaccess files, see Creating the Application Descriptors. This is not necessary, if<br />

the project was created as a sub-package of an SAP HANA XS application. To make this project a valid SAP<br />

HANA application, add the .xsapp and .xsaccess files.<br />

4. Optional step (not part of the example below): Develop a server-side logic for the project by means of server-<br />

side JavaScript or OData service.<br />

5. Activate the project on SAP HANA's Web server.<br />

6. Execute the application on SAP HANA'S Web server.<br />

For SAPUI5 applications, the following view types are supported:<br />

● JavaScript: JSview (file ext<strong>en</strong>sion: js)<br />

● XML: XMLview (file ext<strong>en</strong>sion: xml)<br />

● JSON: JSONview (file ext<strong>en</strong>sion: json)<br />

The following procedure gives an example for the creation of an SAPUI5 application:<br />

1. To op<strong>en</strong> the wizard for creating an SAPUI5 application, choose File New Other SAPUI5 Application<br />

226<br />

Developm<strong>en</strong>t Application Project .<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Building UIs With SAPUI5


2. Specify the name, for example MyApplication, and location for your project. Select Desktop and Create an<br />

Initial View.<br />

You can also add a view later on by creating a separate SAPUI5 application view. If a new view has be<strong>en</strong><br />

created for an existing SAPUI5 application project, the view needs to be manually called either from the<br />

index.html page, or from another view via view nesting. For more information, see the Demo Kit -<br />

Developer Guide under Model View Controller Concept.<br />

3. Enter a name for the initial view in the Name field, for example, helloworld. Do not add a file ext<strong>en</strong>sion.<br />

This is done automatically based on the respective view type.<br />

4. Choose JavaScript and finish the wizard.<br />

The following application parts are created:<br />

○ View file; in this example, a JSview file<br />

○ Controller file<br />

○ index.html file containing the refer<strong>en</strong>ces for the sap.ui.core and sap.ui.commons libraries, the<br />

theme (sap_goldreflection), and information about the script type and the script ID. In a second script<br />

block, the index file refers to the project name, view type, and name. A cont<strong>en</strong>t default for placing the<br />

controls on the UI later on and the ARIA application role.<br />

5. Change the bootstrap tag (located in the index.html file) to <strong>en</strong>able the application to access the SAPUI5<br />

libraries on the xs<strong>en</strong>gine as follows: src="resources/sap-ui-core.js" to src="/sap/ui5/1/<br />

resources/sap-ui-core.js".<br />

6. Create a new folder i18n in the WebCont<strong>en</strong>t folder. Add a new file messagebundle.hdbtextbundle<br />

to the i18n folder with the following cont<strong>en</strong>t:<br />

# TRANSLATE<br />

# XBUT,30<br />

MY_BUTTON_TEXT=Hello {0} button<br />

Note: A specific suffix .hdbtextbundle is needed for the resource bundles on SAP HANA (so<br />

called .properties file on other platforms).<br />

7. To add a control to your view (in this example to the helloworld.view.js), insert the following coding:<br />

createCont<strong>en</strong>t : function(oController) {<br />

// require the jQuery.sap.resources module<br />

jQuery.sap.require("jquery.sap.resources");<br />

value<br />

}<br />

SAP HANA Developer Guide<br />

Building UIs With SAPUI5<br />

// load the resource bundle<br />

var oBundle = jQuery.sap.resources({<br />

// specify url of the .hdbtextbundle<br />

url : "i18n/messagebundle.hdbtextbundle"<br />

});<br />

var aControls = [];<br />

var oButton = new sap.ui.commons.Button({<br />

id : this.createId("MyButton"),<br />

// access the text using the welcome key and pass the<br />

// for the placeholder ( {0} ) via an array<br />

text : oBundle.getText("MY_BUTTON_TEXT", [ "World" ])<br />

});<br />

aControls.push(oButton.attachPress(oController.doIt));<br />

return aControls;<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 227


The coding is put into the createCont<strong>en</strong>t method, which creates the cont<strong>en</strong>t of the view. The View<br />

wizard creates the body of the method.<br />

Note: In your SAPUI5 coding, refer to the resource bundle with the URL containing the file ext<strong>en</strong>sion,<br />

for example:<br />

var oBundle = jQuery.sap.resources({<br />

url : "i18n/messagebundle.hdbtextbundle",<br />

locale: sLocale})<br />

var oResourceModel = new sap.ui.model.resource.ResourceModel({<br />

bundleURL : "i18n/messagebundle.hdbtextbundle "})<br />

8. To implem<strong>en</strong>t the doIt method for the button's press ev<strong>en</strong>t, insert the following coding into the controller (in<br />

this example: helloworld.controller.js):<br />

doIt : function(oEv<strong>en</strong>t) { alert(oEv<strong>en</strong>t.getSource().getId() +<br />

"does it!"); }<br />

9. Create a .xsapp and a .xsaccess file.<br />

10. Share, commit, and activate your project to transfer the SAPUI5 application to the SAP HANA repository.<br />

11. To start the UI application on SAP HANA's Web server, use the following URL: ://:/MyApplication/WebCont<strong>en</strong>t/<br />

index.html. Replace the placeholders accordingly; MyApplication refers to the name of your project<br />

according to Step 2.<br />

10.2.1 Local Testing of a SAPUI5 Application<br />

This section provides a description how local testing can be performed as an optional step.<br />

If you want to test the SAPUI5 application before you activate your project, you can test it within Eclipse on your<br />

local PC. This local testing is optional. If you perform a local test, note the following:<br />

● The src attribute in the bootstrap tag of the index.html file needs to have a differ<strong>en</strong>t URL than the src<br />

attribute for execution on SAP HANA's Web server. This can be achieved by manually changing the URL<br />

before submitting to SAP HANA's Web server, or by using a code snippet, that detects if the application runs<br />

locally or not, and sets the URL accordingly.<br />

● If you call a data service in form of a server-side JavaScript or an OData service that resides in the SAP HANA<br />

box, it is necessary to use a URL that points to SAP HANA's Web server. It is usually also necessary to use the<br />

so-called proxy servlet to avoid cross-domain issues. In case of the bootstrap URL, for example, the URL for<br />

local execution differs from the URL for execution on SAP HANA's Web server. For more information, see the<br />

procedure below and the refer<strong>en</strong>ced section in the Demo Kit.<br />

For more information, see the Demo Kit - Developer Guide under Testing a SAPUI5 Application.<br />

To perform a local test, proceed as follows:<br />

1. Change the URL set as "src" in the bootstrap tag of the index.html file (see explanation above). To avoid<br />

228<br />

a manual change before submitting the application, use the following code snippet that detects the context<br />

automatically, in which the application runs, and sets the URL accordingly.<br />

<br />

<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Building UIs With SAPUI5


<br />

// use alternative bootstrap for testing locally in<br />

// Eclipse during <strong>dev</strong>elopm<strong>en</strong>t time<br />

// this is only a helper mechanism during <strong>dev</strong>elopm<strong>en</strong>t time<br />

if (!window.sap) {<br />

var oriTag = docum<strong>en</strong>t.getElem<strong>en</strong>tById("sap-ui-bootstrap");<br />

oriTag.id = "wrong";<br />

oriTag.src = "wrong.js";<br />

var script = " " +<br />

"";<br />

docum<strong>en</strong>t.write(script);<br />

}<br />

<br />

2. If you use requests to back<strong>en</strong>d services, you need to use a suitable URL that points to the back<strong>en</strong>d server and,<br />

to avoid cross-domain issues, you need to use the so-called proxy servlet. Similar to the bootstrap tag, you<br />

can change the respective code manually before submitting, or you can use a code snippet that determines<br />

the URL automatically dep<strong>en</strong>ding on the context, in which the application runs.<br />

Note: As the server-side logic of an SAPUI5 application cannot be executed locally on the <strong>dev</strong>eloper's<br />

PC, it can only run on the server. H<strong>en</strong>ce, this needs to be committed and activated before it can be<br />

tested.<br />

For more information, see the Demo Kit - Developer Guide under Testing a SAPUI5 Application Enabling<br />

Back<strong>en</strong>d Access for Local Testing .<br />

3. To test your application, choose one of the following options:<br />

○ Op<strong>en</strong> the context m<strong>en</strong>u for the index.html file located in your project's WebCont<strong>en</strong>t folder and<br />

choose Run As Web App Preview .<br />

○ To run your application on a server, for example Tomcat, op<strong>en</strong> the context m<strong>en</strong>u of your project, choose<br />

Run As Run on Server and select the respective server.<br />

10.2.2 SAPUI5 Runtime Version Comparison<br />

This section describes how to compare the SAPUI5 runtime versions installed locally and on SAP HANA' Web<br />

server.<br />

It is possible that the SAPUI5 runtime version installed locally in your Eclipse differs from the SAPUI5 runtime<br />

version on SAP HANA's Web server.<br />

To verify, which version is installed locally, you can check the SAP HANA studio Eclipse version via Help About<br />

SAP HANA Studio Installation Details Features under "SAPUI5 Feature"<br />

(com.sap.ui5.uilib.feature).<br />

To find out the SAPUI5 runtime version on SAP HANA's Web server, op<strong>en</strong> the SAP HANA modeler perspective in<br />

the SAP HANA studio Eclipse via Window Op<strong>en</strong> Perspective Modeler . Choose Setup Delivery Units ...<br />

. The version, support package, and patch version of the SAPUI5 runtime libs are displayed there. You can also<br />

op<strong>en</strong> the SAPUI5 runtime index page under ://:/sap/ui5/1/<br />

SAP HANA Developer Guide<br />

Building UIs With SAPUI5<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 229


index.html and press CTRL-ALT-SHIFT-P. The SAPUI5 runtime version is displayed in the field.<br />

If the local version is, for example, newer than the version on SAP HANA's Web server and you use code<br />

completion or test the application locally in Eclipse, the results may differ or you may use features that are not<br />

available on the server. We recomm<strong>en</strong>d the following:<br />

● To detect new features, check the @since tags provided in the JSDoc.<br />

● Before deploym<strong>en</strong>t, test the application locally in Eclipse with the runtime resources from the server by<br />

configuring the resource servlet to fetch the runtime resources from the server. For more information, see the<br />

Demo Kit - Developer Guide under Testing an SAPUI5 Application UI5 Library Location Used for Testing .<br />

● After deploym<strong>en</strong>t, always test the application on the server.<br />

10.3 Supporting Translation<br />

This section provides a description of what needs to be done to support the translation of resource bundles.<br />

To <strong>en</strong>able the translation of the user interface, define a specific suffix for the resource bundles and use a specific<br />

first line in the resource bundle file. This is described in step 6 in the Creating an SAPUI5 Application topic.<br />

For more information, see the Demo Kit - Developer Guide under Localization.<br />

Related Links<br />

Creating an SAPUI5 Application [page 226]<br />

This section provides an example how to create an SAPUI5 application.<br />

230<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Building UIs With SAPUI5


11 Enabling Search<br />

With a SAP HANA database, your users will want to search tables and views much like they would wh<strong>en</strong> searching<br />

for information on the Internet. In SAP HANA, you can either directly query data using SQL queries or you can<br />

build search apps using a UI toolkit.<br />

Before <strong>en</strong>abling search, you must meet the following prerequisites:<br />

● Your SAP HANA database contains column-ori<strong>en</strong>ted tables.<br />

● A valid data type is assigned to each column. The data types of the columns determine how you can query<br />

your data.<br />

In SAP HANA, you can search on single or multiple columns of almost any visible data type. In addition to standard<br />

string search, SAP HANA also supports full text search.<br />

During a full text search, the SAP HANA search <strong>en</strong>gine examines structured text, such as author and date<br />

attributes, as well as unstructured text, such as body text. Unlike a string search, for a text search, the sequ<strong>en</strong>ce<br />

of words and characters is not critical for finding matches. A full text index <strong>en</strong>ables this functionality by analyzing<br />

and preprocessing the available text semantically. This includes normalization, tok<strong>en</strong>ization, word stemming, and<br />

parts of speech tagging.<br />

To <strong>en</strong>able search, proceed as follows:<br />

1. Create any required full text indexes for the columns in the table.<br />

○ For columns defined with the data type TEXT or SHORTTEXT(n), full text indexes are automatically<br />

g<strong>en</strong>erated. For columns of any other data type, you must manually create any required full text indexes.<br />

○ Wh<strong>en</strong> you create a full text index, you can also define synchronization and trigger text analysis.<br />

2. Build SQL search queries.<br />

○ Search queries use the SQL SELECT statem<strong>en</strong>t.<br />

○ For searches on large object types or text, the queries must include the CONTAINS predicate.<br />

3. Optionally, build search apps using the UI toolkit for SAP HANA Info Access .<br />

○ The UI toolkit provides UI building blocks for <strong>dev</strong>eloping browser-based search apps for <strong>en</strong>d users.<br />

○ The UI toolkit is based on HTML5 and JavaScript libraries.<br />

○ The UI toolkit connects to the database using the SAP HANA Info Access service that wraps search and<br />

analytic SQL queries and exposes them through an HTTP interface.<br />

11.1 Creating Full Text Indexes<br />

Wh<strong>en</strong> you create a TEXT or SHORTTEXT column in a table, SAP HANA automatically creates a corresponding full<br />

text index. However, for columns of other data types, you must manually create and define any necessary full text<br />

indexes.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 231


A full text index is an additional data structure that is created to <strong>en</strong>able text search features on a specific column<br />

in a table. Conceptually, full text indexes support searching on columns in the same way that indexes support<br />

searching through books.<br />

To create a full text index, proceed as follows:<br />

1. Determine the columns for which you require an index.<br />

2. Use the CREATE FULLTEXT INDEX statem<strong>en</strong>t to create an index with the specified index name.<br />

CREATE FULLTEXT INDEX ON '(' ')'<br />

[]<br />

3. Specify any of the following additional parameters for the full text index:<br />

LANGUAGE COLUMN <br />

LANGUAGE DETECTION '(' ')'<br />

MIME TYPE COLUMN <br />

FUZZY SEARCH INDEX <br />

PHRASE INDEX RATIO <br />

CONFIGURATION <br />

SEARCH ONLY <br />

FAST PREPROCESS <br />

FUZZY SEARCH INDEX <br />

TEXT_ANALYSIS <br />

SYNC<br />

|ASYNC<br />

|ASYNC FLUSH [QUEUE] EVERY n MINUTES<br />

|ASYNC FLUSH [QUEUE] AFTER n DOCUMENTS<br />

|ASYNC FLUSH [QUEUE] EVERY n MINUTES OR AFTER m DOCUMENTS<br />

If you do not specify any parameters, the default values are used.<br />

The system creates a separate hidd<strong>en</strong> full text index column for each source column that you have specified.<br />

You can now create queries to search those columns.<br />

You can check the parameters of an existing full text index by using the SYS.FULLTEXT_INDEXES monitoring<br />

view.<br />

Related Links<br />

You want to create a full text index i1 for table A, column C, with the following characteristics:<br />

● Synchronous processing<br />

● Fuzzy search index disabled<br />

● Languages for language detection: English, German, and South Korean<br />

To create the index, you use the following syntax:<br />

CREATE FULLTEXT INDEX i1 ON A(C) FUZZY SEARCH INDEX OFF<br />

SYNC<br />

LANGUAGE DETECTION<br />

('EN','DE','KR')<br />

Full Text Index Types [page 233]<br />

SAP HANA automatically creates full text indexes for columns of type TEXT and SHORTTEXT(n). For other<br />

column types, you must manually create any required full text indexes.<br />

232<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Synchronization [page 236]<br />

Full text indexes in a SAP HANA database must be created and updated in synchronization with the<br />

corresponding columns. This synchronization can be either synchronous or asynchronous.<br />

Full Text Index Parameters [page 243]<br />

The cont<strong>en</strong>t and behavior of a full text index is configured by the use of both default and user-specified<br />

parameters. To view the configuration of a full text index, you use the SYS.FULLTEXT_INDEXES view.<br />

11.1.1 Full Text Index Types<br />

SAP HANA automatically creates full text indexes for columns of type TEXT and SHORTTEXT(n). For other<br />

column types, you must manually create any required full text indexes.<br />

Characteristic TEXT SHORTTEXT (n) Manually Created<br />

SQL data type exposed to<br />

user<br />

Data returned by SELECT Original data (returns<br />

normalized data if the<br />

SEARCH_ONLY parameter<br />

is ON)<br />

NCLOB NVARCHAR(n) Original data type<br />

Original data Original data<br />

SQL insertion mode SYNC SYNC SYNC or ASYNC<br />

Drop index Yes (via drop column) Yes (via drop column) Yes<br />

Text search via CONTAINS Yes Yes Yes<br />

SQL string search Not possible Possible Dep<strong>en</strong>ds on underlying<br />

data type<br />

Change parameters of full<br />

text index<br />

Partially Partially All (with rebuild)<br />

Rebuild index No No Yes<br />

Base type can be changed No No No (no dep<strong>en</strong>d<strong>en</strong>cy<br />

betwe<strong>en</strong> base-column and<br />

index available)<br />

TEXT Indexes<br />

In a SAP HANA database, wh<strong>en</strong> you create a table that contains large text docum<strong>en</strong>ts, you can define the columns<br />

with the TEXT data type. This data type allows you to query large text docum<strong>en</strong>ts and pres<strong>en</strong>t cont<strong>en</strong>t excerpts in<br />

search hit lists. You can also reconstruct the docum<strong>en</strong>t and display it in its original formatting.<br />

Wh<strong>en</strong> you create a TEXT column and insert cont<strong>en</strong>t, SAP HANA extracts and processes the text from the original<br />

docum<strong>en</strong>t and th<strong>en</strong> automatically g<strong>en</strong>erates a full text index for the column. To create this full text index, SAP<br />

HANA replaces the original data in the column with the processed text. This text is th<strong>en</strong> returned with the data<br />

type NCLOB. The original data is no longer available.<br />

If you insert new <strong>en</strong>tries in the TEXT column, the full text index is automatically and synchronously updated.<br />

CREATE COLUMN TABLE <br />

(<br />

k int primary key,<br />

cont<strong>en</strong>t TEXT<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

FAST PREPROCESS OFF<br />

PHRASE INDEX RATIO<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 233


0.77<br />

)<br />

Limitations<br />

The TEXT data type has the following search-relevant limitations:<br />

● SQL string searches are not supported.<br />

● The SQL functions CONCAT and JOIN are not supported.<br />

● TEXT columns cannot be converted to other data types.<br />

● Text analysis is not supported.<br />

For TEXT columns, SAP HANA does not support the following SQL expressions:<br />

● HAVING<br />

● WHERE with strings or non-alphanumeric characters<br />

● ORDER BY<br />

● GROUP BY<br />

● Aggregate expressions (COUNT, MIN, MAX, etc.)<br />

● JOIN ON<br />

Changes to TEXT Indexes<br />

TEXT full text indexes are automatically g<strong>en</strong>erated and you do not specify names for them; therefore, you cannot<br />

directly manipulate them. However, wh<strong>en</strong> you create, alter, or drop a table column, the same change is<br />

automatically applied to the full text index for that column.<br />

By using the ALTER TABLE statem<strong>en</strong>t to affect changes on the index, you can alter the following parameters:<br />

● PHRASE INDEX RATIO<br />

● FUZZY SEARCH INDEX<br />

SHORTTEXT(n) Indexes<br />

If the tables in your SAP HANA database contain columns with text strings that are relatively short in l<strong>en</strong>gth, you<br />

can define those columns with the SHORTTEXT(n) data type. The SHORTTEXT(n) data type <strong>en</strong>ables both SQL<br />

string search and full text search capabilities.<br />

SAP HANA preprocesses the text in the column and stores that preprocessed text as a full text index in a hidd<strong>en</strong><br />

column attached to the original column. Wh<strong>en</strong> queried, the text in the full text index returns with the NVARCHAR<br />

data type. The original text is still available; however, search queries are performed, by default, on the text in the<br />

index.<br />

Wh<strong>en</strong> you create a column table and define a column with the data type SHORTTEXT(n), as in the following<br />

example, a full text index is automatically g<strong>en</strong>erated. Wh<strong>en</strong>ever new <strong>en</strong>tries are th<strong>en</strong> inserted in the column, the<br />

full text index is automatically and synchronously updated.<br />

234<br />

CREATE COLUMN TABLE <br />

(<br />

k int primary key,<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


)<br />

cont<strong>en</strong>t SHORTTEXT(100)<br />

Changes to SHORTTEXT(n) Indexes<br />

FAST PREPROCESS OFF<br />

SEARCH ONLY ON<br />

SHORTTEXT(n) full text indexes are automatically g<strong>en</strong>erated and you do not specify names for them; therefore,<br />

you cannot directly manipulate them. However, wh<strong>en</strong> you create, alter, or drop a table column, the same change<br />

is automatically applied to the index for that column.<br />

Wh<strong>en</strong> using the ALTER TABLE statem<strong>en</strong>t to affect changes on the index, you can only alter the following<br />

parameters:<br />

● PHRASE INDEX RATIO<br />

● FUZZY SEARCH INDEX<br />

Note: You cannot change the l<strong>en</strong>gth of the original text and you cannot convert SHORTTEXT(n) to another<br />

data type.<br />

Manually Created Indexes<br />

If the tables in your SAP HANA database contain ext<strong>en</strong>sive columns that are frequ<strong>en</strong>tly queried but do not have<br />

automatically g<strong>en</strong>erated full text indexes, meaning they are not TEXT or SHORTTEXT(n) type columns, you can<br />

improve search performance by manually creating full text indexes.<br />

To manually create a full text index, the column must have one of the following SQL data types:<br />

● VARCHAR<br />

● NVARCHAR<br />

● ALPHANUM<br />

● CLOB<br />

● NCLOB<br />

● BLOB<br />

Wh<strong>en</strong> you manually create an index, the system attaches a hidd<strong>en</strong> column to the specified column. This hidd<strong>en</strong><br />

column contains textual data that SAP HANA Preprocessor has extracted from the text in the source column. The<br />

original text in the source column remains unchanged. Search queries are th<strong>en</strong> performed on the hidd<strong>en</strong> column;<br />

however, they always return the original text. Dep<strong>en</strong>ding on the data type that is assigned to a source column,<br />

string search may be possible.<br />

You can manually create an index directly after creating a table or you can create the index later. Once you create<br />

an index for a column, the system automatically processes any text that is inserted into this column and adds the<br />

processed text to the index. Processing for manually created indexes can be performed synchronously or<br />

asynchronously.<br />

You can specify differ<strong>en</strong>t parameters wh<strong>en</strong> you create a full text index. If parameter changes are required later,<br />

you can change the values for the existing index directly or re-create the index with the parameters that you want<br />

to change.<br />

Related Links<br />

Creating Full Text Indexes [page 231]<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 235


Wh<strong>en</strong> you create a TEXT or SHORTTEXT column in a table, SAP HANA automatically creates a corresponding<br />

full text index. However, for columns of other data types, you must manually create and define any necessary<br />

full text indexes.<br />

Altering Full Text Index Parameters [page 242]<br />

You can alter a full text index after it is created. Altering an index includes changing the values of the<br />

parameters and altering the parameters by replacing the index.<br />

Synchronization [page 236]<br />

Full text indexes in a SAP HANA database must be created and updated in synchronization with the<br />

corresponding columns. This synchronization can be either synchronous or asynchronous.<br />

Full Text Index Parameters [page 243]<br />

The cont<strong>en</strong>t and behavior of a full text index is configured by the use of both default and user-specified<br />

parameters. To view the configuration of a full text index, you use the SYS.FULLTEXT_INDEXES view.<br />

11.1.2 Synchronization<br />

Full text indexes in a SAP HANA database must be created and updated in synchronization with the<br />

corresponding columns. This synchronization can be either synchronous or asynchronous.<br />

Synchronous<br />

In SAP HANA, indexes of the type TEXT and SHORTTEXT(n) are synchronous. Text preprocessing is<br />

automatically performed wh<strong>en</strong> a column is created or new text is inserted and the full text index is th<strong>en</strong><br />

automatically updated. The system cannot transport any data to the proper database tables until text<br />

preprocessing is complete.<br />

Asynchronous<br />

If you manually create a full text index, you can specify whether the index is synchronous or asynchronous. By<br />

default, manually created indexes are asynchronous. Text preprocessing is not initially performed wh<strong>en</strong> the table<br />

or column is created or wh<strong>en</strong>ever new text is inserted. In this case, inserting the results of the text preprocessing<br />

and writing the original data do not occur at the same time. Therefore, the full text information may not be<br />

immediately available for searching.<br />

To handle asynchronous processing of text, SAP HANA uses queues.<br />

Queues<br />

The queue is a mechanism used to <strong>en</strong>able a full text index to operate asynchronously. This means that wh<strong>en</strong> you<br />

insert new <strong>en</strong>tries into the column, the text is not made available in the column until it is preprocessed.<br />

Wh<strong>en</strong> you insert new <strong>en</strong>tries, the queue s<strong>en</strong>ds the text to the preprocessor for analysis. It returns a serialized<br />

instance of a DAF (docum<strong>en</strong>t analysis format) object, which is th<strong>en</strong> processed further by the HANA column store.<br />

The result is stored in the full text index.<br />

The SAP HANA queue manager automatically creates a queue wh<strong>en</strong> you create an asynchronous full text index or<br />

wh<strong>en</strong> the index server is started and the queue manager finds the information that a specific queue is needed. The<br />

queues are always created on the server on which the table is stored.<br />

Every <strong>en</strong>try in the queue has one of the following processing states:<br />

● New<br />

236<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


● Preprocessing<br />

● Preprocessed<br />

● Indexing<br />

● Error<br />

If the original column <strong>en</strong>try is modified or deleted during text processing, the queue is notified and, if necessary,<br />

the <strong>en</strong>try is preprocessed again.<br />

Note: The cont<strong>en</strong>t of the queue is not made persist<strong>en</strong>t at any stage. If the HANA index server process fails,<br />

the queue data is lost and the queue manager automatically restarts the process for those <strong>en</strong>tries that<br />

were not already processed. Any incomplete text preprocessing is restarted from the beginning.<br />

Flush Scheduling<br />

Wh<strong>en</strong> you create an asynchronous full text index, you can specify wh<strong>en</strong> docum<strong>en</strong>ts are removed from the queue<br />

after they are preprocessed and inserted into the full text index; this is called flushing. You can schedule flushing<br />

based on either time or the number of docum<strong>en</strong>ts. To do this, wh<strong>en</strong> you create the full text index, define one of the<br />

following clauses with the ASYNC parameter:<br />

● FLUSH EVERY (n) MINUTES<br />

● FLUSH AFTER (n) DOCUMENTS<br />

● FLUSH EVERY (n) MINUTES OR AFTER (m) DOCUMENTS<br />

Note: You cannot specify negatives values for minutes or docum<strong>en</strong>ts.<br />

To determine wh<strong>en</strong> the queue of an existing full text index is flushed, see the FLUSH_EVERY_MINUTES and<br />

FLUSH_AFTER_ROWS attributes in the view FULLTEXT_INDEXES.<br />

Related Links<br />

Manipulating Queue Processing [page 237]<br />

By default, queues are active initially and run automatically based on the parameters you specify wh<strong>en</strong><br />

creating the full text index. However, if necessary, you can manually manipulate the processing of an existing<br />

queue.<br />

Manipulating Queue Processing<br />

By default, queues are active initially and run automatically based on the parameters you specify wh<strong>en</strong> creating<br />

the full text index. However, if necessary, you can manually manipulate the processing of an existing queue.<br />

To manipulate the processing of a queue, the following commands are available:<br />

● FLUSH<br />

Updates the full text index with the docum<strong>en</strong>ts in the queue which have already be<strong>en</strong> processed and removes<br />

them from the queue.<br />

● SUSPEND<br />

Susp<strong>en</strong>ds the full text index processing queue<br />

● ACTIVATE<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 237


Activates the full text index processing queue if it has be<strong>en</strong> susp<strong>en</strong>ded<br />

To manipulate the processing of a queue:<br />

1. Id<strong>en</strong>tify which queue process you want to manipulate by using the monitoring view M_FULLTEXT_QUEUES.<br />

For information about the specific cont<strong>en</strong>t of the view, see SAP HANA System Tables and Monitoring Views.<br />

2. Use the ALTER FULLTEXT INDEX statem<strong>en</strong>t to flush, susp<strong>en</strong>d, or reactivate the queue.<br />

Use the following syntax:<br />

ALTER FULLTEXT INDEX FLUSH|SUSPEND|ACTIVATE QUEUE<br />

Related Links<br />

SAP HANA System Tables and Monitoring Views: M_FULLTEXT_QUEUES<br />

11.1.3 Text Analysis<br />

The text analysis provides a vast number of possible <strong>en</strong>tity types and analysis rules for many industries in 20<br />

languages. However, you do not have to deal with this complexity wh<strong>en</strong> analyzing your individual set of<br />

docum<strong>en</strong>ts. The language modules included with the software contain system dictionaries and provide an<br />

ext<strong>en</strong>sive set of predefined <strong>en</strong>tity types. The extraction process can extract <strong>en</strong>tities using these lists of specific<br />

<strong>en</strong>tities. It can also discover new <strong>en</strong>tities using linguistic models. Extraction classifies each extracted <strong>en</strong>tity by<br />

<strong>en</strong>tity type and pres<strong>en</strong>ts this metadata in a standardized format.<br />

The following data types are <strong>en</strong>abled for text analysis: NVARCHAR, VARCHAR, and STRING.<br />

The following text analysis options are delivered by SAP:<br />

Table 10: Options<br />

Name of Option Description<br />

LINGANALYSIS_BASIC This option provides the following language processing<br />

capabilities for linguistic analysis of unstructured data:<br />

● Segm<strong>en</strong>tation - the separation of input text into its elem<strong>en</strong>ts<br />

LINGANALYSIS_STEMS This option provides the following language processing<br />

capabilities for linguistic analysis of unstructured data:<br />

● Segm<strong>en</strong>tation - the separation of input text into its elem<strong>en</strong>ts<br />

● Stemming - the id<strong>en</strong>tification of word stems, or dictionary<br />

forms<br />

LINGANALYSIS_FULL This option provides the following language processing<br />

capabilities for linguistic analysis of unstructured data:<br />

● Segm<strong>en</strong>tation - the separation of input text into its elem<strong>en</strong>ts<br />

● Stemming - the id<strong>en</strong>tification of word stems, or dictionary<br />

forms<br />

● Tagging - the labeling of words' parts of speech<br />

EXTRACTION_CORE This option extracts <strong>en</strong>tities of interest from unstructured text,<br />

e.g. people, organizations, places, and other parties described in<br />

the docum<strong>en</strong>t.<br />

238<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Name of Option Description<br />

In most use cases, this option is suffici<strong>en</strong>t.<br />

EXTRACTION_CORE_VOICEOFCUSTOMER Voice of the customer cont<strong>en</strong>t includes a set of <strong>en</strong>tity types and<br />

rules that address requirem<strong>en</strong>ts for extracting customer<br />

s<strong>en</strong>tim<strong>en</strong>ts and requests. You can use this cont<strong>en</strong>t to retrieve<br />

specific information about your customers' needs and<br />

perceptions wh<strong>en</strong> processing and analyzing text. The option<br />

involves complex linguistic analysis and pattern matching that<br />

includes processing parts of speech, syntactic patterns, negation,<br />

and so on, to id<strong>en</strong>tify the patterns to be extracted.<br />

Voice of the customer cont<strong>en</strong>t is supported for these languages:<br />

● English<br />

● Fr<strong>en</strong>ch<br />

● German<br />

● Spanish<br />

To use the text analyzing function, create a full text index on the column which contains your texts with the<br />

following parameters:<br />

TEXT_ANALYSIS ON<br />

CONFIGURATION ''<br />

Note:<br />

Technical names of the options are case-s<strong>en</strong>sitive.<br />

If your tables contain a language indicator, you should <strong>en</strong>ter the name of the column:<br />

LANGUAGE_COLUMN <br />

If no language is specified, EN will be used by default.<br />

Once the indexing is started, the text analysis runs in the background. Dep<strong>en</strong>ding on the number and size of the<br />

texts, one analysis can take hours. To check the status of the text analysis, you can use the default monitoring<br />

view FULLTEXT_INDEXES.<br />

For each full text index, the system creates an additional table with the naming $TA_ within the<br />

same schema which contains the source table.<br />

This table stores the extracted <strong>en</strong>tities and the analysis results. You can use this table to build joins with other<br />

search <strong>en</strong>abled views, for example to use it for interactive navigation or auto-completion in search input fields.<br />

You can find detailed information on this table under Structure of the $TA Table.<br />

To keep track of deletions in the source table, the keys in the $TA table need to be aligned to the keys of the<br />

source table. To do this, use the following SQL statem<strong>en</strong>t:<br />

ALTER TABLE ""."$TA_INDEX_NAME" ADD CONSTRAINT COMMAND<br />

FOREIGN KEY("key_1", "key_2", "key_n") REFERENCES "".""("key_1","key_2","key_n") ON DELETE CASCADE<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 239


Related Links<br />

For triggering the text analysis using the option EXTRACTION_CORE, specify the following additional<br />

parameters for the full text index:<br />

TEXT_ANALYSIS ON<br />

CONFIGURATION 'EXTRACTION_CORE'<br />

LANGUAGE_COLUMN LANG<br />

ALTER TABLE "MY_SCHEMA"."$TA_CUSTOMER_INDEX" ADD CONSTRAINT ALTER_COMMAND<br />

FOREIGN KEY("KEY_1", "KEY_2") REFERENCES<br />

"MY_SCHEMA"."CUSTOMERS"("KEY_1","KEY_2") ON DELETE CASCADE<br />

Text Data Processing Language Refer<strong>en</strong>ce Guide<br />

This guide describes in detail the standard extraction cont<strong>en</strong>t and the linguistic analysis<br />

Structure of the $TA Table<br />

The table $TA_ is g<strong>en</strong>erated automatically after triggering the index creation. The table is built<br />

from the key fields of the source table, additional key fields TA_RULE and TA_COUNTER, and 8 additional fields.<br />

● Key fields of the source table<br />

● Name of the analyzed column<br />

● Entity type, for example DATE or NOUN_GROUP<br />

● Entity value, for example October 29, 2010 or horizontal stabilizer<br />

● Normalized <strong>en</strong>tity value, if available, for example 2010-10-29<br />

Table 11: Structure of TA table<br />

Column ID Key Description Data Type<br />

<br />

Yes In order to support a foreign key definition<br />

linking from the $TA table to its source table,<br />

the $TA table has to use exactly the same key<br />

columns of its source table (in data type and<br />

ID).<br />

The $TA table includes all keys from the<br />

source table.<br />

TA_RULE Yes Stores the rule package that yielded the<br />

tok<strong>en</strong>. This is also required to distinguish<br />

betwe<strong>en</strong> LXP output and output from the<br />

<strong>en</strong>tity extraction.<br />

TA_COUNTER Yes The tok<strong>en</strong> counter counts all tok<strong>en</strong>s across<br />

240<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

the docum<strong>en</strong>t. The order is only unique for a<br />

same as in source table<br />

NVARCHAR(200)<br />

BIGINT<br />

SAP HANA Developer Guide<br />

Enabling Search


Column ID Key Description Data Type<br />

giv<strong>en</strong> processing type (h<strong>en</strong>ce the previous<br />

attribute as key).<br />

TA_TOKEN - Term or <strong>en</strong>tity - dep<strong>en</strong>ding on processing<br />

type.<br />

TA_LANGUAGE - Usually, the docum<strong>en</strong>t's language is stated in<br />

the source table. In rare cases where this is<br />

not true, the language code is stored here. As<br />

there is no support for multi-language<br />

docum<strong>en</strong>ts, the language code is id<strong>en</strong>tical for<br />

all result records of a docum<strong>en</strong>t.<br />

TA_TYPE - The tok<strong>en</strong> type contains the linguistic or<br />

semantic type of the tok<strong>en</strong>; for instance<br />

"noun" (if option = LINGANALYSIS_*) or<br />

"company" (if option = EXTRACTION_*).<br />

TA_NORMALIZED - Stores a normalized repres<strong>en</strong>tation of the<br />

tok<strong>en</strong>. This becomes relevant e.g. for German<br />

with umlauts, or ß/ss. Normalization with<br />

regards to capitalization would not be as<br />

important as to justify this column.<br />

TA_STEM - Stores the linguistic stemming information,<br />

e.g. the singular nominative for nouns, or the<br />

indicative for verbs. If text analysis yields<br />

several stems, only the first stem will be<br />

stored, assuming this to be the best match.<br />

TA_PARAGRAPH - Stores the number of all paragraphs in the<br />

docum<strong>en</strong>t.<br />

TA_SENTENCE - Stores the number of all s<strong>en</strong>t<strong>en</strong>ces in a<br />

docum<strong>en</strong>t.<br />

TA_CREATED_AT - Stores the creation time. Used for mere<br />

administrative information; e.g. for<br />

reorganizing purposes.<br />

The $TA table can be modified like any other table, but it cannot be partitioned.<br />

You can add additional columns to this table, e.g. with a statem<strong>en</strong>t like ALTER TABLE<br />

NVARCHAR(250)<br />

NVARCHAR(2)<br />

NVARCHAR(100)<br />

NVARCHAR(250)<br />

NVARCHAR(300)<br />

INTEGER<br />

INTEGER<br />

TIMESTAMP<br />

"TA"."$TA_SOURCE_TEXT_TA" ADD(C INTEGER GENERATED ALWAYS AS 1). In this example, the value 1 will be<br />

writt<strong>en</strong> to only existing rows in the new column C. The new column will not be filled automatically in delta updates.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 241


Note:<br />

If the source table has a field name id<strong>en</strong>tical to one of the default fields from the $TA table, you will receive<br />

an error message after the CREATE FULTTEXT INDEX statem<strong>en</strong>t informing you to r<strong>en</strong>ame the field of the<br />

source table. After you r<strong>en</strong>ame the corresponding field, you can execute the CREATE FULLTEXT INDEX<br />

statem<strong>en</strong>t again.<br />

11.1.4 Dropping Full Text Indexes<br />

If you want to delete a full text index that you manually created, for example, because it is refer<strong>en</strong>ced only rarely<br />

or preprocessing is too time-consuming, you can drop the full text index. For TEXT or SHORTTEXT full text<br />

indexes, you cannot drop the full text index; instead, you must delete the related column in the table.<br />

You also need to drop full text indexes wh<strong>en</strong> adding or removing index parameters. As parameters cannot be<br />

added to or removed from an existing full text index, if you want to change parameters, you must first drop the full<br />

text index and th<strong>en</strong> create a new index with the new parameters.<br />

To drop a full text index, you use the DROP FULLTEXT INDEX statem<strong>en</strong>t:<br />

DROP FULLTEXT INDEX <br />

Related Links<br />

Note: Before you can drop a full text index, you must remove the relationship betwe<strong>en</strong> the source table<br />

and any existing $TA tables (for text analysis). To do so, use the following statem<strong>en</strong>t:<br />

ALTER TABLE SCHEMA DROP <br />

The name constraint must be the same as originally used wh<strong>en</strong> adding the constraint. For more<br />

information, see Text Analysis.<br />

Altering Full Text Index Parameters [page 242]<br />

You can alter a full text index after it is created. Altering an index includes changing the values of the<br />

parameters and altering the parameters by replacing the index.<br />

Text Analysis [page 238]<br />

11.1.5 Altering Full Text Index Parameters<br />

You can alter a full text index after it is created. Altering an index includes changing the values of the parameters<br />

and altering the parameters by replacing the index.<br />

● To alter the parameters of a full text index, use the ALTER FULLTEXT INDEX statem<strong>en</strong>t.<br />

You can only use this statem<strong>en</strong>t to alter the following parameters:<br />

○ Fuzzy search index<br />

○ Phrase index ratio<br />

Example syntax:<br />

ALTER FULLTEXT INDEX <br />

PHRASE INDEX RATIO <br />

FUZZY SEARCH INDEX <br />

● To alter any other parameter, you must replace the existing full text index as follows:<br />

242<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


a) Delete the existing full text index by using the DROP FULLTEXT INDEX statem<strong>en</strong>t.<br />

b) Create a new index using the new parameter values.<br />

Related Links<br />

Creating Full Text Indexes [page 231]<br />

Wh<strong>en</strong> you create a TEXT or SHORTTEXT column in a table, SAP HANA automatically creates a corresponding<br />

full text index. However, for columns of other data types, you must manually create and define any necessary<br />

full text indexes.<br />

Synchronization [page 236]<br />

Full text indexes in a SAP HANA database must be created and updated in synchronization with the<br />

corresponding columns. This synchronization can be either synchronous or asynchronous.<br />

Queues [page 236]<br />

The queue is a mechanism used to <strong>en</strong>able a full text index to operate asynchronously. This means that wh<strong>en</strong><br />

you insert new <strong>en</strong>tries into the column, the text is not made available in the column until it is preprocessed.<br />

Full Text Index Parameters [page 243]<br />

The cont<strong>en</strong>t and behavior of a full text index is configured by the use of both default and user-specified<br />

parameters. To view the configuration of a full text index, you use the SYS.FULLTEXT_INDEXES view.<br />

11.1.6 Full Text Index Parameters<br />

The cont<strong>en</strong>t and behavior of a full text index is configured by the use of both default and user-specified<br />

parameters. To view the configuration of a full text index, you use the SYS.FULLTEXT_INDEXES view.<br />

In SAP HANA, full text indexes are configured using the following parameters:<br />

Parameter Data<br />

Type<br />

SCHEMA_NAM<br />

E<br />

NVARCH<br />

AR(256)<br />

TABLE_NAME NVARCH<br />

AR(256)<br />

TABLE_OID BIGINT<br />

INDEX_NAME NVARCH<br />

AR(256)<br />

INDEX_OID BIGINT<br />

LANGUAGE_C<br />

OLUMN<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

NVARCH<br />

AR(256)<br />

Default<br />

(TEXT)<br />

Default<br />

(SHORTTEXT)<br />

None None None<br />

Default (Manually<br />

Created)<br />

Description<br />

Specifies the schema name<br />

Specifies the table name<br />

Specifies the object ID of the<br />

table<br />

Specifies the name of the full<br />

text index<br />

Specifies the object ID of the<br />

full text index<br />

Specifies the language used for<br />

analyzing the docum<strong>en</strong>t. If no<br />

language is specified,<br />

automatic language detection is<br />

performed. The detected<br />

language is stored with the<br />

TEXT_AE attribute.<br />

With this option, you can refer<br />

to a column of the same<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 243


Parameter Data<br />

Type<br />

MIME_TYPE_<br />

COLUMN<br />

LANGUAGE_D<br />

ETECTION<br />

FAST_PREPR<br />

OCESS<br />

244<br />

NVARCH<br />

AR(256)<br />

NVARCH<br />

AR(5000<br />

)<br />

Default<br />

(TEXT)<br />

Default<br />

(SHORTTEXT)<br />

None None None<br />

EN EN EN<br />

TINYINT ON ON ON<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

Default (Manually<br />

Created)<br />

Description<br />

database table in which the<br />

language for the docum<strong>en</strong>t is<br />

stored. The column is read by<br />

the queue.<br />

languageColumn in basetable<br />

should be of type NVARCHAR/<br />

VARCHAR(m) where m>=2<br />

wh<strong>en</strong> not NULL:<br />

table(tableoid).hasColumn(lang<br />

uageColumn)<br />

This column holds a format/<br />

mimetype indicator (for plain<br />

text, the <strong>en</strong>coding can also be<br />

specified), e.g. ('text/<br />

plain:CP-1252','PDF','MS_WOR<br />

D 3.0',..).<br />

'FORMAT' is handled in the<br />

same way as 'LANGUAGE'.<br />

wh<strong>en</strong> not NULL:<br />

table(tableoid).hasColumn(mi<br />

meTypeColumn)<br />

Specifies the set of languages<br />

to be considered for automatic<br />

language detection. If reliable<br />

language detection cannot be<br />

performed, the first language in<br />

the list will be used as the<br />

default language.<br />

This option is used to limit the<br />

languages for text analysis. The<br />

parameter is curr<strong>en</strong>tly ignored<br />

by text analysis. wh<strong>en</strong> not<br />

NULL: for each language L in<br />

languageDetection: L in (select<br />

language from<br />

SYS.M_TEXT_ANALYSIS_LANG<br />

UAGES)<br />

Specifies if fast preprocessing<br />

should be performed. With fast<br />

preprocessing the detected<br />

language is always the default<br />

language.<br />

SAP HANA Developer Guide<br />

Enabling Search


Parameter Data<br />

Type<br />

FUZZY_SEAR<br />

CH_INDEX<br />

SEARCH_ONL<br />

Y<br />

IS_EXPLICI<br />

T<br />

FLUSH_AFTE<br />

R_DOCUMENT<br />

S<br />

FLUSH_EVER<br />

Y_MINUTES<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

Default<br />

(TEXT)<br />

Default<br />

(SHORTTEXT)<br />

TINYINT OFF OFF OFF<br />

Default (Manually<br />

Created)<br />

TINYINT OFF ON for LOB-types<br />

OFF, otherwise ON<br />

TINYINT 0 0 1<br />

INTEGER N/A N/A<br />

INTEGER N/A N/A<br />

Description<br />

If this option is activated,<br />

linguisitic analysis is skipped.<br />

Only a simple tok<strong>en</strong>izer is used.<br />

This does not work for<br />

languages which do not use<br />

spaces as word separators. The<br />

fast analyzer cannot handle<br />

binary docum<strong>en</strong>ts.<br />

If this option is <strong>en</strong>abled, a<br />

special index is created for the<br />

fuzzy search. This index<br />

accelerates the fuzzy search<br />

but uses additional memory.<br />

If set to ON, you cannot<br />

reconstruct original cont<strong>en</strong>t or<br />

show the docum<strong>en</strong>t in its<br />

original formatting wh<strong>en</strong> using<br />

the highlight function. With this<br />

setting, the text attributes do<br />

not store any DAFs, that<br />

means, it is not possible to<br />

retrieve the HTML-converted or<br />

original data from the text<br />

attribute. The docum<strong>en</strong>t will,<br />

however, use less memory.<br />

If the text attribute is created<br />

via a manually created full text<br />

index, the source attribute that<br />

contains the original data is not<br />

affected by this setting.<br />

Specifies whether the full text<br />

index was manually created<br />

(also known as explicit). By<br />

default, manually created full<br />

text indexes use ASYNC<br />

synchronization.<br />

Specifies wh<strong>en</strong> asynchronous<br />

full text indexes are flushed.<br />

The specified value cannot be<br />

negative.<br />

Specifies wh<strong>en</strong> asynchronous<br />

full text indexes are flushed.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 245


Parameter Data<br />

Type<br />

CONFIGURAT<br />

ION<br />

INTERNAL_C<br />

OLUMN_NAME<br />

PHRASE_IND<br />

EX_RATIO<br />

TEXT_ANALY<br />

SIS<br />

246<br />

NVARCH<br />

AR(5000<br />

)<br />

NVARCH<br />

AR(512)<br />

Default<br />

(TEXT)<br />

Default<br />

(SHORTTEXT)<br />

None None None<br />

FLOAT 0.0 0.0 (0.2 if<br />

l<strong>en</strong>gth


Parameter Data<br />

Type<br />

Default<br />

(TEXT)<br />

Default<br />

(SHORTTEXT)<br />

Default (Manually<br />

Created)<br />

Description<br />

parameter is automatically set<br />

to OFF.<br />

Text analysis can extract<br />

<strong>en</strong>tities such as persons,<br />

products, or places, from<br />

docum<strong>en</strong>ts and thus <strong>en</strong>rich the<br />

set of structured information in<br />

SAP HANA. You can use these<br />

additional attributes, which are<br />

stored in a new table, wh<strong>en</strong><br />

creating models (views) for<br />

analytics and search sc<strong>en</strong>arios<br />

to <strong>en</strong>able improved analytics<br />

and search in SAP HANA.<br />

For more information, see Text<br />

Analysis [page 238].<br />

Memory Consumption of Full Text Index Parameters<br />

In SAP HANA, certain full text index parameters can have a significant impact on memory consumption based on<br />

how they are defined.<br />

The following full text index parameters can have a significant impact on memory consumption:<br />

Parameter Memory Impact Details<br />

PHRASE_INDEX_RATIO If the value is greater than 0.0, th<strong>en</strong> there is additional<br />

memory overhead. The maximum memory<br />

consumption is the memory consumption of the full<br />

text index multiplied by the parameter value.<br />

FUZZY_SEARCH_INDEX To increase response times for fuzzy search, wh<strong>en</strong><br />

<strong>en</strong>abled, this parameter creates additional in-memory<br />

structures. For text-type columns, fuzzy search<br />

indexes require approx. 10% of the memory size of the<br />

column.<br />

TEXT_ANALYSIS If set to ON, an additional table is created for storing<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

structured data extracted from the source text for text<br />

analysis. The amount of extracted data dep<strong>en</strong>ds on the<br />

data in the source column, the text analysis rules, and<br />

the structure of the results. In certain cases, the<br />

memory consumption of the extracted data could<br />

exceed the memory consumption of the source data.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 247


11.2 Building SQL Search Queries<br />

In column-ori<strong>en</strong>ted tables, you can perform searches using the SQL SELECT statem<strong>en</strong>t.<br />

Before building SQL search queries, the following prerequisites must be met:<br />

● The tables you want to search are column-ori<strong>en</strong>ted.<br />

● You have created any required views for the tables you want to search.<br />

● You have created any required full text indexes for the columns you want to search.<br />

SAP HANA supports the standard SQL search syntax and functions for search queries on nearly all visible data<br />

types. You build SQL queries using the SELECT statem<strong>en</strong>t, as in the following example:<br />

SELECT * FROM Contacts WHERE ID=1<br />

However, in SAP HANA, columns of large object types and text have additional requirem<strong>en</strong>ts. To <strong>en</strong>able search on<br />

columns of these types, you must <strong>en</strong>sure the following requirem<strong>en</strong>ts are met:<br />

● Full text indexes have be<strong>en</strong> created for the search-relevant columns. For columns of type TEXT and<br />

SHORTTEXT, this is done automatically.<br />

● Search queries on the columns use the CONTAINS predicate.<br />

For large object types and text, you build SQL queries using the SELECT statem<strong>en</strong>t and CONTAINS predicate, as<br />

in the following example:<br />

SELECT * FROM Docum<strong>en</strong>ts WHERE CONTAINS (*,'Comm<strong>en</strong>t')<br />

To build a search query, proceed as follows:<br />

1. Use the SQL SELECT statem<strong>en</strong>t and specify the table or view and column you want to search. If required,<br />

include the CONTAINS predicate.<br />

2. If required, specify scalar functions for the search.<br />

3. Specify the search terms and, optionally, the search type (EXACT, LINGUISTIC, or FUZZY).<br />

Note: If you do not specify a search type, by default, the search query is performed as an exact<br />

search.<br />

For further examples of the syntax used with the SELECT statem<strong>en</strong>t, see SAP HANA SQL Refer<strong>en</strong>ce<br />

Manual.<br />

Related Links<br />

SAP HANA SQL Refer<strong>en</strong>ce Manual: SELECT<br />

11.2.1 Search Queries with CONTAINS<br />

In SAP HANA, you can search one or multiple columns by creating a query that includes the CONTAINS predicate.<br />

In SAP HANA, a search query with CONTAINS has a look and feel similar to common Internet search <strong>en</strong>gines.<br />

248<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


The CONTAINS predicate is optional for search queries on columns of most data types; however, for large object<br />

types and text, this predicate is mandatory. You can build a search query with the CONTAINS predicate as<br />

follows:<br />

SELECT * FROM <br />

WHERE CONTAINS ((, , ), )<br />

Wh<strong>en</strong> you specify the CONTAINS predicate, SAP HANA runs the following internal checks:<br />

● SAP HANA checks if the query contains one or more terms. If the query contains multiple terms, the terms<br />

are tok<strong>en</strong>ized and concat<strong>en</strong>ated.<br />

● SAP HANA checks whether the query is to be run on one or more columns. If you only specify one column, to<br />

optimize the search, additional processes are skipped and the query is run on the single column. If you specify<br />

a wildcard, and therefore possibly numerous columns, SAP HANA automatically determines which columns<br />

are relevant for the search query.<br />

After the checks are performed, SAP HANA builds and runs an internal query on the relevant columns only.<br />

Note:<br />

If a column has a full text index assigned, SAP HANA will automatically search on the index rather than on<br />

the original column.<br />

Determination of Search-Relevant Columns<br />

You can specify the search-relevant columns either at the creation of the view or directly for the query. SAP HANA<br />

determines which relevant columns to search based on the following hierarchy:<br />

1. You specify a list of columns within the CONTAINS predicate. Ev<strong>en</strong> if a list of columns has be<strong>en</strong> defined for<br />

the view, it is overridd<strong>en</strong> by the columns stated in the query.<br />

2. If you <strong>en</strong>ter an asterisk (*) instead of a column list but you specified a list of relevant columns wh<strong>en</strong> creating<br />

the view, this list is used for the query.<br />

3. If you <strong>en</strong>ter an asterisk (*) and no list was provided wh<strong>en</strong> the view was created, all visible columns of the view<br />

or table are considered as search-relevant.<br />

For information about creating views, see Creating Views in the SAP HANA Administration Guide.<br />

Search Operators and Syntax<br />

With the CONTAINS predicate, SAP HANA supports the following search operators:<br />

● OR<br />

Matches are returned that contain at least one of the terms joined by the OR operator.<br />

● - (minus)<br />

With a minus sign, SAP HANA searches in columns for matches that do not contain the term immediately<br />

following the minus sign.<br />

● " " (quotation marks)<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 249


Terms within the quotation marks are not tok<strong>en</strong>ized and are handled as a string. Therefore, all search<br />

matches must be exact.<br />

Note: If you <strong>en</strong>ter multiple search terms, the AND operator is automatically interpreted. Therefore, you do<br />

not need to specify it.<br />

For more information about the unique syntax requirem<strong>en</strong>ts of the CONTAINS predicate, see the SAP HANA SQL<br />

Refer<strong>en</strong>ce.<br />

Scalar Functions<br />

For search queries using the CONTAINS predicate, you can use differ<strong>en</strong>t scalar functions to either return<br />

additional information about the results of your search queries or <strong>en</strong>hance how the results are displayed. These<br />

functions include SNIPPET, HIGHLIGHTED, and SCORE.<br />

Limitations<br />

The following limitations apply to search queries using the CONTAINS predicate:<br />

● You cannot search on more than one table or view at a time. If more than one table is joined in the SELECT<br />

statem<strong>en</strong>t, th<strong>en</strong> all columns m<strong>en</strong>tioned in the CONTAINS predicate must come from only one of the tables.<br />

● You cannot <strong>en</strong>ter a minus (-) search operator directly after OR.<br />

● Brackets are not supported as search operators.<br />

● Searches using the CONTAINS predicate do not consider non-physical columns, such as calculated columns,<br />

as search-relevant because these columns are created during the search and, therefore, are not available<br />

wh<strong>en</strong> SAP HANA internally checks the CONTAINS search query.<br />

● The CONTAINS predicate only works on column-ori<strong>en</strong>ted tables.<br />

● If you specify multiple CONTAINS predicates in the WHERE clause of the SELECT statem<strong>en</strong>t, only one of the<br />

predicates is allowed to consist of more than one column in the list of .<br />

Related Links<br />

SAP HANA SQL Refer<strong>en</strong>ce: CONTAINS Predicate<br />

SAP HANA Administration Guide<br />

SNIPPET Function<br />

For search queries using the CONTAINS predicate, you can use the function SNIPPET to return search results<br />

with an excerpt of the text with your search term highlighted in bold. This short text excerpt provides some<br />

context for you to see where and how the term is used in the docum<strong>en</strong>t.<br />

This function uses the following syntax:<br />

SELECT *, SNIPPET () FROM <br />

WHERE CONTAINS ()<br />

250<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Limitations<br />

The SNIPPET function has the following limitations:<br />

● Only the first search term specified with the CONTAINS predicate is highlighted in the returned text.<br />

● The query result contains only the first hit of the first search term.<br />

● The text excerpt that is displayed with the search term is limited to a string of 12 tok<strong>en</strong>s.<br />

● This function only works on columns of the TEXT data type or columns with a full text index.<br />

HIGHLIGHTED Function<br />

For search queries using the CONTAINS predicate, you can use the function HIGHLIGHTED to return the<br />

cont<strong>en</strong>t of the found docum<strong>en</strong>t with your search term highlighted in bold.<br />

Search queries using the HIGHLIGHTED function return the data type NCLOB.<br />

This function uses the following syntax:<br />

SELECT *, HIGHLIGHTED () FROM <br />

WHERE CONTAINS ()<br />

Limitations<br />

The HIGHLIGHTED function has the following limitations:<br />

● Only the first search term specified with the CONTAINS predicate is highlighted in the returned text.<br />

● The query result contains all hits of the first search term.<br />

● This function only works on columns of the TEXT data type or columns with a full text index.<br />

SCORE Function<br />

For search queries using the CONTAINS predicate, you can use the function SCORE to get the score, that means<br />

the relevance, of a record found.<br />

SAP HANA calculates a score based on the following information:<br />

● The relevance or weighting of attributes in a search using the CONTAINS predicate. The relevance of a hit<br />

dep<strong>en</strong>ds on the weight of the column that caused the hit. You can specify weights wh<strong>en</strong> you create the view or<br />

in the CONTAINS predicate.<br />

● Fuzziness in fuzzy search. The more exact a hit is, the higher the score is.<br />

● Text ranking (TF-IDF).<br />

This function uses the following syntax:<br />

SELECT SCORE (),* FROM <br />

WHERE CONTAINS ()<br />

11.2.2 EXACT Search<br />

An exact search returns records only if the search term or search phrase is contained in the table column exactly<br />

as specified. In the SELECT statem<strong>en</strong>t of the search query, you can specify the EXACT search type.<br />

In an exact search, the search <strong>en</strong>gine uses the word dictionary and the phrase index to detect the possible<br />

matches. The search <strong>en</strong>gine th<strong>en</strong> checks whether the words appear and use exactly the same spelling.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 251


● For text columns, the search term must match at least one of the tok<strong>en</strong>ized terms to return a column <strong>en</strong>try as<br />

a match.<br />

● For string columns, the search term must match the <strong>en</strong>tire string to return a column <strong>en</strong>try as a match.<br />

Note: For more flexibility in a search query, you can use the supported wildcards % and *. Wildcards are<br />

supported for both text and string columns.<br />

You can perform an exact search by using the CONTAINS predicate with the EXACT option in the WHERE clause<br />

of a SELECT statem<strong>en</strong>t. The exact search is the default search type. If you do not specify any search type in the<br />

search query, an exact search will be executed automatically.<br />

SELECT * FROM <br />

WHERE CONTAINS (, , EXACT)<br />

SELECT * FROM <br />

WHERE CONTAINS (, )<br />

--- Exact search will be executed implicitly.<br />

SELECT * FROM <br />

WHERE CONTAINS (, '"cats and dogs"')<br />

--- Phrase search.<br />

11.2.3 LINGUISTIC Search<br />

A linguistic search finds all words that have the same word stem as the search term. It also finds all words for<br />

which the search term is the word stem. In the SELECT statem<strong>en</strong>t of the full text search query, you can specify<br />

the LINGUISTIC search type.<br />

Wh<strong>en</strong> you execute a linguistic search, the system has to determine the stems of the searched terms. It will look up<br />

the stems in the stem dictionary. The hits in the stem dictionary point to all words in the word dictionary that have<br />

this stem<br />

You can call the linguistic search by using the CONTAINS predicate with the LINGUISTIC option in the WHERE<br />

clause of a SELECT statem<strong>en</strong>t.<br />

A linguistic search for produced will also find producing and produce.<br />

Limitations<br />

SELECT * FROM <br />

WHERE CONTAINS (


Fuzzy search can be used in various applications, for example:<br />

● Fault-tolerant search in text columns (for example, html or pdf): Search for docum<strong>en</strong>ts on 'Driethanolamyn'<br />

and find all docum<strong>en</strong>ts that contain the term 'Triethanolamine'.<br />

● Fault-tolerant search in structured database cont<strong>en</strong>t: Search for a product called 'coffe krisp biscuit' and find<br />

'Toffee Crisp Biscuits'.<br />

● Fault-tolerant check for duplicate records: Before creating a new customer record in a CRM system, search for<br />

similar customer records and verify that there are no duplicates already stored in the system. Wh<strong>en</strong>, for<br />

example, creating a new record 'SAB Akti<strong>en</strong>gesellschaft & Co KG Deutschl.' in 'Wahldorf', the system shall<br />

bring up 'SAP Deutschland AG & Co. KG' in 'Walldorf' as a possible duplicate.<br />

You can call the fuzzy search by using the CONTAINS predicate with the FUZZY option in the WHERE clause of a<br />

SELECT statem<strong>en</strong>t.<br />

Fuzzy Score<br />

SELECT * FROM <br />

WHERE CONTAINS (, , FUZZY (0.8))<br />

Note: You can improve the performance of a fuzzy search on a text column by defining a fuzzy<br />

index at the column. You can define a fuzzy index with the option FUZZY SEARCH INDEX ON in<br />

the CREATE FULLTEXT INDEX statem<strong>en</strong>t or in the definition of data type TEXT.<br />

The fuzzy search algorithm calculates a fuzzy score for each string comparison. The higher the score, the more<br />

similar the strings are. A score of 1.0 means the strings are id<strong>en</strong>tical. A score of 0.0 means the strings have<br />

nothing in common.<br />

You can request the score in the SELECT statem<strong>en</strong>t by using the SCORE() function. You can sort the results of a<br />

query by score in desc<strong>en</strong>ding order to get the best records first (the best record is the record that is most similar<br />

to the user input). Wh<strong>en</strong> a fuzzy search of multiple columns is used in a SELECT statem<strong>en</strong>t, the score is returned<br />

as an average of the scores of all columns used.<br />

Wh<strong>en</strong> searching text columns, a TF/IDF (term frequ<strong>en</strong>cy/inverse docum<strong>en</strong>t frequ<strong>en</strong>cy) score is returned by<br />

default instead of the fuzzy score. The fuzzy score influ<strong>en</strong>ces the TF/IDF calculation, but it is important to keep in<br />

mind that, with TF/IDF, the range of the score values returned is normed to the interval betwe<strong>en</strong> 0.0 and 1.0, and<br />

the best record always gets a score of 1.0, regardless of its fuzzy score.<br />

The TF/IDF calculation can be disabled so that you get the fuzzy score instead. In particular, this makes s<strong>en</strong>se for<br />

short-text columns containing data such as product names or company names. On the other hand, you should<br />

use TF/IDF for long-text columns containing data such as product descriptions, HTML data, or Word and PDF<br />

docum<strong>en</strong>ts.<br />

Option spellCheckFactor<br />

There are two use cases for the option spellCheckFactor.<br />

● A) This option allows you to set the score for terms that are not fully equal but that would be a 100% match<br />

because of the internal character standardization used by the fuzzy search.<br />

For example, the terms 'Café' and 'cafe' give a score of 1.0 although the terms are not equal. For some users it<br />

may be necessary to distinguish betwe<strong>en</strong> both terms.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 253


The decision if two terms are equal is based on the term repres<strong>en</strong>tation stored in the column dictionary.<br />

Therefore the spellCheckFactor option works differ<strong>en</strong>tly on string and text columns, as described in the<br />

following sections.<br />

● B) The fuzzy search can return a 100% match for terms that are not id<strong>en</strong>tical but can't be differ<strong>en</strong>tiated by<br />

the fuzzy-string-compare algorithm.<br />

For example, fuzzy search can't differ<strong>en</strong>tiate betwe<strong>en</strong> terms 'abaca' and 'acaba', for example. In this case, the<br />

spellCheckFactor can be used to avoid a score of 1.0.<br />

Wh<strong>en</strong> A) and B) are not needed by an application, you can set the spellCheckFactor to 1.0 to disable the feature.<br />

Standardization of Letters and Terms<br />

All characters are replaced by a lowercase character without any diacritics before the fuzzy comparison takes<br />

place. This is called standardization. So it is possible to get a 100% match wh<strong>en</strong> comparing two unequal terms,<br />

because the standardization process returned two id<strong>en</strong>tical terms.<br />

Standardization Examples<br />

Original Letter Standardized Letter<br />

E e<br />

e e<br />

É e<br />

é e<br />

Ė e<br />

ė e<br />

The letter i is treated differ<strong>en</strong>tly as it is not standardized to an ı as would be the 'standard' rule.<br />

Original Letter Standardized Letter<br />

I i<br />

İ i<br />

i i<br />

ı i<br />

German umlauts are replaced by two characters.<br />

Original Letter Standardized Letter<br />

Ä ae<br />

254<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Original Letter Standardized Letter<br />

ä ae<br />

Ö oe<br />

ö oe<br />

Ü ue<br />

ü ue<br />

ß ss<br />

Because of this standardization we get high fuzzy scores for common differ<strong>en</strong>ces in the spelling of words.<br />

Original term Standardized term<br />

müller mueller<br />

Mueller mueller<br />

Cafe cafe<br />

Café cafe<br />

Search on a String Column (VARCHAR, NVARCHAR)<br />

The decision if two strings are the same is based on the string repres<strong>en</strong>tation that is stored in the dictionary for<br />

that column. The cont<strong>en</strong>ts of a string column are converted to lowercase characters before they are stored in the<br />

dictionary. Other standardizations are not done.<br />

So it is possible to use the spellCheckFactor option to, for example, distinguish betwe<strong>en</strong> 'café' and 'cafe'.<br />

CREATE COLUMN TABLE test_spell_check_factor<br />

(<br />

id INTEGER PRIMARY KEY,<br />

s NVARCHAR(255)<br />

);<br />

INSERT INTO test_spell_check_factor VALUES ('1','Muller');<br />

INSERT INTO test_spell_check_factor VALUES ('2','Mueller');<br />

INSERT INTO test_spell_check_factor VALUES ('3','Müller');<br />

INSERT INTO test_spell_check_factor VALUES ('4','Möller');<br />

SELECT SCORE() AS score, id, s<br />

FROM test_spell_check_factor<br />

WHERE CONTAINS(s, 'Müller', FUZZY(0.5, 'spellCheckFactor=0.9'))<br />

ORDER BY score DESC;<br />

DROP TABLE test_spell_check_factor;<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 255


SCORE ID T Description<br />

1.0 3 Müller<br />

0.9 2 Mueller


Option similarCalculationMode<br />

The option similarCalculationMode controls how the similarity of two strings (or, for TEXT attributes, terms) is<br />

calculated.<br />

Score calculation modes<br />

Basically, the similarity of two strings is defined by the number of common characters, wrong characters,<br />

additional characters in the search string and additional characters in the refer<strong>en</strong>ce string.<br />

There are the following calculation modes:<br />

Table 12: Modes<br />

Mode Impact on wrong<br />

characters<br />

Impact on additional<br />

characters in search<br />

search high high low<br />

compare (default) moderate high high<br />

symmetricsearch high moderate moderate<br />

Note that high impact results in a lower score.<br />

Table 13: Examples with score<br />

Request Refer<strong>en</strong>ce Compa<br />

re<br />

Search Symmetricsearch<br />

search searching 0.76 0.96 0.86<br />

search search 0.85 0.75 0.75<br />

search searchingforextrater<br />

searchingforextrater<br />

restriallife<br />

searchingforextrater<br />

restriallife<br />

searchingforextrater<br />

restriallife<br />

SQL Examples<br />

Preparations<br />

restriallife<br />

0.0 0.91 0.87<br />

searching 0.0 0.35 0.84<br />

search 0.0 0.24 0.79<br />

searchingforthemea<br />

ningoflife<br />

0.6 0.57 0.6<br />

OP TABLE test_similar_calculation_mode;<br />

CREATE COLUMN TABLE test_similar_calculation_mode<br />

(<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

Impact on additional<br />

characters in table<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 257


);<br />

id INTEGER PRIMARY KEY,<br />

s NVARCHAR(255)<br />

INSERT INTO test_similar_calculation_mode VALUES ('1','stringg');<br />

INSERT INTO test_similar_calculation_mode VALUES ('2','string theory');<br />

INSERT INTO test_similar_calculation_mode VALUES ('3','this is a very very<br />

very long string');<br />

INSERT INTO test_similar_calculation_mode VALUES ('4','this is another<br />

very long string');<br />

similarCalculationMode compare<br />

SELECT TO_INT(SCORE()*100)/100 AS score, id, s<br />

FROM test_similar_calculation_mode<br />

WHERE CONTAINS(s, 'explain string theory', FUZZY(0.5,<br />

'similarCalculationMode=compare'))<br />

ORDER BY score DESC;<br />

Score ID S<br />

0.69 2 string theory<br />

similarCalculationMode search<br />

SELECT TO_INT(SCORE()*100)/100 AS score, id, s<br />

FROM test_similar_calculation_mode<br />

WHERE CONTAINS(s, 'explain string theory', FUZZY(0.5,<br />

'similarCalculationMode=search'))<br />

ORDER BY score DESC;<br />

Score ID S<br />

0.68 4 this is another very long string<br />

0.66 3 this is a very very very long string<br />

0.65 2 string theory<br />

similarCalculationMode symmetricsearch<br />

SELECT TO_INT(SCORE()*100)/100 AS score, id, s<br />

FROM test_similar_calculation_mode<br />

WHERE CONTAINS(s, 'explain string theory', FUZZY(0.5,<br />

'similarCalculationMode=symmetricsearch'))<br />

ORDER BY score DESC;<br />

Score ID S<br />

0.85 2 string theory<br />

0.71 1 stringg<br />

0.61 4 this is another very long string<br />

0.58 3 this is a very very very long string<br />

258<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Supported Data Types<br />

Fuzzy search works out-of-the-box on the following column-store data types:<br />

● TEXT<br />

● SHORTTEXT<br />

● VARCHAR, NVARCHAR<br />

● DATE<br />

● All data types with a full-text index<br />

String Types<br />

String types support a basic fuzzy string search. The values of a column are compared with the user input, using<br />

the fault-tolerant fuzzy string comparison.<br />

Wh<strong>en</strong> working with string types, the fuzzy string comparison always compares the full strings. If searching with<br />

'SAP', for example, a record such as 'SAP Deutschland AG & Co. KG' gets a very low score, because only a very<br />

small part of the string is equal (3 of 27 characters match).<br />

A fuzzy search on string types is an alternative to a non-fault-tolerant SQL statem<strong>en</strong>t such as<br />

SELECT ... FROM products WHERE product_name = 'coffe krisp biscuit' ...<br />

which would not return any results because of the spelling errors.<br />

Supported SQL data types are<br />

● VARCHAR<br />

● NVARCHAR<br />

It is possible to speed up the fuzzy search by creating additional data structures, which are used for faster<br />

calculation of the fuzzy score. These data structures exist in the memory only, so no additional disk space is<br />

required.<br />

To get the best response times possible, you should <strong>en</strong>able the fast fuzzy search structures for all database<br />

columns that have a high load of fuzzy searches, and for all database columns that are used in performance-<br />

critical queries.<br />

Text Types<br />

Text types support a more sophisticated kind of fuzzy search. Texts are tok<strong>en</strong>ized (split into terms) and the fuzzy<br />

comparison is done term by term.<br />

For example, wh<strong>en</strong> searching with 'SAP', a record such as 'SAP Deutschland AG & Co. KG' gets a high score,<br />

because the term 'SAP' exists in both texts. A record such as 'SAPPHIRE NOW Orlando' gets a lower score,<br />

because 'SAP' is only a part of the longer term 'SAPPHIRE' (3 of 8 characters match).<br />

A fuzzy search in text columns replaces non-fault-tolerant statem<strong>en</strong>ts such as<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 259


SELECT ... FROM docum<strong>en</strong>ts WHERE doc_cont<strong>en</strong>t LIKE '% Driethanolamyn %' ...<br />

Supported SQL data types are<br />

● TEXT<br />

● SHORTTEXT<br />

● Full-text index<br />

A full-text index is an additional index structure that can be defined for non-text columns to add text search<br />

features. Supported column types are, for example, NCLOB and NVARCHAR.<br />

It is possible to speed up the fuzzy search by creating additional data structures, which are used for faster<br />

calculation of the fuzzy score. These data structures exist in the memory only, so no additional disk space is<br />

required. To create the additional structures, use the flag 'fast_fuzzy_search' wh<strong>en</strong> creating a TEXT or<br />

SHORTTEXT column or wh<strong>en</strong> creating a full-text index.<br />

To get the best response times possible, you should <strong>en</strong>able the fast fuzzy search structures for all database<br />

columns that have a high load of fuzzy searches and for all database columns that are used in performance-<br />

critical queries.<br />

Other Types<br />

Fuzzy search is available for the SQL type DATE. A fuzzy search on date values checks for date-specific errors<br />

such as dates that lie within a giv<strong>en</strong> range of days, or dates where the month and day have be<strong>en</strong> interchanged (for<br />

example, American versus British date format).<br />

It is not possible to create additional data structures for date types to speed up the search. The queries run with<br />

optimal performance without any database tuning.<br />

Syntax<br />

You can call the fuzzy search by using the CONTAINS() function with the FUZZY() option in the WHERE clause of a<br />

SELECT statem<strong>en</strong>t.<br />

Basic example without additional search options<br />

SELECT SCORE() AS score, *<br />

FROM docum<strong>en</strong>ts<br />

WHERE CONTAINS(doc_cont<strong>en</strong>t, 'Driethanolamyn', FUZZY(0.8))<br />

ORDER BY score DESC;<br />

Example with additional search options<br />

Additional search options that change the default behavior of the fuzzy search can be specified as additional<br />

string parameters in the FUZZY() function.<br />

SELECT SCORE() AS score, *<br />

FROM docum<strong>en</strong>ts<br />

WHERE CONTAINS(doc_cont<strong>en</strong>t, 'Driethanolamyn', FUZZY(0.8, 'option1=value1,<br />

260<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


option2=value2'))<br />

ORDER BY score DESC;<br />

The search options are specified as a comma-separated list of key-value pairs.<br />

Available Fuzzy Search Options<br />

Note that some data types in the table below are data-type combinations.<br />

● Text: SQL types TEXT and SHORTTEXT and any columns that have an additional full-text index<br />

● String: SQL types VARCHAR and NVARCHAR<br />

● Date: SQL type DATE<br />

Table 14: Available Fuzzy Search Options<br />

Name of Option Short<br />

Name<br />

textSearch ts fulltext,<br />

Range Defa<br />

ult<br />

compare<br />

fullte<br />

emptyScore es 0.0..1.0 not<br />

similarCalculatio<br />

nMode<br />

spellCheckFacto<br />

r<br />

abbreviationSimi<br />

larity<br />

bestMatchingTo<br />

k<strong>en</strong>Weight<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

scm search,<br />

compare,<br />

symmetri<br />

csearch<br />

xt<br />

set<br />

comp<br />

are<br />

Applies to<br />

Types<br />

Text, String,<br />

Date<br />

Text, String,<br />

Date<br />

Description<br />

Switches betwe<strong>en</strong> full-text search with TF/IDF<br />

score and duplicate search with fuzzy score.<br />

For more information, see Option textSearch<br />

[page 285].<br />

Defines how an empty and a non-empty value<br />

shall match.<br />

Text, String Defines how the score is calculated for a<br />

comparison of strings (or terms in a Text<br />

column).<br />

For more information, see Option<br />

similarCalculationMode [page 257] .<br />

scf 0.0..1.0 0.9 Text, String Sets the score for strings that get a fuzzy score of<br />

abs 0.0..1.0 0.0 Text<br />

bmtw 0.0..1.0 0 Text<br />

1.0 but are not fully equal.<br />

For more information, see Option<br />

spellCheckFactor [page 253].<br />

Activates abbreviation similarity and sets the<br />

score.<br />

For more information, see Option<br />

abbreviationSimilarity [page 283].<br />

Influ<strong>en</strong>ces the score, shifts total score value<br />

betwe<strong>en</strong> best tok<strong>en</strong> score values and root mean<br />

square of score values.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 261


Name of Option Short<br />

Name<br />

considerNonMat<br />

chingTok<strong>en</strong>s<br />

Range Defa<br />

ult<br />

cnmt max, min,<br />

all, input,<br />

table<br />

max Text<br />

minTextScore mts 0.0..1.0 0.0 Text<br />

andSymmetric as on,off off Text<br />

andThreshold at 0.0..1.0 1.0 Text<br />

termMappingTa<br />

ble<br />

termMappingLis<br />

tId<br />

tmt not<br />

set<br />

Applies to<br />

Types<br />

Text<br />

tmli Text<br />

stopwordTable st not<br />

set<br />

Text<br />

stopwordListId sli Text<br />

262<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

Description<br />

For more information, see Fuzzy Multi-Tok<strong>en</strong><br />

Search on Text Columns [page 278].<br />

Influ<strong>en</strong>ces the score, defines the number of<br />

terms used for score calculation.<br />

For more information, see Fuzzy Multi-Tok<strong>en</strong><br />

Search on Text Columns [page 278].<br />

Minimum score of a TEXT field; if not reached,<br />

the record will not be part of the result.<br />

For more information, see Option minTextScore<br />

[page 284].<br />

Activates a symmetric AND cont<strong>en</strong>t search.<br />

For more information, see Fuzzy Multi-Tok<strong>en</strong><br />

Search with Soft AND [page 281].<br />

Activates a 'soft AND' and determines the<br />

perc<strong>en</strong>tage of the tok<strong>en</strong>s that need to match.<br />

For more information, see Fuzzy Multi-Tok<strong>en</strong><br />

Search with Soft AND [page 281].<br />

Activates the term mappings.<br />

For more information, see Fuzzy Search with<br />

Term Mappings [page 291].<br />

Activates the term mappings.<br />

For more information, see Fuzzy Multi-Tok<strong>en</strong><br />

Search with Soft AND [page 281].<br />

Activates the stopwords.<br />

For more information, see Fuzzy Search with<br />

Stopwords.<br />

Activates the stopwords.<br />

For more information, see Fuzzy Search with<br />

Stopwords.<br />

SAP HANA Developer Guide<br />

Enabling Search


Name of Option Short<br />

Name<br />

maxDateDistanc<br />

e<br />

Range Defa<br />

ult<br />

mdd 0..100 0 Date<br />

Applies to<br />

Types<br />

Description<br />

Specifies the allowed date distance wh<strong>en</strong> using<br />

fuzzy search on dates.<br />

For more information, see Fuzzy Search on DATE<br />

Columns [page 294].<br />

For a list of all allowed search parameter combinations, see Option textSearch [page 285].<br />

Support Information<br />

Memory Usage<br />

Curr<strong>en</strong>tly, all data structures for the fuzzy search share a common 'Pool/FuzzySearch' allocator.<br />

Statistics can be obtained through the system view M_HEAP_MEMORY.<br />

SELECT * FROM sys.m_heap_memory WHERE category LIKE '%FuzzySearch%'<br />

Activating the Trace in the SAP HANA Studio<br />

1. In the SAP HANA studio, op<strong>en</strong> the Administration perspective by double-clicking your system name in the<br />

navigation pane.<br />

2. Select the Diagnosis Files tab and choose Configure in the right corner, as shown below.<br />

3. To configure the trace targets, choose Show All Compon<strong>en</strong>ts and filter for fuzzysearch, as shown below.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 263


To get basic tracing data with information for every search, set the trace level to INFO.<br />

To get detailed information for every search, set the trace level to DEBUG.<br />

Note: Note that DEBUG information cannot be read by <strong>en</strong>d users and should be used for support<br />

issues only.<br />

The default name for the trace file is indexserver_$host_$port.000.trc.<br />

Basic Examples<br />

Speeding Up the Fuzzy Search<br />

You can speed up the fuzzy search for all SQL types except DATE by creating a special data structure called fuzzy<br />

search index. The additional data structures increase the total memory footprint of the loaded table. In<br />

unfavorable cases, the memory footprint of the column can double.<br />

264<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


TEXT and SHORTTEXT<br />

TEXT and SHORTTEXT columns offer the option 'FUZZY SEARCH INDEX' to <strong>en</strong>able and disable the additional data<br />

structures.<br />

Wh<strong>en</strong> creating a table:<br />

CREATE COLUMN TABLE mytable<br />

(<br />

id INTEGER PRIMARY KEY,<br />

col1 TEXT FUZZY SEARCH INDEX ON FAST PREPROCESS ON,<br />

col2 SHORTTEXT(100) FUZZY SEARCH INDEX ON<br />

);<br />

Full-Text Index<br />

A full-text index offers the option 'FUZZY SEARCH INDEX' to <strong>en</strong>able and disable the additional data structures.<br />

Wh<strong>en</strong> creating a full-text index:<br />

CREATE COLUMN TABLE mytable<br />

(<br />

col1 NVARCHAR(2000)<br />

);<br />

CREATE FULLTEXT INDEX myindex ON mytable(col1)<br />

FUZZY SEARCH INDEX ON<br />

FAST PREPROCESS ON;<br />

This can be changed at a later point in time by using the ALTER FULLTEXT INDEX command:<br />

ALTER FULLTEXT INDEX myindex FUZZY SEARCH INDEX OFF;<br />

VARCHAR and NVARCHAR<br />

VARCHAR and NVARCHAR columns also offer the option 'FUZZY SEARCH INDEX' to <strong>en</strong>able and disable the<br />

additional data structures.<br />

Wh<strong>en</strong> creating a table:<br />

CREATE COLUMN TABLE mytable<br />

(<br />

id INTEGER PRIMARY KEY,<br />

col1 VARCHAR(100) FUZZY SEARCH INDEX ON,<br />

col2 NVARCHAR(100) FUZZY SEARCH INDEX ON<br />

);<br />

Additional performance improvem<strong>en</strong>ts are possible wh<strong>en</strong> creating database indexes on the columns.<br />

CREATE INDEX myindex1 ON mytable(col1);<br />

CREATE INDEX myindex2 ON mytable(col2);<br />

The state of the fuzzy search index can be changed at a later point in time by using the ALTER TABLE statem<strong>en</strong>t.<br />

ALTER TABLE mytable ALTER<br />

(<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 265


col1 VARCHAR(100) FUZZY SEARCH INDEX OFF,<br />

col2 NVARCHAR(100)<br />

);<br />

The view SYS.TABLE_COLUMNS shows the curr<strong>en</strong>t state of the fuzzy search index. Wh<strong>en</strong> working with attribute<br />

views, this information is also visible in SYS.VIEW_COLUMNS.<br />

SELECT column_name, data_type_name, fuzzy_search_index<br />

FROM table_columns<br />

WHERE table_name = 'MYTABLE';<br />

Fuzzy Search on One Column<br />

1. Create the data.<br />

CREATE COLUMN TABLE companies<br />

(<br />

id INTEGER PRIMARY KEY,<br />

companyname SHORTTEXT(200) FUZZY SEARCH INDEX ON<br />

);<br />

INSERT INTO companies VALUES (1, 'SAP Corp');<br />

INSERT INTO companies VALUES (2, 'SAP in Walldorf Corp');<br />

INSERT INTO companies VALUES (3, 'ASAP');<br />

INSERT INTO companies VALUES (4, 'ASAP Corp');<br />

INSERT INTO companies VALUES (5, 'BSAP orp');<br />

INSERT INTO companies VALUES (6, 'IBM Corp');<br />

2. Perform the search on one column.<br />

SELECT SCORE() AS score, * FROM companies<br />

WHERE CONTAINS(companyname,'xSAP Corp Walldorf',<br />

FUZZY(0.7,'textSearch=compare,bestMatchingTok<strong>en</strong>Weight=0.7'))<br />

ORDER BY score DESC;<br />

SCORE ID COMPANYNAME<br />

0.94 2 SAP in Walldorf Corp<br />

Fuzzy Search on Two Columns<br />

1. Create the data.<br />

266<br />

CREATE COLUMN TABLE companies2<br />

(<br />

id INTEGER PRIMARY KEY,<br />

companyname SHORTTEXT(200) FUZZY SEARCH INDEX ON,<br />

contact SHORTTEXT(100) FUZZY SEARCH INDEX ON<br />

);<br />

INSERT INTO companies2 VALUES (1, 'SAP Corp', 'Mister Master');<br />

INSERT INTO companies2 VALUES (2, 'SAP in Walldorf Corp', 'Master<br />

Mister');<br />

INSERT INTO companies2 VALUES (3, 'ASAP', 'Nister Naster');<br />

INSERT INTO companies2 VALUES (4, 'ASAP Corp', 'Mixter Maxter');<br />

INSERT INTO companies2 VALUES (5, 'BSAP orp', 'Imster Marter');<br />

INSERT INTO companies2 VALUES (6, 'IBM Corp', 'M. Master');<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


2. Perform the search on two columns.<br />

SELECT SCORE() AS score, * FROM companies2<br />

WHERE CONTAINS(companyname, 'IBM',<br />

FUZZY(0.7,'textSearch=compare,bestMatchingTok<strong>en</strong>Weight=0.7'))<br />

AND CONTAINS(contact, 'Master',<br />

FUZZY(0.7,'textSearch=compare,bestMatchingTok<strong>en</strong>Weight=0.7'))<br />

ORDER BY score DESC;<br />

SCORE ID COMPANYNAME CONTACT<br />

0.91 6 IBM Corp M. Master<br />

3. Perform a freestyle search.<br />

SELECT SCORE() AS score, * FROM companies2<br />

WHERE CONTAINS((companyname,contact), 'IBM Master', FUZZY(0.7))<br />

ORDER BY score DESC;<br />

SCORE ID COMPANYNAME CONTACT<br />

0.8 6 IBM Corp M. Master<br />

Note: Freestyle search always uses TF/IDF to calculate the score and does not support parameters<br />

such as 'textSearch=compare' or 'bestMatchingTok<strong>en</strong>Weight=0.7' that influ<strong>en</strong>ce score calculation.<br />

Therefore, we get a differ<strong>en</strong>t score for the same record.<br />

Fuzzy Search on String Columns<br />

String types support a basic fuzzy string search. The values of a column are compared with the user input using<br />

the fault-tolerant fuzzy string comparison.<br />

Wh<strong>en</strong> working with string types, the fuzzy string compare always compares the full strings. Wh<strong>en</strong>, for example,<br />

searching with 'SAP', a record such as 'SAP Deutschland AG & Co. KG' gets a very low score, because only a very<br />

small part of the string is equal (3 of 27 characters match).<br />

A fuzzy search on string types is a replacem<strong>en</strong>t for a non-fault-tolerant SQL statem<strong>en</strong>t such as<br />

SELECT ... FROM products WHERE product_name = 'coffe krisp biscuit' ...<br />

that would not return any results because of the spelling errors.<br />

Supported SQL data types are VARCHAR and NVARCHAR.<br />

It is possible to speed up the fuzzy search by creating additional data structures called 'fuzzy search indexes',<br />

which are used for a faster calculation of the fuzzy score. These indexes exist in the memory only, so no additional<br />

disk space is needed.<br />

To get the best response times possible, you should <strong>en</strong>able the fuzzy search indexes for all database columns that<br />

have a high load of fuzzy searches and for all database columns that are used in performance-critical queries.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 267


Use Case Fuzzy Search - House Numbers<br />

Score Calculation<br />

The house number comparison aims for a 'simple' solution that is easy to understand, gives good results, and<br />

works for most countries. The limitations of the algorithm are:<br />

● The algorithm focuses on numeric values - either a single number ('8') or a range of numbers ('8 - 12').<br />

● House number additions (for example, the 'a' in '8a') are either equal or not equal.<br />

Wh<strong>en</strong> comparing two strings containing house numbers with each other, the score is calculated according to the<br />

rules described below.<br />

House number addition. A house number addition in terms of this backlog item is any additional text that is<br />

writt<strong>en</strong> before or after the numeric value of a house number.<br />

House number ranges. Wh<strong>en</strong> a string contains at least two numbers and there is a dash betwe<strong>en</strong> the first and<br />

second number, this is treated as a house number range. The first number is the lower bound of the range, the last<br />

number is the upper bound.<br />

Multiple numbers. Wh<strong>en</strong> multiple numbers are part of a house number string that does not define a house<br />

number range, the first number is the house number used for the comparison. All remaining information is used<br />

as a house number addition.<br />

Whitespace characters. For all rules, whitespace characters are ignored wh<strong>en</strong> comparing the house numbers.<br />

For the score calculation it does not matter if a house number is giv<strong>en</strong> as '8a' or '8 a' or if it is '8-10' or '8 - 10'.<br />

Symmetry. In all examples, the score calculation is symmetric. This means that either string 1 or string 2 can be<br />

the user input and the other string is stored in the database table.<br />

Rule 1 - House Numbers or House Number Ranges Are Id<strong>en</strong>tical<br />

For id<strong>en</strong>tical house numbers, a score of 1.0 is returned. Id<strong>en</strong>tical house numbers are house number strings that<br />

are equal wh<strong>en</strong> whitespace characters are ignored.<br />

Examples:<br />

String 1 String 2 Score<br />

5 5 1.0<br />

5a 5 a 1.0<br />

8-12 8-12 1.0<br />

9 in the backyard 9 in the backyard 0.9<br />

268<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Rule 2 - House Numbers or House Number Ranges Are Very Similar (House<br />

Number Additions Are Differ<strong>en</strong>t)<br />

House numbers or house number ranges are considered very similar wh<strong>en</strong> the numeric values are id<strong>en</strong>tical but<br />

the additional information differs.<br />

Examples:<br />

String 1 String 2 Score<br />

5 5 a 0.9<br />

5a 5 b 0.9<br />

5 Nr. 5 0.9<br />

8-12 8 - 12a 0.9<br />

8-12 8 - 12/5 0.9<br />

8 this is a long text -12 8 - 12a 0.9<br />

7 below 7 0.9<br />

9 9 in the backyard 0.9<br />

9 in the backyard 9 in the backyard 0.9<br />

Rule 3 - House Numbers or House Number Ranges Are Less Similar<br />

House numbers and house number ranges are considered less similar in the following cases:<br />

1. A house number is compared to a house number range and the numeric value of the house number equals the<br />

lower or upper bound of the range.<br />

2. Two house number ranges are compared and the numeric value of either the lower or upper bound are equal.<br />

String 1 String 2 Score<br />

8 8-12 0.8<br />

12a 8-12 0.8<br />

8-10 8-12 0.8<br />

8-10 8-10/12 0.8<br />

10-12a 8-12 0.8<br />

8 in the backyard 8-12 0.8<br />

Rule 4 - Overlapping House Number Ranges<br />

House numbers and house number ranges overlap in the following cases:<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 269


1. A house number is compared to a house number range and the numeric value of the house number lies within<br />

the range.<br />

2. Two house number ranges are compared and the ranges overlap.<br />

Examples:<br />

String 1 String 2 Score<br />

10 8-12 0.7<br />

10a 8-12 0.7<br />

9 8-12 0.7<br />

8-12 10-14 0.7<br />

8-12a 10b-14 0.7<br />

Last Rule - House Numbers Are Not Equal<br />

Examples:<br />

String 1 String 2 Score<br />

5 6 0.0<br />

8a 9a 0.0<br />

6 8-12 0.0<br />

8-10 12-14 0.0<br />

House Number Columns and Other String Search Options<br />

The following search options available for string column types are not valid for house number columns.<br />

SpellCheckFactor<br />

Wh<strong>en</strong> comparing house numbers, the search option 'spellCheckFactor' is ignored. So for house numbers, the<br />

results are always the same as with 'spellCheckFactor=1.0'.<br />

SimilarCalculationMode<br />

Wh<strong>en</strong> comparing house numbers, the search option 'similarCalculationMode' is ignored and has no effect on the<br />

search result. Both options are ignored, no error is returned wh<strong>en</strong> any of the options is giv<strong>en</strong>.<br />

SQL Syntax<br />

To <strong>en</strong>able the search for house numbers on an (N)VARCHAR column, the FUZZY SEARCH MODE clause is used in<br />

a CREATE TABLE statem<strong>en</strong>t.<br />

CREATE COLUMN TABLE tab<br />

(<br />

id INTEGER PRIMARY KEY,<br />

270<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


col1 NVARCHAR(20) FUZZY SEARCH MODE 'hous<strong>en</strong>umber'<br />

);<br />

To <strong>en</strong>able or disable the house number search mode at a later point in time, you use the ALTER TABLE statem<strong>en</strong>t.<br />

The fuzzy search mode is not changed if the FUZZY SEARCH MODE clause is omitted.<br />

-- <strong>en</strong>able hous<strong>en</strong>umber search<br />

ALTER TABLE tab ALTER<br />

(<br />

col1 VARCHAR(20) FUZZY SEARCH MODE 'hous<strong>en</strong>umber'<br />

);<br />

-- disable hous<strong>en</strong>umber search<br />

ALTER TABLE tab ALTER<br />

(<br />

col1 VARCHAR(20) FUZZY SEARCH MODE NULL<br />

);<br />

-- do not change the status of the search mode<br />

ALTER TABLE tab ALTER<br />

(<br />

col1 VARCHAR(20)<br />

);<br />

You can query the state of the fuzzy search mode by using the system view TABLE_COLUMNS.<br />

SELECT column_name, data_type_name, fuzzy_search_mode<br />

FROM table_columns<br />

WHERE table_name = 'TAB';<br />

Example<br />

Note: You cannot use a fuzzy search index in combination with the house number search mode.<br />

The following example creates a table that contains a single house number column only and executes some<br />

searches on this column.<br />

CREATE COLUMN TABLE hous<strong>en</strong>umbers<br />

(<br />

hous<strong>en</strong>umber NVARCHAR(50) FUZZY SEARCH MODE 'hous<strong>en</strong>umber'<br />

);<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('5');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('5a');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('5 a');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('Nr. 5');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('8-12');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('8 - 12');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('8 - 12a');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('Nr. 8-12');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('8 - 12/5');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('8');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('12a');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('8-10');<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 271


INSERT INTO hous<strong>en</strong>umbers VALUES ('10-12a');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('10a');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('10-14');<br />

INSERT INTO hous<strong>en</strong>umbers VALUES ('9');<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM hous<strong>en</strong>umbers<br />

WHERE CONTAINS(hous<strong>en</strong>umber, '5', FUZZY(0.8))<br />

ORDER BY TO_DECIMAL(SCORE(),3,2) DESC;<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM hous<strong>en</strong>umbers<br />

WHERE CONTAINS(hous<strong>en</strong>umber, 'Nr. 5', FUZZY(0.8))<br />

ORDER BY TO_DECIMAL(SCORE(),3,2) DESC;<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM hous<strong>en</strong>umbers<br />

WHERE CONTAINS(hous<strong>en</strong>umber, '8a-12', FUZZY(0.8))<br />

ORDER BY TO_DECIMAL(SCORE(),3,2) DESC;<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM hous<strong>en</strong>umbers<br />

WHERE CONTAINS(hous<strong>en</strong>umber, '10-12', FUZZY(0.8))<br />

ORDER BY TO_DECIMAL(SCORE(),3,2) DESC;<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM hous<strong>en</strong>umbers<br />

WHERE CONTAINS(hous<strong>en</strong>umber, '9 in the BACKYARD', FUZZY(0.8))<br />

ORDER BY TO_DECIMAL(SCORE(),3,2) DESC;<br />

Use Case Fuzzy Search - Postcodes<br />

Postcodes in almost all countries are ordered by region. This means that if the leading characters of the<br />

postcodes of two differ<strong>en</strong>t addresses are the same, the addresses are near to each other. In Germany, for<br />

example, addresses within large cities share the first or ev<strong>en</strong> the first two digits of their postcode.<br />

The only exception known to the <strong>dev</strong>elopm<strong>en</strong>t team is Cambodia, where postcodes are not ordered by region.<br />

Wh<strong>en</strong> doing a fuzzy search on addresses, it makes s<strong>en</strong>se to return a higher score for postcodes that are 'near' to a<br />

giv<strong>en</strong> user input than for postcodes that are 'far away' from the user input. It makes s<strong>en</strong>se to give a higher weight<br />

to the leading characters and a lower weight to the trailing characters of the postcode.<br />

Valid addresses may contain a country code in front of the postcode (for example, 'D-12345' or 'DE-12345' for a<br />

German address). This is also supported by the fuzzy postcode search.<br />

Score Calculation<br />

Before the fuzzy score is calculated, the postcode strings are standardized.<br />

1. Country codes are separated from the postcode strings. Country codes in this case consist of one to three<br />

272<br />

letters (a-z only, no numbers) at the beginning of the postcode, followed by a minus sign. Longer words are<br />

not considered a country code because postal standards do not allow country names in front of the postcode.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


2. Country codes are standardized to <strong>en</strong>able a comparison of differ<strong>en</strong>t codes for the same country, for example,<br />

'D-', 'DE-' and 'DEU-' for German postcodes. All unknown/invalid country codes are standardized to one<br />

special 'dummy' country code.<br />

3. Spaces and dashes are removed from the remaining postcode.<br />

4. All letters are standardized to uppercase.<br />

User Input Country Code Remaining Postcode<br />

71691 71691<br />

716 91 71691<br />

D-71691 D 71691<br />

DE-71 691 DE 71691<br />

D 71691 D71691<br />

Germany-71691 GERMANY71691<br />

GB-A1H 2ZU GB A1H2ZU<br />

A1H-2ZU A1H2ZU<br />

gb-A1h 2zu GB A1H2ZU<br />

XY-12345 XX 12345<br />

zz-12345 XX 12345<br />

AI-2640 AI 2640<br />

The last example is the only known example where the country code is part of the postcode (AI = Anguilla). The<br />

algorithm works here as well, as the country code is also compared. The two examples directly above the AI<br />

example show invalid country codes. Both are standardized to the same non-exist<strong>en</strong>t 'dummy' country code.<br />

Postcode Comparison<br />

The standardized postcodes are compared using a variation of the fuzzy string comparison. This variation gives a<br />

higher weight to the first two characters of the postcode.<br />

Country codes are giv<strong>en</strong> the same weight as a single character at the <strong>en</strong>d of the postcode.<br />

● Only postcodes with the same country code can get a score of 1.0.<br />

● If one country code is giv<strong>en</strong> and the second country code is empty, the score of the postcode comparison is<br />

less than 1.0.<br />

● If both country codes are giv<strong>en</strong> and are differ<strong>en</strong>t, the score of the postcode comparison is also less than 1.0.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 273


Parameter similarCalculationMode<br />

The search option 'similarCalculationMode' with options 'search' and 'symmetricsearch' is available for postcode<br />

columns.<br />

Wh<strong>en</strong> using the search option 'similarCalculationMode', a postcode search with a postcode prefix will find all<br />

addresses in a giv<strong>en</strong> area.<br />

● A search with '71' returns all postcodes beginning with '71'.<br />

● A search with '1234' returns all postcodes starting with a sequ<strong>en</strong>ce similar to '1234' and, with a lower score, all<br />

postcodes that contain a '1234'.<br />

Parameter spellCheckFactor<br />

Two postcodes may be considered id<strong>en</strong>tical by the fuzzy string comparison, but may still be differ<strong>en</strong>t. In this case,<br />

the value of the parameter 'spellCheckFactor' is applied and the score is multiplied by the spellCheckFactor.<br />

Examples for non-equal postcodes that get a score of 1.0 are:<br />

● '123456' and '12 34 56'<br />

● '7070717' and '7071707'<br />

The default value of the search option spellCheckFactor is 0.9. To disable this feature, set 'spellCheckFactor=1.0'.<br />

Example<br />

The following example uses a spellCheckFactor of 1.0, which is not the default value.<br />

Postcode 1 Postcode 2 Score Remarks<br />

71691 71691 1.0<br />

71691 71 691 1.0<br />

71691 81691 0.51 Highest weight on the<br />

first digit<br />

71691 72691 0.7 High weight on the<br />

second digit<br />

71691 71692 0.96 Lower weight on all<br />

other digits<br />

71691 D-71691 0.96 Country code missing<br />

in one column<br />

D-71691 A-71691 0.96 Country codes are<br />

71691 D-71692 0.92<br />

D-71691 A-71692 0.92<br />

274<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

differ<strong>en</strong>t<br />

SAP HANA Developer Guide<br />

Enabling Search


Postcode 1 Postcode 2 Score Remarks<br />

GB-A1H 2ZU Gb-a1h2zu 1.0<br />

XX-12345 YY-12345 1.0 Invalid country codes<br />

are 'equal'<br />

D-12345 YY-12345 0.96 Valid and invalid<br />

SQL Syntax<br />

country code<br />

(N)VARCHAR columns have to be defined as postcode columns to <strong>en</strong>able the fuzzy postcode search. You do this<br />

by using the FUZZY SEARCH MODE clause.<br />

In addition, it is also possible to increase the performance of the postcode search by activating a fuzzy search<br />

index and by creating a database index on the postcode column.<br />

CREATE COLUMN TABLE tab<br />

(<br />

id INTEGER PRIMARY KEY,<br />

postcode NVARCHAR(20) FUZZY SEARCH INDEX ON FUZZY SEARCH MODE<br />

'postcode'<br />

);<br />

CREATE INDEX myindex1 ON tab(postcode);<br />

The postcode search can be <strong>en</strong>abled or disabled at a later point in time with the ALTER TABLE statem<strong>en</strong>t. Do not<br />

specify the FUZZY SEARCH MODE clause to disable the postcode search.<br />

-- <strong>en</strong>able postcode search<br />

ALTER TABLE tab ALTER<br />

(<br />

postcode NVARCHAR(100) FUZZY SEARCH MODE 'postcode'<br />

);<br />

-- disable postcode search<br />

ALTER TABLE tab ALTER<br />

(<br />

postcode NVARCHAR(100) FUZZY SEARCH MODE NULL<br />

);<br />

-- do not change the status of the search mode<br />

ALTER TABLE tab ALTER<br />

(<br />

postcode NVARCHAR(100)<br />

);<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 275


You can query the status of the fuzzy search index and the fuzzy search mode from the system view<br />

TABLE_COLUMNS.<br />

SELECT column_name, data_type_name, fuzzy_search_index, fuzzy_search_mode<br />

FROM table_columns<br />

WHERE table_name = 'TAB';<br />

Example<br />

CREATE COLUMN TABLE postcodes<br />

(<br />

postcode NVARCHAR(50) FUZZY SEARCH INDEX ON FUZZY SEARCH MODE 'postcode'<br />

);<br />

INSERT INTO postcodes VALUES ('71691');<br />

INSERT INTO postcodes VALUES ('81691');<br />

INSERT INTO postcodes VALUES ('72691');<br />

INSERT INTO postcodes VALUES ('71692');<br />

INSERT INTO postcodes VALUES ('716 91');<br />

INSERT INTO postcodes VALUES ('A1H 2ZU');<br />

INSERT INTO postcodes VALUES ('A1H2ZU');<br />

INSERT INTO postcodes VALUES ('D-71691');<br />

INSERT INTO postcodes VALUES ('D-71692');<br />

INSERT INTO postcodes VALUES ('A-71691');<br />

INSERT INTO postcodes VALUES ('A-71692');<br />

INSERT INTO postcodes VALUES ('DE-71 691');<br />

INSERT INTO postcodes VALUES ('D 71691');<br />

INSERT INTO postcodes VALUES ('GB-A1H 2ZU');<br />

INSERT INTO postcodes VALUES ('XX-12345');<br />

INSERT INTO postcodes VALUES ('D-12345');<br />

INSERT INTO postcodes VALUES ('71234');<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM postcodes<br />

WHERE CONTAINS(postcode, '71691', FUZZY(0.5, 'spellCheckFactor=1.0'))<br />

ORDER BY SCORE() DESC;<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM postcodes<br />

WHERE CONTAINS(postcode, 'D-71691', FUZZY(0.5, 'spellCheckFactor=1.0'))<br />

ORDER BY SCORE() DESC;<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM postcodes<br />

WHERE CONTAINS(postcode, 'Gb-a1h2zu', FUZZY(0.5, 'spellCheckFactor=1.0'))<br />

ORDER BY SCORE() DESC;<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM postcodes<br />

WHERE CONTAINS(postcode, 'YY-12345', FUZZY(0.5, 'spellCheckFactor=1.0'))<br />

ORDER BY SCORE() DESC;<br />

SELECT TO_DECIMAL(SCORE(),3,2), *FROM postcodes<br />

WHERE CONTAINS(postcode, '71', FUZZY(0.5, 'spellCheckFactor=1.0'))<br />

ORDER BY SCORE() DESC;<br />

SELECT TO_DECIMAL(SCORE(),3,2), *<br />

FROM postcodes<br />

276<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


WHERE CONTAINS(postcode, '1234', FUZZY(0.5, 'spellCheckFactor=1.0'))<br />

ORDER BY SCORE() DESC;<br />

Fuzzy Search on Text Columns<br />

Text types support a more sophisticated kind of fuzzy search. Texts are tok<strong>en</strong>ized (split into terms) and the fuzzy<br />

comparison is done term by term. For example, wh<strong>en</strong> searching with 'SAP', a record such as 'SAP Deutschland AG<br />

& Co. KG' gets a high score, because the term 'SAP' exists in both texts. A record such as 'SAPPHIRE NOW<br />

Orlando' gets a lower score, because 'SAP' is only a part of the longer term 'SAPPHIRE' (3 of 8 characters match).<br />

Fuzzy search on text columns replaces non-fault-tolerant statem<strong>en</strong>ts such as<br />

SELECT ... FROM docum<strong>en</strong>ts WHERE doc_cont<strong>en</strong>t LIKE '% Driethanolamyn %' ...<br />

The following SQL data types are supported:<br />

● TEXT<br />

● SHORTTEXT<br />

● fulltext index<br />

A fulltext index is an additional index structure that can be defined for non-text columns to add text search<br />

features. Supported column types are, for example, NCLOB and NVARCHAR.<br />

It is possible to speed up the fuzzy search by creating data structures called 'fuzzy search indexes', which are<br />

used for a faster calculation of the fuzzy score. These indexes exist in the memory only, so no additional disk<br />

space is needed.<br />

To get the best response times possible, you should <strong>en</strong>able the fuzzy search indexes for all database columns that<br />

have a high load of fuzzy searches and for all database columns that are used in performance-critical queries.<br />

Fuzzy Search on SQL Type TEXT<br />

A call to contains that refer<strong>en</strong>ces a TEXT column is automatically processed as a text search. In this case, the<br />

mode textsearch=compare and all fuzzy search options are allowed:<br />

CREATE COLUMN TABLE mytable<br />

(<br />

col1 TEXT<br />

);<br />

SELECT score() AS score, * FROM mytable WHERE contains(col1, 'a b',<br />

fuzzy(0.8, 'textsearch=compare'));<br />

Fuzzy Search on SQL Type SHORTTEXT<br />

Wh<strong>en</strong> a SHORTTEXT column is created, a column of column store type cs_string and a second hidd<strong>en</strong> text<br />

column are created. A call to contains that refer<strong>en</strong>ces the SHORTTEXT column is automatically redirected by the<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 277


freestyler to the additional hidd<strong>en</strong> TEXT column. In this case, the mode textsearch=compare and all fuzzy search<br />

options are allowed:<br />

CREATE COLUMN TABLE mytable<br />

(<br />

col1 SHORTTEXT(200)<br />

);<br />

SELECT score() AS score, * FROM mytable WHERE contains(col1, 'a b',<br />

fuzzy(0.8, 'textsearch=compare'));<br />

Fuzzy Search on a FULLTEXT INDEX<br />

Wh<strong>en</strong> a full text index is created on a column that is not of type TEXT (e.g. NVARCHAR, NCLOB, ...) a hidd<strong>en</strong> text<br />

column is added to the table. A call to contains that refer<strong>en</strong>ces the non-TEXT column is automatically redirected<br />

by the freestyler to the additional text column. In this case, the mode textsearch=compare and all fuzzy search<br />

options are allowed:<br />

CREATE COLUMN TABLE mytable<br />

(<br />

col1 NVARCHAR(2000)<br />

);<br />

CREATE FULLTEXT INDEX myindex ON mytable(col1);<br />

SELECT score() AS score, * FROM mytable WHERE contains(col1, 'a b',<br />

fuzzy(0.8, 'textsearch=compare'));<br />

Merge Delta for Better Performance<br />

Wh<strong>en</strong> inserting or loading a large number of rows in a table that has a TEXT or SHORTTEXT column or that uses a<br />

FULLTEXT INDEX, it is important to merge the delta part of the table to get a good search performance.<br />

A delta merge can be started manually with the following SQL statem<strong>en</strong>t:<br />

MERGE DELTA OF mytable;<br />

Alternatively, a delta merge can be triggered automatically by the mergedog process.<br />

Fuzzy Multi-Tok<strong>en</strong> Search on Text Columns<br />

Cont<strong>en</strong>t Types<br />

Wh<strong>en</strong> using more than one tok<strong>en</strong> within a query, the default cont<strong>en</strong>t type is AND (for example, ... WHERE<br />

CONTAINS (mycolumn, 'software firm', FUZZY(0.5)) ... will return <strong>en</strong>tries that contain a tok<strong>en</strong> similar to 'software'<br />

and a tok<strong>en</strong> similar to 'firm').<br />

Alternatively, you can use OR by adding the key word betwe<strong>en</strong> the tok<strong>en</strong>s (for example, ... WHERE CONTAINS<br />

(mycolumn, 'apple OR 'banana', FUZZY(0.5)) ... will return <strong>en</strong>tries that contain a tok<strong>en</strong> similar to 'apple' and<br />

<strong>en</strong>tries that contain a tok<strong>en</strong> similar to 'banana').<br />

278<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


PHRASE is similar to AND but restricts hits to those that contain the tok<strong>en</strong>s as a phrase, that is, in the same order<br />

and with nothing betwe<strong>en</strong> them. A PHRASE is indicated by adding double quotes around the tok<strong>en</strong>s, within the<br />

single quotes (for example, ... WHERE CONTAINS (mycolumn, '"day dream"', FUZZY(0.5)) ... will not return an<br />

<strong>en</strong>try containing 'I dream of a day').<br />

The cont<strong>en</strong>t type AND that is used for a full-text search (default behavior: textSearch=fulltext) is implem<strong>en</strong>ted as<br />

a logical AND to achieve better performance. For example, a search for 'Miller & Miller AG' with cont<strong>en</strong>t type AND<br />

matches 'Miller AG'.<br />

textSearch=compare should be used for duplicate detection and for comparing company names, product names,<br />

and so on. Here, search results are better because of the strict AND comparison that is used. In other words, if<br />

you search for 'Miller & Miller' with cont<strong>en</strong>t type AND, only records that contain the term 'Miller' at least twice are<br />

returned.<br />

A strict AND assigns terms from the user input to terms in the database <strong>en</strong>try only once (and vice versa). For<br />

more information, see Fuzzy Multi-Tok<strong>en</strong> Search with Soft AND [page 281].<br />

Parameters Influ<strong>en</strong>cing the Score<br />

Name of Option Range Default Applies to Types<br />

bestMatchingTok<strong>en</strong>Weigh<br />

t<br />

considerNonMatchingTok<br />

<strong>en</strong>s<br />

Formula for score calculation:<br />

0.0..1.0 not set TEXT<br />

max, min, all, input, table max TEXT<br />

score = bestMatchingTok<strong>en</strong>Weight x max(tok<strong>en</strong>Scores) + (1-bestMatchingTok<strong>en</strong>Weight) x √(Σ(tok<strong>en</strong>Score²)/<br />

tok<strong>en</strong>Count)<br />

tok<strong>en</strong>Count is determined according to the parameter considerNonMatchingTok<strong>en</strong>s as follows:<br />

● input: Use search term tok<strong>en</strong> count<br />

● table: Use column value tok<strong>en</strong> count<br />

● all: Use sum of search and column value tok<strong>en</strong> count (where the numerator is multiplied by 2)<br />

● min: Use smaller value of tok<strong>en</strong> counts<br />

● max: Use larger value of tok<strong>en</strong> counts (default)<br />

Recomm<strong>en</strong>dations for specific search cont<strong>en</strong>t types<br />

If you are using an "OR" search (searching for "this or that"), you should set considerNonMatchingTok<strong>en</strong>s to table<br />

to get a useful score assessm<strong>en</strong>t.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 279


Example<br />

DROP TABLE test_table;<br />

CREATE COLUMN TABLE test_table<br />

(<br />

id INTEGER PRIMARY KEY,<br />

t SHORTTEXT(200) FUZZY SEARCH INDEX ON<br />

);<br />

INSERT INTO test_table VALUES ('1','eins');<br />

INSERT INTO test_table VALUES ('2','eins zwei');<br />

INSERT INTO test_table VALUES ('3','eins zwei drei');<br />

INSERT INTO test_table VALUES ('4','eins zwei drei vier');<br />

INSERT INTO test_table VALUES ('5','eins zwei drei vier funf');<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM test_table<br />

WHERE CONTAINS(t, 'eins zwoi drei',<br />

FUZZY(0.5,'textSearch=compare,bestMatchingTok<strong>en</strong>Weight=1.0'))<br />

ORDER BY score DESC, id;<br />

SCORE ID T<br />

1 3 eins zwei drei<br />

1 4 eins zwei drei vier<br />

1 5 eins zwei drei vier funf<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM test_table<br />

WHERE CONTAINS(t, 'eins zwoi drei',<br />

FUZZY(0.5,'textSearch=compare,bestMatchingTok<strong>en</strong>Weight=0'))<br />

ORDER BY score DESC, id;<br />

SCORE ID T<br />

0.92 3 eins zwei drei<br />

0.8 4 eins zwei drei vier<br />

0.71 5 eins zwei drei vier funf<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM test_table<br />

WHERE CONTAINS(t, 'eins zwoi drei',<br />

FUZZY(0.5,'textSearch=compare,bestMatchingTok<strong>en</strong>Weight=0,considerNonMatching<br />

Tok<strong>en</strong>s=all'))<br />

ORDER BY score DESC, id;<br />

SCORE ID T<br />

0.92 3 eins zwei drei<br />

0.85 4 eins zwei drei vier<br />

0.8 5 eins zwei drei vier funf<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM test_table<br />

WHERE CONTAINS(t, 'eins zwoi drei',<br />

FUZZY(0.5,'textSearch=compare,bestMatchingTok<strong>en</strong>Weight=0,considerNonMatching<br />

280<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Tok<strong>en</strong>s=input'))<br />

ORDER BY score DESC, id;<br />

SCORE ID T<br />

0.92 3 eins zwei drei<br />

0.92 4 eins zwei drei vier<br />

0.92 5 eins zwei drei vier funf<br />

Parameters Influ<strong>en</strong>cing the Result Set<br />

Option Range Default Applies to Types<br />

andSymmetric on,off off TEXT<br />

andThreshold 0.0..1.0 1.0 TEXT<br />

For examples, see Fuzzy Multi-Tok<strong>en</strong> Search with Soft AND [page 281] .<br />

Fuzzy Multi-Tok<strong>en</strong> Search with Soft AND<br />

A fuzzy search on one text column can also use a softer AND, so that not all tok<strong>en</strong>s used in the search term have<br />

to match the result.<br />

There are two parameters that control this behavior:<br />

Option Name Range Default Applies to Types Short Description<br />

andSymmetric on,off off TEXT Activates a<br />

symmetric AND<br />

cont<strong>en</strong>t search<br />

andThreshold 0.0..1.0 1.0 TEXT Determines the<br />

Creating example data:<br />

DROP TABLE test_soft_and;<br />

CREATE COLUMN TABLE test_soft_and<br />

(<br />

id INTEGER PRIMARY KEY,<br />

t SHORTTEXT(200) FUZZY SEARCH INDEX ON<br />

);<br />

INSERT INTO test_soft_and VALUES ('1','eins');<br />

INSERT INTO test_soft_and VALUES ('2','eins zwei');<br />

INSERT INTO test_soft_and VALUES ('3','eins zwei drei');<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

perc<strong>en</strong>tage of<br />

tok<strong>en</strong>s that need to<br />

match<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 281


INSERT INTO test_soft_and VALUES ('4','eins zwei drei vier');<br />

INSERT INTO test_soft_and VALUES ('5','eins zwei drei vier funf');<br />

Search with andSymmetric=off<br />

SELECT SCORE() AS score, * FROM test_soft_and<br />

WHERE CONTAINS(T, 'eins zwei drei', FUZZY(0.5,<br />

'andSymmetric=off,bestMatchingTok<strong>en</strong>Weight=0.5,textSearch=compare'))<br />

ORDER BY score DESC, id;<br />

SCORE ID T<br />

1 3 eins zwei drei<br />

0.933012723922729 4 eins zwei drei vier<br />

0.887298345565796 5 eins zwei drei vier funf<br />

Search with andSymmetric=on<br />

SELECT SCORE() AS score, * FROM test_soft_and<br />

WHERE CONTAINS(T, 'eins zwei drei',<br />

FUZZY(0.5,'andSymmetric=on,bestMatchingTok<strong>en</strong>Weight=0.5,textSearch=compare')<br />

)<br />

ORDER BY score DESC, id;<br />

SCORE ID T<br />

1 3 eins zwei drei<br />

0.933012723922729 4 eins zwei drei vier<br />

0.90824830532074 2 eins zwei<br />

0.887298345565796 5 eins zwei drei vier funf<br />

0.788675129413605 1 eins<br />

Search with andThreshold<br />

SELECT SCORE() AS score, * FROM test_soft_and<br />

WHERE CONTAINS(T, 'eins XXX drei vier',<br />

FUZZY(0.5,'andThreshold=0.75,bestMatchingTok<strong>en</strong>Weight=0.5,textSearch=compare<br />

'))<br />

ORDER BY score DESC, id;<br />

SCORE ID T<br />

0.933012723922729 4 eins zwei drei vier<br />

0.887298345565796 5 eins zwei drei vier funf<br />

SELECT SCORE() AS score, * FROM test_soft_and<br />

WHERE CONTAINS(T, 'eins XXX drei vier',<br />

FUZZY(0.5,'andThreshold=0.5,bestMatchingTok<strong>en</strong>Weight=0.5,textSearch=compare'<br />

282<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


))<br />

ORDER BY score DESC, id;<br />

SCORE ID T<br />

0.933012723922729 4 eins zwei drei vier<br />

0.887298345565796 5 eins zwei drei vier funf<br />

0.853553414344788 3 eins zwei drei<br />

Option abbreviationSimilarity<br />

The option abbreviationSimilarity is used to search for and find a word using its first character and vice versa with<br />

a giv<strong>en</strong> score. With abbreviationSimilarity = 0.9, a SELECT retrieves “word” with SCORE = 0.9 wh<strong>en</strong> you search<br />

with “w” (and vice versa).<br />

CREATE COLUMN TABLE abbrev<br />

(<br />

id INTEGER PRIMARY KEY,<br />

name SHORTTEXT(200) FUZZY SEARCH INDEX ON<br />

);<br />

INSERT INTO abbrev VALUES ('1','Peter');<br />

INSERT INTO abbrev VALUES ('2','Hans');<br />

INSERT INTO abbrev VALUES ('3','H.');<br />

INSERT INTO abbrev VALUES ('4','P.');<br />

INSERT INTO abbrev VALUES ('5','Hans-Peter');<br />

INSERT INTO abbrev VALUES ('6','H.-P.');<br />

INSERT INTO abbrev VALUES ('7','HP');<br />

INSERT INTO abbrev VALUES ('8','G Gerd');<br />

INSERT INTO abbrev VALUES ('9','G');<br />

INSERT INTO abbrev VALUES ('10','Gerd');<br />

Search one tok<strong>en</strong> with abbreviationSimilarity<br />

SELECT SCORE() AS score, id, name FROM abbrev<br />

WHERE CONTAINS(name, 'HP', FUZZY(0.5,<br />

'abbreviationSimilarity=0.80,textSearch=compare'))<br />

ORDER BY score DESC, id;<br />

SCORE ID NAME<br />

1 7 HP<br />

0.800000011920929 3 H.<br />

0.565685451030731 6 H.-P.<br />

Search two tok<strong>en</strong>s with abbreviationSimilarity<br />

SELECT SCORE() AS score, id, name FROM abbrev<br />

WHERE CONTAINS(name, 'Hans Peter',FUZZY(0.5,<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 283


'abbreviationSimilarity=0.80,textSearch=compare'))<br />

ORDER BY score DESC, id;<br />

SCORE ID NAME<br />

1 5 Hans-Peter<br />

0.800000011920929 6 H.-P.<br />

Search two tok<strong>en</strong>s with abbreviationSimilarity<br />

SELECT SCORE() AS score, id, name FROM abbrev<br />

WHERE CONTAINS(name, 'Go Gerd',FUZZY(0.5,<br />

'abbreviationSimilarity=0.80,textSearch=compare'))<br />

ORDER BY score DESC, id;<br />

SCORE ID NAME<br />

0.905538558959961 8 G Gerd<br />

Option minTextScore<br />

The minTextScore option allows you to set the score a text field has to reach to be a match.<br />

Note: If you use a fuzzySimilarity of 0.0, the parameter minTextScore will be redundant.<br />

DROP TABLE tab_mintextscore;<br />

CREATE COLUMN TABLE tab_mintextscore<br />

(<br />

id INTEGER PRIMARY KEY,<br />

t TEXT FAST PREPROCESS ON FUZZY SEARCH INDEX ON<br />

);<br />

INSERT INTO tab_mintextscore VALUES ('1','Bert');<br />

INSERT INTO tab_mintextscore VALUES ('2','Berta');<br />

INSERT INTO tab_mintextscore VALUES ('3','Bart');<br />

Search on a text column<br />

SELECT SCORE() AS score, id, t FROM tab_mintextscore<br />

WHERE CONTAINS(t, 'Ernie OR Bert', FUZZY(0.100, 'textSearch=compare,<br />

bestMatchingTok<strong>en</strong>Weight=0,minTextScore=0.70'))<br />

ORDER BY score DESC, id;<br />

SCORE ID T Description<br />

0.7 1 Bert


Option textSearch<br />

The textSearch option is used to select the search algorithm for TEXT columns:<br />

● textSearch=fulltext (default value): A full-text search is done on a TEXT column. IDF calculation or<br />

specialOrRanking (dep<strong>en</strong>ding on search flags) is used. This is the 'old' NewDB behavior.<br />

● textSearch=compare: A search similar to a Fuzzy Double search is done. Additional search options are<br />

<strong>en</strong>abled.<br />

Allowed search options and error handling<br />

Dep<strong>en</strong>ding on the data type of a column and the type of the search (freestyle or attribute search) of a query <strong>en</strong>try,<br />

some of the searchOptions parameters are not allowed because they do not make s<strong>en</strong>se.<br />

If the user sets an option that is not allowed, a SQL error is thrown and the SELECT aborts.<br />

textSearch=compar<br />

e<br />

FUZZY-Double-like<br />

search on TEXT<br />

attribute search and<br />

textSearch=<br />

compare and<br />

datatype= TEXT<br />

Full-text search on<br />

TEXT<br />

attribute search and<br />

textSearch= fulltext<br />

and datatype= TEXT<br />

Freestyle full-text<br />

search<br />

freestyle search and<br />

textSearch= fulltext<br />

YES n/a n/a NO<br />

textSearch=fulltext n/a YES n/a (default mode) NO<br />

similarCalculationM<br />

ode<br />

YES YES YES YES<br />

spellCheckFactor YES YES YES YES<br />

fuzzySimilarity > 0 YES YES YES YES<br />

fuzzySimilarity = 0 YES NO NO YES<br />

Search on types<br />

other than TEXT<br />

attribute search and<br />

datatype TEXT<br />

emptyScore YES NO NO YES (Only valid for<br />

abbreviationSimilarit<br />

y<br />

YES NO NO NO<br />

text, string and date<br />

types. Numeric<br />

types are not<br />

supported.)<br />

maxDateDistance NO NO YES YES (Only valid for<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

date types. Other<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 285


termMappingTable/<br />

ListId<br />

stopwordTable/<br />

ListId<br />

FUZZY-Double-like<br />

search on TEXT<br />

Full-text search on<br />

TEXT<br />

Freestyle full-text<br />

search<br />

YES YES YES NO<br />

YES NO NO NO<br />

andThreshold YES NO NO NO<br />

andSymmetric YES NO NO NO<br />

bestMatchingTok<strong>en</strong><br />

Weight<br />

considerNonMatchin<br />

gTok<strong>en</strong>s<br />

YES NO NO NO<br />

YES NO NO NO<br />

minTextScore YES NO NO NO<br />

Rank Calculation fuzzy score IDF IDF (TEXT) or fuzzy<br />

Leg<strong>en</strong>d<br />

YES - The parameter is allowed.<br />

score (other types)<br />

NO - The parameter is not allowed and an error message is returned if the user sets this option.<br />

Search on types<br />

other than TEXT<br />

types are not<br />

supported.)<br />

fuzzy score<br />

ignored - The parameter is ignored and no error message is returned to the user. This is necessary because the<br />

freestyler passes all search options to the g<strong>en</strong>erated search on single columns.<br />

Rank calculation<br />

Wh<strong>en</strong> 'fulltext' is specified, the search is done using IDF or specialOrRanking (dep<strong>en</strong>ding on the search flags). The<br />

fuzzy score is not calculated.<br />

Wh<strong>en</strong> 'compare' is specified, the fuzzy score is calculated using bestMatchingTok<strong>en</strong>Weight and<br />

considerNonMatchingTok<strong>en</strong>s. The user does not have to set these options. In this case, the default values are<br />

used.<br />

286<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Fuzzy Search with Stopwords<br />

Usage<br />

Stopwords are terms that are less significant for a search and are therefore not used to g<strong>en</strong>erate the result set. In<br />

other words, the search is carried out as if the stopwords are not pres<strong>en</strong>t (either in the user input or in the<br />

database column).<br />

However, stopwords influ<strong>en</strong>ce the score that is calculated. A record with stopwords id<strong>en</strong>tical to the user input<br />

gets a higher score than a record with differing or missing stopwords.<br />

Stopwords can be defined either as single terms or as stopword phrases consisting of multiple terms. Stopword<br />

phrases are only applied wh<strong>en</strong> all terms of the stopword appear in exactly the giv<strong>en</strong> order.<br />

Use case example: Wh<strong>en</strong> searching for company names, the legal form (Ltd, SA, AG, and so on) is less significant<br />

and less selective than the other parts of the name.<br />

Stopwords are stored in a column-store table with the following format:<br />

CREATE COLUMN TABLE mystopwords<br />

(<br />

stopword_id VARCHAR(32) PRIMARY KEY,<br />

list_id VARCHAR(32) NOT NULL,<br />

language_code CHAR(2),<br />

term NVARCHAR(200) NOT NULL<br />

);<br />

Stopwords are language dep<strong>en</strong>d<strong>en</strong>t. It is possible to define the language that a stopword is valid for. You can also<br />

define stopwords for all languages by not setting a language.<br />

(It makes s<strong>en</strong>se to add the language information now so that you can make use of the feature wh<strong>en</strong> it is available,<br />

without having to change the stopword definitions.)<br />

As with term mappings, stopwords can be grouped together in multiple groups. Groups of stopwords are<br />

id<strong>en</strong>tified by the value of the list_id column that is part of the stopword table.<br />

INSERT INTO mystopwords VALUES (1, 'legalform', '', 'Ltd');<br />

INSERT INTO mystopwords VALUES (2, 'legalform', 'de', 'GmbH');<br />

INSERT INTO mystopwords VALUES (3, 'legalform', 'de', 'Gesellschaft mit<br />

beschränkter Haftung');<br />

INSERT INTO mystopwords VALUES (4, 'legalform', 'de', 'AG');<br />

INSERT INTO mystopwords VALUES (5, 'legalform', 'de',<br />

'Akti<strong>en</strong>gesellschaft');<br />

To activate stopwords for a search on a TEXT column, you need to provide two search options (similar to the<br />

options used for term mappings):<br />

● stopwordListId=mylist1,mylist2,mylist3<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 287


● stopwordTable=[.]<br />

SELECT TO_DECIMAL(SCORE(),3,2) as score, company FROM mydata<br />

WHERE CONTAINS(company, 'xy gmbh', FUZZY(0.7, 'textsearch=compare,<br />

stopwordTable=MYSTOPWORDS, stopwordListId=legalform'))<br />

ORDER BY score DESC;<br />

To activate language-specific stopwords, you must provide the language parameter:<br />

SELECT TO_DECIMAL(SCORE(),3,2) as score, company FROM mydata<br />

WHERE CONTAINS(company, 'xy gmbh', FUZZY(0.7, 'textsearch=compare,<br />

stopwordTable=MYSTOPWORDS, stopwordListId=legalform'), language('de'))<br />

ORDER BY score DESC;<br />

Note: In this case, all stopwords where language_code is set to 'de' or empty will be used. Any stopwords<br />

with other language codes will be ignored.<br />

Stopwords are removed from the search term first. In this example, the result set of the search is the same as for<br />

the search '... WHERE CONTAINS(company, 'xy', ...'.<br />

Wh<strong>en</strong> calculating the score, the fuzzy scores of the non-stopword terms have the biggest influ<strong>en</strong>ce on the<br />

resulting score. Stopwords in the user input and in the database records are also giv<strong>en</strong> less weight than the non-<br />

stopword terms, so records with matching stopwords get a higher score than records with differing or missing<br />

stopwords.<br />

The result of the above example is as follows:<br />

Score Company Comm<strong>en</strong>t<br />

1.00 XY GmbH<br />

0.95 XY Missing stopword<br />

0.95 XY Akti<strong>en</strong>gesellschaft Differing stopword<br />

0.92 XY Gesellschaft mit beschränkter<br />

Haftung<br />

Many differing stopwords<br />

0.78 XY Company Additional non-matching term, no<br />

stopword<br />

The value giv<strong>en</strong> for stopwordTable can be any valid SQL id<strong>en</strong>tifier as defined in the SQL refer<strong>en</strong>ce manual. If<br />

schema is omitted, the curr<strong>en</strong>t schema is used. The following examples all refer<strong>en</strong>ce the same stopword table.<br />

SET SCHEMA schema1;<br />

SELECT ... WHERE CONTAINS(c, 'xy', FUZZY(0.7,<br />

'stopwordTable=schema1.mystopwords, ...'))...;<br />

SELECT ... WHERE CONTAINS(c, 'xy', FUZZY(0.7,<br />

'stopwordTable="SCHEMA1"."MYSTOPWORDS", ...'))...;<br />

SELECT ... WHERE CONTAINS(c, 'xy', FUZZY(0.7,<br />

'stopwordTable=mystopwords, ...'))...;<br />

288<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Stopword Example<br />

CREATE COLUMN TABLE stopwords<br />

(<br />

stopword_id VARCHAR(32) PRIMARY KEY,<br />

list_id VARCHAR(32) NOT NULL,<br />

language_code CHAR(2) NOT NULL,<br />

term NVARCHAR(200) NOT NULL<br />

);<br />

CREATE COLUMN TABLE companies<br />

(<br />

id INTEGER PRIMARY KEY,<br />

companyname SHORTTEXT(200) FUZZY SEARCH INDEX ON<br />

);<br />

INSERT INTO companies VALUES ('1', 'SAP AG');<br />

INSERT INTO companies VALUES ('2', 'SAP Akti<strong>en</strong>gesellschaft');<br />

INSERT INTO stopwords VALUES ('1', '01', 'de', 'AG');<br />

INSERT INTO stopwords VALUES ('2', '01', 'de', 'Akti<strong>en</strong>gesellschaft');<br />

INSERT INTO stopwords VALUES ('3', '01', 'de', 'blub');<br />

Query 1: User input without stopwords. Stopwords in the database table only.<br />

SELECT TO_DECIMAL(SCORE(), 3, 2) AS score, *<br />

FROM companies<br />

WHERE CONTAINS(companyname, 'sap', FUZZY(0.8, 'stopwordTable=stopwords,<br />

stopwordListId=01, textSearch=compare'))<br />

ORDER BY score DESC, ID;<br />

SCORE ID COMPANYNAME<br />

0.95 1 SAP AG<br />

0.95 2 SAP Akti<strong>en</strong>gesellschaft<br />

Query 2: User input with stopword. Other stopwords in the database table.<br />

SELECT TO_DECIMAL(SCORE(), 3, 2) AS score, *<br />

FROM companies<br />

WHERE CONTAINS (companyname, 'sap blub', FUZZY(0.8,<br />

'stopwordTable=stopwords, stopwordListId=01, textSearch=compare'))<br />

ORDER BY score DESC, ID;<br />

SCORE ID COMPANYNAME<br />

0.95 1 SAP AG<br />

0.95 2 SAP Akti<strong>en</strong>gesellschaft<br />

Query 3: User input with stopword. One record with matching stopword, one record with differing stopword.<br />

SELECT TO_DECIMAL(SCORE(), 3, 2) AS score, *<br />

FROM companies<br />

WHERE CONTAINS (companyname, 'sap akti<strong>en</strong>gesellschaft', FUZZY(0.8,<br />

'stopwordTable=stopwords, stopwordListId=01, textSearch=compare'))<br />

ORDER BY score DESC, ID;<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 289


SCORE ID COMPANYNAME<br />

1 2 SAP Akti<strong>en</strong>gesellschaft<br />

0.95 1 SAP AG<br />

Query 4: User input with two stopwords. Database records with one matching stopword.<br />

SELECT TO_DECIMAL(SCORE(), 3, 2) AS score, *<br />

FROM companies<br />

WHERE CONTAINS (companyname, 'sap ag akti<strong>en</strong>gesellschaft', FUZZY(0.8,<br />

'stopwordTable=stopwords, stopwordListId=01, textSearch=compare'))<br />

ORDER BY score DESC, ID;<br />

SCORE ID COMPANYNAME<br />

0.97 1 SAP AG<br />

0.97 2 SAP Akti<strong>en</strong>gesellschaft<br />

Stopwords Combined With Term Mappings<br />

Wh<strong>en</strong> stopwords and term mappings are combined in a single query, term mappings are applied first. Stopwords<br />

are th<strong>en</strong> applied to all variations of the search term created by the term mappings.<br />

Example<br />

Let us assume that you have defined the following term mapping:<br />

Term 1 Term 2<br />

Incredible Busy Machines IBM<br />

Ltd Limited<br />

Now you search for "Incredible Busy Machines Ltd".<br />

The search would be carried out for all possible search terms:<br />

Search Terms<br />

Incredible Busy Machines Ltd<br />

Incredible Busy Machines Limited<br />

IBM Ltd<br />

IBM Limited<br />

Let us assume that you have defined the following stopwords:<br />

Stopword<br />

busy machines<br />

290<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Stopword<br />

ltd<br />

The stopwords will not be searched, so the resulting search terms would be:<br />

Search Terms<br />

Incredible Busy Machines Ltd<br />

Incredible Busy Machines Limited<br />

IBM Ltd<br />

IBM Limited<br />

Fuzzy Search with Term Mappings<br />

Facts About Term Mappings<br />

Term mappings have the following characteristics:<br />

● Term mappings can be used to ext<strong>en</strong>d the search by adding additional search terms to the user input.<br />

Wh<strong>en</strong>ever the user <strong>en</strong>ters a search term, the search term is expanded and synonyms, hypernyms, hyponyms,<br />

and so on are added. The result that is returned to the user contains additional records or docum<strong>en</strong>ts related<br />

to the search term that may be useful to the user.<br />

● Term mappings are defined in a column table and can be changed at any time.<br />

The curr<strong>en</strong>t term-mapping definition is applied wh<strong>en</strong> a search is started. The definition of term mappings<br />

does not change the data that is stored in the database tables (in contrast to the definition of synonyms in<br />

Text Analysis, where a change of synonyms requires a reload or reindexing of the text data).<br />

● Term mappings can be grouped.<br />

Each group of term mappings is id<strong>en</strong>tified by a list_id that is stored in the term-mapping table. By grouping<br />

term mappings it is possible to apply differ<strong>en</strong>t sets of term mappings to differ<strong>en</strong>t columns of a table. For<br />

example, you may want to use some term mappings wh<strong>en</strong> searching company names and other term<br />

mappings wh<strong>en</strong> searching docum<strong>en</strong>ts. Wh<strong>en</strong> starting a search, it is possible to specify the term-mapping<br />

list_ids that shall be applied to each column.<br />

● Term mappings can be assigned a weight.<br />

In this case, records that are found because of a term mapping will get a lower score than records found with<br />

the original user input. From the user's view, the result list is sorted in a more useful way.<br />

● Term mappings are defined as a unidirectional replacem<strong>en</strong>t.<br />

For a term-mapping definition of 'term1' -> 'term2', 'term1' is replaced with 'term2', but 'term2' is not replaced<br />

with 'term1'. This is helpful if you want a search with a hypernym to find all hyponyms, but not the other way<br />

round. If a bidirectional replacem<strong>en</strong>t is needed (as for synonyms), both directions have to be added to the<br />

term-mapping table.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 291


● Term mappings are language dep<strong>en</strong>d<strong>en</strong>t.<br />

It is possible to define the language that a term mapping is valid for. You can also define term mappings for all<br />

languages by not setting a language.<br />

Use Cases<br />

Synonyms<br />

If you have a large database of company names, you might want to map the companies' legal forms.<br />

For example:<br />

Searching for You would also like to find With a weight of<br />

AG Akti<strong>en</strong>gesellschaft 1.0<br />

Ltd Limited 1.0<br />

As these are synonyms, the term mappings have to be added to the term-mapping table in both directions, as<br />

shown in the example below.<br />

Usually, synonym definitions get a weight of 1.0, because records found wh<strong>en</strong> the term mapping is applied are as<br />

good as records found with the original user input.<br />

Hypernyms, Hyponyms<br />

If you search with a hypernym, you might also find other docum<strong>en</strong>ts related to this topic.<br />

For example:<br />

Searching for You would also like to find With a weight of<br />

car VW Golf 0.8<br />

As these are not synonyms, and a search with 'VW Golf' shall not return all docum<strong>en</strong>ts about cars, the term<br />

mapping is added to the term-mapping table in this direction only.<br />

Format of the Term-Mapping Table<br />

Column Name Type Primary Key Description Comm<strong>en</strong>t<br />

MAPPING_ID VARCHAR(32) x Primary key For example, a GUID<br />

LIST_ID VARCHAR(32) Term-mapping list ID Used to group term<br />

LANGUAGE_CODE CHAR(2) Language code<br />

292<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

(ISO2)<br />

mappings<br />

NULL: term mapping<br />

is valid for all<br />

languages<br />

SAP HANA Developer Guide<br />

Enabling Search


Column Name Type Primary Key Description Comm<strong>en</strong>t<br />

TERM_1 NVARCHAR(200) Term 1, the term to<br />

be replaced<br />

TERM_2 NVARCHAR(200) Term 2, the term<br />

that replaces term 1<br />

WEIGHT DECIMAL Weight, 0.0


FUZZY(0.8,<br />

'termMappingTable=termmappings,termMappingListId=01,textSearch=compare'))<br />

ORDER BY score DESC, id;<br />

SCORE ID COMPANYNAME<br />

1.0 2 SAP Akti<strong>en</strong>gesellschaft<br />

0.9 1 SAP AG<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM companies<br />

WHERE CONTAINS(companyname, 'sap ag',<br />

FUZZY(0.8,'termMappingTable=TERMMAPPINGS,termMappingListId=01,textSearch=co<br />

mpare'))<br />

ORDER BY score DESC, id;<br />

SCORE ID COMPANYNAME<br />

1.0 1 SAP AG<br />

0.9 2 SAP Akti<strong>en</strong>gesellschaft<br />

To activate language-specific term mappings, you must provide the language parameter:<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM companies<br />

WHERE CONTAINS(companyname, 'sap ag',<br />

FUZZY(0.8,'termMappingTable=TERMMAPPINGS,termMappingListId=01,textSearch=co<br />

mpare'), language('de'))<br />

ORDER BY score DESC, id;<br />

Note: In this case, all term mappings where language_code is set to 'de' or empty will be used. Any term<br />

mappings with other language codes will be ignored.<br />

Fuzzy Search on DATE Columns<br />

A fuzzy search on DATE columns supports two types of error:<br />

● Date-specific typos<br />

● Dates lying within a user-defined maximum distance<br />

Score Calculation for Typos<br />

Instead of using Lev<strong>en</strong>shtein distance or other string-compare algorithms, the following date-specific typos and<br />

errors are defined as similar:<br />

1. One wrong digit at any position (for example, 2011-08-15 instead of 2011-08-25). This type of error gets a<br />

score of 0.90.<br />

2. Two digits interchanged within one compon<strong>en</strong>t (day, month, or year) (for example, 2001-01-12, 2010-10-12, or<br />

2010-01-21 instead of 2010-01-12). This type of error gets a score of 0.85.<br />

3. Month and day interchanged (US versus European date format) (for example, 2010-10-12 instead of<br />

294<br />

2010-12-10). This type of error gets a score of 0.80.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Only one of these errors is allowed. Dates with more than one error are not considered similar, so the score is 0.0.<br />

Dates with a score less than the fuzzySimilarity parameter are not returned.<br />

Example:<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM dates<br />

WHERE CONTAINS(dateofbirth, '2000-01-10', FUZZY(0.8))<br />

ORDER BY score DESC;<br />

For this example we get:<br />

2000-01-09 -> 0.00 (not returned to the user)<br />

2000-01-10 -> 1.00<br />

2000-01-11 -> 0.90<br />

2000-01-12 -> 0.90<br />

...<br />

2000-01-21 -> 0.00 (not returned to the user)<br />

...<br />

2000-10-01 -> 0.80<br />

Score Calculation for Date Distance<br />

The maximum allowed distance betwe<strong>en</strong> dates can be defined using the search option 'maxDateDistance', which<br />

defines a number of days.<br />

The default for this option is 0, that is, the feature is disabled. This is shown in the following example:<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM dates<br />

WHERE CONTAINS(dateofbirth, '2000-01-10', FUZZY(0.95, 'maxDateDistance=5'))<br />

ORDER BY score DESC;<br />

This query returns all dates betwe<strong>en</strong> 2000-01-05 and 2000-01-15.<br />

The fuzzy score for dates is calculated as follows:<br />

The id<strong>en</strong>tical date gets a score of 1.0.<br />

The date that is maxDateDistance days away from the search input gets a score that equals the fuzzySimilarity<br />

parameter (0.95 in the example above).<br />

The score of dates betwe<strong>en</strong> the id<strong>en</strong>tical date and maxDateDistance is calculated as a linear function betwe<strong>en</strong> the<br />

two dates defined above. In other words, for each day the score is reduced by ((1-fuzzySimilarity) /<br />

maxDateDistance).<br />

For dates outside the range of maxDateDistance, the score is 0.0.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 295


Therefore, for the example above we get:<br />

2000-01-04 -> 0.00<br />

2000-01-05 -> 0.95<br />

2000-01-06 -> 0.96<br />

...<br />

2000-01-09 -> 0.99<br />

2000-01-10 -> 1.0<br />

2000-01-11 -> 0.99<br />

2000-01-12 -> 0.98<br />

...<br />

2000-01-15 -> 0.95<br />

2000-01-16 -> 0.00<br />

The distance betwe<strong>en</strong> dates is calculated following the rules of the Gregorian cal<strong>en</strong>dar.<br />

The special case 'fuzzySimilarity = 1.0' and maxDateDistance=n is allowed and returns all dates within a range of n<br />

days with a rank of 1.0.<br />

Dates That Meet Both Conditions<br />

If a date meets the conditions of a typo and also the conditions of the maxDateDistance parameter, two scores<br />

are calculated for the same date. In this case, the score() function returns the highest of both scores. This is<br />

shown in the following example:<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM dates<br />

WHERE CONTAINS(dateofbirth, '2000-01-10', FUZZY(0.8, 'maxDateDistance=5'))<br />

ORDER BY score DESC;<br />

This query returns the following:<br />

2000-01-04 -> 0.00<br />

2000-01-05 -> 0.80<br />

2000-01-06 -> 0.84<br />

2000-01-07 -> 0.88<br />

2000-01-08 -> 0.92<br />

2000-01-09 -> 0.96<br />

2000-01-10 -> 1.0<br />

296<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


2000-01-11 -> 0.96<br />

2000-01-12 -> 0.92<br />

2000-01-13 -> 0.90<br />

2000-01-14 -> 0.90<br />

2000-01-15 -> 0.90<br />

2000-01-16 -> 0.90<br />

Search Rules<br />

Overview<br />

With fuzzy search in SAP HANA, you can search for structured database cont<strong>en</strong>t that is similar to the user input.<br />

In this case, the user input and the records in the database are nearly the same but differ in their spelling (for<br />

example, typing errors) or contain additional information (for example, additional or missing terms).<br />

Among the use cases of fuzzy search on structured data, there is the prev<strong>en</strong>tion of duplicate records. New<br />

database records can be checked for similar and already existing records in real time, just before the new record<br />

is saved.<br />

For example, before saving a new customer to the database, the application checks for similar customers that<br />

may be duplicates of the newly <strong>en</strong>tered customer. The application does some searches and th<strong>en</strong> pres<strong>en</strong>ts to the<br />

user any existing customers that are similar to the user input. The user th<strong>en</strong> decides whether to create a new<br />

customer (because the records pres<strong>en</strong>ted are similar, but not really duplicates) or to accept one of the existing<br />

customers and continue with this customer record.<br />

The searches performed by the application are defined by business rules that define wh<strong>en</strong> two customers are<br />

similar. For example, two customers may be considered similar by the application as soon as one of the following<br />

conditions is true:<br />

1. The customers' names and addresses are similar.<br />

2. The customers' last names and addresses are id<strong>en</strong>tical but the first names are differ<strong>en</strong>t (may be persons<br />

living in the same household).<br />

3. The customers' names are similar and the dates of birth are id<strong>en</strong>tical.<br />

These rules can be hardcoded in the application by writing three SELECT statem<strong>en</strong>ts that do the three searches<br />

defined above. Wh<strong>en</strong>ever the requirem<strong>en</strong>ts for the search rules change, the application code has to be changed,<br />

tested and deployed to the productive system. This may be costly in terms of time and <strong>dev</strong>elopm<strong>en</strong>t resources<br />

needed.<br />

Alternatively, the application can use search rules to store the rules as a configuration object in the SAP HANA<br />

database. Instead of embedding the rules in SELECT statem<strong>en</strong>ts that are part of the application code, the<br />

application has to call a database procedure only to process all rules defined in the configuration object.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 297


Wh<strong>en</strong> the business requirem<strong>en</strong>ts change, only the search rule definition in the configuration object has to be<br />

changed, tested, and deployed. The interface to the database procedure that is called by the application stays<br />

unchanged. So without any change to the application code, the definition of the search rules is changed and the<br />

user immediately gets search results according to the new requirem<strong>en</strong>ts. This results in much less effort and<br />

more flexibility wh<strong>en</strong> changing search rules.<br />

Supported Database Objects<br />

You can search on attribute views. The views have to be modeled using the SAP HANA studio and have to be<br />

stored as objects in the SAP HANA repository.<br />

Other database objects, such as row tables, column tables, calculation views, or analytic views, are not supported.<br />

Important Terms<br />

A search rule set is the configuration object that is stored in the SAP HANA repository and that contains the<br />

definition of the search rules. Wh<strong>en</strong> the database procedure is called to do a search, a search rule set is executed.<br />

This means that all rules that are defined in the search rule set are executed.<br />

A search rule defines a condition wh<strong>en</strong> two records – the user input and a record in the database – are<br />

considered similar. Each rule in a search rule set is converted to a SELECT statem<strong>en</strong>t and is executed wh<strong>en</strong> the<br />

search rule set is processed.<br />

Creating Search Rule Sets<br />

You created a workspace and a project in the SAP HANA studio. In this workspace, you created a package that will<br />

contain your rule set.<br />

1. In the SAP HANA modeler, op<strong>en</strong> the Project Explorer view and navigate to your package.<br />

2. From the context m<strong>en</strong>u of your package, select New Other Search Rule Set .<br />

3. Enter a file name for your rule set. The file has to have the ext<strong>en</strong>sion .searchruleset.<br />

4. Op<strong>en</strong> and edit the search rule set in the search rule set editor. See Working with the Search Rule Set Editor<br />

[page 298]<br />

5. Define the attribute view, key columns, score selection parameter, stopwords, and term mappings. See<br />

Configuring Search Rule Sets [page 299]<br />

6. From the context m<strong>en</strong>u of your package or search rule, choose Team Activate .<br />

You can now execute a search with the rule set. See Executing a Search With a Rule Set [page 300]<br />

Working with the Search Rule Set Editor<br />

● To op<strong>en</strong> a rule set in the editor, double-click a rule set file or, from the context m<strong>en</strong>u, select Op<strong>en</strong> With<br />

Search Rule Set Editor .<br />

● To add new nodes, childr<strong>en</strong> or siblings, you can use the context m<strong>en</strong>u of each node.<br />

For example, you can a new key column node in the following ways:<br />

○ Select the attribute view node and, in the context m<strong>en</strong>u, choose New Key Column.<br />

○ Select a key column node and, in the context m<strong>en</strong>u, choose New Key Column.<br />

● To delete a node from the search rule set, select the node and, from the context m<strong>en</strong>u, select Delete.<br />

298<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


This deletes the node and all its child nodes.<br />

● To change the order of nodes or to move nodes to other par<strong>en</strong>t nodes, you can drag and drop the nodes.<br />

With the SAP HANA studio running on Microsoft Windows, you can copy nodes below the same par<strong>en</strong>t node<br />

or ev<strong>en</strong> to another par<strong>en</strong>t node by pressing CTRL while dragging.<br />

● To change properties, click on the value of the property in the Properties view and <strong>en</strong>ter the new value.<br />

Each node contains a set of properties that define the behavior of the search rules. Node properties are<br />

displayed in the Properties view of the SAP HANA studio wh<strong>en</strong> a node is selected in the tree. If the Properties<br />

view is not displayed, you can op<strong>en</strong> it by choosing Window Show View Properties .<br />

Note: Some node properties refer to database objects or to column names. These properties are<br />

case-s<strong>en</strong>sitive so you have to <strong>en</strong>ter all names in the correct notation.<br />

Configuring Search Rule Sets<br />

● Define the attribute view.<br />

The search rule set searches on an attribute view that is modeled using the SAP HANA studio. The attribute<br />

view to be used is defined in the attribute view node of the search rule set. The name property contains the<br />

name of the attribute view. The FQN notation (fully qualified name) is used to specify the view.<br />

● Define the key columns and the score selection parameter.<br />

A search may return the same record more than once because it matches more than one rule.<br />

To <strong>en</strong>able the search to return each record only once, key columns must be defined in a way that makes<br />

records in the result set unique. For an attribute view, there is no definition of key columns available, so the<br />

key columns have to be defined for each search rule set.<br />

The key columns are a set of one or more columns of the attribute view that clearly id<strong>en</strong>tify a record in the<br />

view. So the key columns are similar to the primary key columns of a database table.<br />

As for primary keys, LOB types (BLOB, CLOB, NCLOB, TEXT) are not allowed as key columns.<br />

Note: It is possible to create an invalid key column definition that does not make the result set unique.<br />

In this case, wh<strong>en</strong> running a search, an error is raised wh<strong>en</strong> records returned by a single rule are not<br />

unique.<br />

By default, each search rule set contains one key column node below the attribute view node. If more columns<br />

are needed to make records unique, more key column nodes can be added below the attribute view node.<br />

In each key column node <strong>en</strong>ter the name of the attribute view column in the properties panel.<br />

In addition to the key columns, you have to define how the result set shall be made unique. Records returned<br />

by more than one rule usually have differ<strong>en</strong>t scores assigned. Only one combination of score and rule name<br />

can be returned in the result set.<br />

The score selection parameter defines whether the values with the highest score or the values found with the<br />

first matching rule are returned.<br />

The score selection parameter is defined in the properties panel of the rule set node.<br />

● Define stopwords and term mappings.<br />

To use stopwords and term mappings in a search rule set, the configuration options have to be added to the<br />

rule set.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 299


First, op<strong>en</strong> the context m<strong>en</strong>u of the Search Rule Set node and select New Stopwords (table-based) or New<br />

Term Mappings (table based).<br />

In the properties of the new nodes, you can define the stopword table and term mapping table that is used.<br />

On the Stopwords (table-based) or Term Mappings (table-based) node, select New Column to <strong>en</strong>able the<br />

stopwords or term mappings on a column. In the properties panel, you can define the name of the column<br />

where stopwords and term mappings shall be applied.<br />

Below the Column nodes, create new List ID nodes (op<strong>en</strong> the context m<strong>en</strong>u and select New List ID). In each<br />

list ID node, you can configure a stopword or term mapping list that is applied on the column.<br />

The stopword and term mapping settings are valid for a giv<strong>en</strong> column in all rules.<br />

Executing a Search With a Rule Set<br />

HANA exports a new built-in function: SYS.EXECUTE_SEARCH_RULE_SET, with which you can execute a<br />

previously defined search rule set.<br />

The function has one parameter, which is an XML string to run the search. Within this XML, you have to specify:<br />

● The ruleset that should be executed<br />

● The way the result will be returned<br />

● The limitation of the result<br />

● The input values<br />

The EXECUTE_SEARCH_RULE_SET method returns by default a ResultSet object. This object contains all the<br />

columns from the refer<strong>en</strong>ced attribute view plus additional columns _SCORE and _RULE_ID. Alternatively, the<br />

EXECUTE_SEARCH_RULE_SET can write the result into a results table that needs to be created by the user.<br />

For code samples of SYS.EXECUTE_SEARCH_RULE_SET calls, see Search with a Rule Set - Code Samples [page<br />

300].<br />

Transaction Isolation Level<br />

The EXECUTE_SEARCH_RULE_SET function creates one SELECT statem<strong>en</strong>t for each of the rules and runs the<br />

statem<strong>en</strong>ts indep<strong>en</strong>d<strong>en</strong>t of each other. The statem<strong>en</strong>ts are executed in the transaction context of the calling<br />

application and use the same isolation level as the application. The isolation level has an influ<strong>en</strong>ce on the results of<br />

the EXECUTE_SEARCH_RULE_SET function wh<strong>en</strong> there are other transactions running in parallel that change the<br />

cont<strong>en</strong>ts of the database tables.<br />

Wh<strong>en</strong> the isolation level 'READ COMMITTED' is used, each of the SELECT statem<strong>en</strong>ts of the search rule set sees<br />

all changes that have be<strong>en</strong> committed at the time the execution of the SELECT statem<strong>en</strong>t begins. So, for example,<br />

the second rule of a rule set may see a new record that was not committed wh<strong>en</strong> the first rule has be<strong>en</strong> executed.<br />

In this case, the new record may be returned by the 'wrong' rule and the user gets an incorrect result.<br />

Wh<strong>en</strong> the isolation levels 'REPEATABLE READ' or 'SERIALIZABLE' are used, all SELECT statem<strong>en</strong>ts see the same<br />

state of the database. So the results returned by EXECUTE_SEARCH_RULE_SET are always correct.<br />

Search with a Rule Set - Code Samples<br />

Executing a search and returning the result as a ResultSet:<br />

CALL SYS.EXECUTE_SEARCH_RULE_SET('<br />

<br />

<br />

-- specifies the SearchRuleSet<br />

Herbert -- specifies the input value<br />

for column FIRSTNAME<br />

300<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Hofmann -- specifies the input value<br />

for column LASTNAME<br />

<br />

');<br />

Executing a search and writing the result to a column table provided by the user:<br />

--First create the result table<br />

set schema MY_SCHEMA;<br />

CREATE COLUMN TABLE MY_RESULT_TABLE (<br />

_SCORE FLOAT,<br />

_RULE_ID VARCHAR(255),<br />

"FIRSTNAME" TEXT FUZZY SEARCH INDEX ON FAST PREPROCESS ON,<br />

"LASTNAME" TEXT FUZZY SEARCH INDEX ON FAST PREPROCESS ON<br />

};<br />

-- Afterwards you can execute the search using the created result table.<br />

CALL SYS.EXECUTE_SEARCH_RULE_SET('<br />

<br />

<br />

-- specifies the SearchRuleSet<br />

-- specifies the schema of<br />

the result table<br />

-- specifies the name of the<br />

result table<br />

Herbert -- specifies the input value<br />

for column FIRSTNAME<br />

Hofmann -- specifies the input value<br />

for column LASTNAME<br />

<br />

');<br />

-- get the result<br />

select * from MY_RESULT_TABLE;<br />

Limiting the number of rows returned by a search:<br />

Note: Wh<strong>en</strong> calling the system procedure EXECUTE_SEARCH_RULE_SET, the application can define the<br />

maximum number of rows that are returned by setting a limit parameter. By default, this parameter is<br />

undefined, which means that an unlimited number of rows is returned. The limitation takes place after<br />

each rule and in the <strong>en</strong>d wh<strong>en</strong> all rules are performed. In the following example, a maximum number of<br />

100 rows will be returned. You can use this parameter with the ResultSet object and with the custom<br />

result table.<br />

-- run the search<br />

CALL SYS.EXECUTE_SEARCH_RULE_SET('<br />

<br />

<br />

billy<br />

smith<br />

<br />

');<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 301


Frequ<strong>en</strong>tly Asked Questions<br />

Why are there results with a score lower than the requested fuzzySimilarity?<br />

In text fields, the parameter fuzzySimilarity sets the minimum similarity that a tok<strong>en</strong> has to match to be included<br />

in the search result. All other fuzzy search operations (for example, applying term mappings, considering<br />

stopwords, abbreviationSimilarity) can influ<strong>en</strong>ce the score that you will see.<br />

How many misspellings are allowed with a particular fuzzySimilarity?<br />

This question is not easy to answer. The scoring algorithm is not linear to the number of misspellings; the position<br />

of the misspelling is also important. You can use the following example to familiarize yourself with it.<br />

DROP TABLE test;<br />

CREATE COLUMN TABLE test<br />

(<br />

id INTEGER PRIMARY KEY,<br />

companyname SHORTTEXT(200) FUZZY SEARCH INDEX ON<br />

);<br />

INSERT INTO test VALUES ('1','abc');<br />

INSERT INTO test VALUES ('2','abx');<br />

INSERT INTO test VALUES ('3','xbc');<br />

INSERT INTO test VALUES ('4','axc');<br />

INSERT INTO test VALUES ('5','abcx');<br />

INSERT INTO test VALUES ('6','xabc');<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM test<br />

WHERE CONTAINS(companyname, 'abc',<br />

FUZZY(0.5,'textSearch=compare,bestMatchingTok<strong>en</strong>Weight=1'))<br />

ORDER BY score DESC, id;<br />

SCORE ID COMPANYNAME<br />

1 1 abc<br />

0.89 5 abcx<br />

0.82 2 abx<br />

0.75 6 xabc<br />

0.61 3 xbc<br />

0.61 4 axc<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, * FROM test<br />

WHERE CONTAINS(companyname, 'abcx',<br />

FUZZY(0.5,'textSearch=compare,bestMatchingTok<strong>en</strong>Weight=1'))<br />

ORDER BY score DESC, id;<br />

SCORE ID COMPANYNAME<br />

1 5 abcx<br />

0.89 1 abc<br />

302<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


SCORE ID COMPANYNAME<br />

0.88 6 xabc<br />

0.75 3 abx<br />

0.59 3 xbc<br />

0.59 4 axc<br />

How do I find out if the fuzzy search index is <strong>en</strong>abled for column x?<br />

See Basic Examples.<br />

How do I <strong>en</strong>able the fuzzy search index for a particular column?<br />

See Basic Examples.<br />

The additional data structures will increase the total memory footprint of the loaded table. In unfavorable cases<br />

the memory footprint of the column can double.<br />

How can I see how much memory is used for a fuzzy search index?<br />

See Memory Usage [page 263].<br />

Is the score betwe<strong>en</strong> request and result always stable for TEXT columns?<br />

It dep<strong>en</strong>ds on how you look at the topic. The algorithm is indeed deterministic, but you need to take all parameters<br />

into account. Cases can be constructed where a small change in the fuzzySimilarity will change the rank betwe<strong>en</strong><br />

the same strings.<br />

Why is this? The fuzzySimilarity is the minimum score that tok<strong>en</strong>s need to reach to be considered for the result. If<br />

you use andThreshold or the keyword "OR" in your search, not all tok<strong>en</strong>s have to reach the fuzzySimilarity to be<br />

part of the result. This can lead to a change in the total score if you change the fuzzySimilarity. Let us look at an<br />

example:<br />

DROP TABLE companies;<br />

CREATE COLUMN TABLE companies<br />

(<br />

id INTEGER PRIMARY KEY,<br />

companyname SHORTTEXT(200)<br />

);<br />

INSERT INTO companies VALUES(1, 'akti<strong>en</strong> gesellschaft');<br />

INSERT INTO companies VALUES(2, 'aktiv gesellschaft');<br />

Important: The similarity betwe<strong>en</strong> "akti<strong>en</strong>" and "aktiv" is 0.77.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 303


If the fuzzySimilarity is lower than 0.77, the tok<strong>en</strong> scoring will be part of the result score. If the fuzzySimilarity is<br />

higher than 0.77, the tok<strong>en</strong> scoring will not be considered, so the total scoring will be lower.<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, id, companyname<br />

FROM companies<br />

WHERE CONTAINS(companyname, 'aktiv OR gesellschaft', FUZZY(0.75,<br />

'textSearch=compare'))<br />

ORDER BY score DESC, id;<br />

SCORE ID COMPANYNAME<br />

1 2 aktiv gesellschaft<br />

0.89 1 akti<strong>en</strong> gesellschaft<br />

SELECT TO_DECIMAL(SCORE(),3,2) AS score, id, companyname<br />

FROM companies<br />

WHERE CONTAINS(companyname, 'aktiv OR gesellschaft', FUZZY(0.80,<br />

'textSearch=compare'))<br />

ORDER BY score DESC, id;<br />

SCORE ID COMPANYNAME<br />

1 2 aktiv gesellschaft<br />

0.71 1 akti<strong>en</strong> gesellschaft<br />

11.3 Building Search Apps<br />

11.3.1 Introduction to the UI Toolkit for Info Access<br />

The UI toolkit for SAP HANA Info Access provides UI building blocks for <strong>dev</strong>eloping browser-based search apps on<br />

SAP HANA. Such applications provide real-time information access and faceted search features for huge volumes<br />

of structured and unstructured text data.<br />

The toolkit <strong>en</strong>ables a freestyle search of a SAP HANA attribute view, displaying and analyzing the result set. The<br />

toolkit provides UI elem<strong>en</strong>ts (widgets) such as a search box, a result list with a detailed view, and charts for basic<br />

analytics on the result set. The widgets are interconnected and adapt in real-time to user <strong>en</strong>tries and mouse-over<br />

(hover) selections.<br />

The toolkit is based on HTML5 and JavaScript libraries such as JQuery/JQueryUI, d3 (Data Driv<strong>en</strong> Docum<strong>en</strong>ts),<br />

and Tempo. The widgets use the SAP HANA Info Access HTTP service. You do not need an additional layer to run<br />

the UI; SAP HANA and a Web browser are suffici<strong>en</strong>t. The toolkit is tested on Mozilla Firefox 17. It also runs on<br />

Microsoft Internet Explorer 9 in standard mode and Google Chrome.<br />

Along with the actual toolkit (the widgets), we deliver a fully operational demo Web app built using this toolkit. The<br />

demo app <strong>en</strong>ables you to explore a search application dealing with a set of sample data for electronic products.<br />

You can use the demo app as a template or for refer<strong>en</strong>ce wh<strong>en</strong> you start <strong>dev</strong>eloping your own app.<br />

You can, for example, use the demo site to easily connect your own data and compose your Web site. To create a<br />

search application this way, it is suffici<strong>en</strong>t to have experi<strong>en</strong>ce in HTML and to have read this docum<strong>en</strong>tation. For<br />

304<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


advanced customizing and layout of the site, more in-depth knowledge of CSS and the above-m<strong>en</strong>tioned<br />

JavaScript libraries is required.<br />

What is the SAP HANA Info Access HTTP Service?<br />

In the first place, SAP HANA is a database. It stores any type of raw data in its tables: master data, transactional<br />

data, numbers, texts, and so on. But SAP HANA can do more than a classic database. SAP HANA also <strong>en</strong>ables you<br />

to turn raw data into meaningful information.<br />

For the world of numbers, there are the analytics features of SAP HANA. By joining, aggregating, and calculating,<br />

they can turn raw facts and numbers into meaningful measures and key figures.<br />

For the world of texts, there are the full text search and text analysis features of SAP HANA. By tok<strong>en</strong>izing,<br />

stemming, normalizing, and analyzing semantically, they can turn a set of strings into a structured and searchable<br />

text corpus.<br />

So there is meaningful information in SAP HANA. But it is still not instantly available to business <strong>en</strong>d users. SQL is<br />

a very powerful tool for accessing and processing SAP HANA information. However, it operates on a very<br />

technical level deep down in the stack and far from an <strong>en</strong>d user UI.<br />

This is where the info access service of SAP HANA steps in. As long as you only need read-access, meaning<br />

search or basic analytics, the service provides shortcuts to Web and mobile UIs.<br />

SAP HANA Info Access Architecture<br />

The SAP HANA info access HTTP service wraps search and analytic SQL queries and exposes them through an<br />

HTTP interface. On the UI layer, Info Access offers the HTML5 <strong>dev</strong>elopm<strong>en</strong>t kit including UI widgets and Web site<br />

templates. No intermediate layer is required. To provide Info Access apps to your users, you only need SAP HANA<br />

and a Web browser.<br />

11.3.2 Installing the Service and the Toolkit<br />

The UI toolkit and the service are part of the default SAP HANA shipm<strong>en</strong>t, but they are not installed automatically.<br />

They are shipped as separate delivery units that you can import and activate quickly as described below.<br />

Importing the Delivery Units<br />

● SAP HANA Appliance Software, support package stack (SPS) 05 or higher, running on a server.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 305


● SAP HANA studio and SAP HANA cli<strong>en</strong>t installed on your local machine.<br />

1. To import the UI toolkit and the service, in the SAP HANA studio, choose the Modeler perspective and select<br />

your database instance.<br />

2. From the m<strong>en</strong>u, choose File Import .<br />

3. Select HANA Cont<strong>en</strong>t Delivery Unit and choose Next.<br />

4. Select Cli<strong>en</strong>t and browse for the HCO_INA_UITOOLKIT.tgz delivery unit.<br />

The delivery units can be found on the SAP HANA host under SYS/global/hdb/cont<strong>en</strong>t.<br />

5. Select both actions and choose Finish.<br />

6. Perform the same import procedure for the HCO_INA_SERVICE.tgz delivery unit.<br />

7. In the Navigator pane, under Cont<strong>en</strong>t, check that the following packages are available:<br />

sap\bc\ina\uitoolkit<br />

sap\bc\ina\demos\epm<br />

sap\bc\ina\service\v2<br />

8. To get started <strong>dev</strong>eloping apps using the toolkit, set up an application project.<br />

Related Links<br />

i031349364909774.ditamap<br />

Registering and Activating the Info Access Service<br />

1. To register the service, switch to the Lifecycle Managem<strong>en</strong>t perspective of the SAP HANA studio and select<br />

your database instance.<br />

2. Choose the Configuration tab page and expand xs<strong>en</strong>gine.ini\application_container.<br />

3. Double-click the application_list line and, under the System column, add the <strong>en</strong>try<br />

InformationAccess.<br />

Caution: Once InformationAccess is running, SAP HANA data is exposed by an HTTP service (port<br />

80).<br />

4. To restart SAP HANA XS, choose the Landscape tab page.<br />

5. From the context m<strong>en</strong>u of the xs<strong>en</strong>gine service, choose Kill...<br />

The service stops completely and restarts automatically.<br />

Importing the Demo Data<br />

1. Go to the SAP Code Exchange Web page of the UI toolkit.<br />

2. From the Docum<strong>en</strong>ts tab page, download the epm_data.zip archive.<br />

3. Follow the instructions in the readme.txt file contained in the archive.<br />

Related Links<br />

SAP Code Exchange Web page of the UI toolkit<br />

11.3.3 Getting to Know the Demo App<br />

You can now explore what an app built using the UI toolkit looks and feels like. Start the sample UI in a Web<br />

browser by op<strong>en</strong>ing the following URL:<br />

http://:80/sap/bc/ina/demos/epm/search.html<br />

306<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Example: http://<strong>hana</strong>1.acme.corp:8001/sap/bc/ina/demos/epm/search.html<br />

Start exploring the UI.<br />

The demo app consists of a header row, a column on the left, and a large cont<strong>en</strong>t area on the right. The column on<br />

the left contains some widgets; the search box and some charts. The charts are used for displaying the count of<br />

result items with distinct values. In the EPM example, it is the count of sold products by category and by curr<strong>en</strong>cy.<br />

The cont<strong>en</strong>t area on the right is for displaying an <strong>en</strong>larged view of one of the widgets, the result list is <strong>en</strong>larged at<br />

page load.<br />

The app starts with a search for all. By typing in the search box or filtering in the charts, you can refine the result<br />

set. The results are displayed in the list ranked by relevancy.<br />

From the right margin of the page, you can pull in the facet repository containing all configured facets that are not<br />

displayed in the column and the cont<strong>en</strong>t pane. Facets are the widgets, such as the results list and charts, that<br />

display the dim<strong>en</strong>sions of the result set.<br />

You can drag and drop all facets to any position on the UI, be it the column, the cont<strong>en</strong>t area or the facet<br />

repository. Wh<strong>en</strong> a chart is <strong>en</strong>larged in the cont<strong>en</strong>t pane, you can change the chart type with a click.<br />

11.3.4 Getting to Know the Demo HTML<br />

The structure and cont<strong>en</strong>t of the UI are defined in the search.html file. Op<strong>en</strong> the search.html file using the<br />

HTML editor. Familiarize yourself with the structure of the HTML.<br />

Partly collapsed, search.html looks like this:<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 307


In the head area and at the <strong>en</strong>d of the HTML, there is meta data and refer<strong>en</strong>ces to the various JavaScript libraries<br />

and CSS used by the UI.<br />

The body of the HTML contains the UI's header bar with the title text and the alert bar for displaying<br />

messages. The rest of the body is the workarea. A workarea connects to a SAP HANA attribute view and<br />

serves as a container for all other widgets on the page. The workarea is divided into the facetPane, the<br />

cont<strong>en</strong>tPane, and the facetrepository.<br />

The facetPane starts with the searchbox followed by a facetcolumn and the facetpane. The<br />

workareaitem widgets inside the column and the pane are only placeholders for facets of the repository that<br />

the user can shuffle around at runtime.<br />

Inside the facetrepository, there are the actual workareaitem widgets. For switching betwe<strong>en</strong> differ<strong>en</strong>t<br />

chart types, there are the switchbox widgets. The last widget in the repository is the resultlist.<br />

11.3.5 Preparing Your Source Data<br />

Before you start to build your information access application, you need to have a clear understanding of who will<br />

use it and for what purpose. Once you are sure which cont<strong>en</strong>t you need to <strong>en</strong>able for access, prepare this data as<br />

described here. Th<strong>en</strong> you define how the cont<strong>en</strong>t is to be displayed and which interactive navigation attributes are<br />

to be provided.<br />

Ensuring Full Text Indexing<br />

Make sure that a full-text index is created for each of your table columns that contains human-readable text data<br />

that is suitable for a freestyle search. The index structure is attached to the column and is leveraged to id<strong>en</strong>tify<br />

texts that contain the search terms. The full text index is automatically updated wh<strong>en</strong> new records are <strong>en</strong>tered in<br />

the table.<br />

308<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


Along with the full text index, you can also trigger a text analysis that extracts <strong>en</strong>tities, such as dates or people,<br />

from the text and, therefore, <strong>en</strong>riches the set of attributes.<br />

Related Links<br />

Creating Full Text Indexes [page 231]<br />

Wh<strong>en</strong> you create a TEXT or SHORTTEXT column in a table, SAP HANA automatically creates a corresponding<br />

full text index. However, for columns of other data types, you must manually create and define any necessary<br />

full text indexes.<br />

Text Analysis [page 238]<br />

Checking the Settings in SAP HANA Studio<br />

Technical search in SAP HANA may not be <strong>en</strong>abled. To check if it is <strong>en</strong>abled, proceed as follows:<br />

1. In the SAP HANA studio m<strong>en</strong>u, choose Window Prefer<strong>en</strong>ces Modeler Search Options .<br />

2. Check if the Enable Search Attributes option is selected. If not, select it and choose Apply and OK.<br />

Note: You must make this setting in every SAP HANA studio that you use to model views for search.<br />

Modeling Your Search Cont<strong>en</strong>t<br />

For each app user, you have created a named database user with the following authorizations:<br />

● Object privileges: SELECT on database schemas and .<br />

● Analytic privileges: For and for the attribute view you want to visualize in the app.<br />

In the SAP HANA modeler, create an attribute view of type standard using the tables that you want to <strong>en</strong>able for<br />

the search. Create joins and add the attributes you want to use for searching and displaying.<br />

Note: You can also join additional attributes derived from the text analysis.<br />

To <strong>en</strong>able certain attributes for the search, proceed as follows:<br />

1. In the Output view, select the attributes.<br />

Note: The searchable attributes must not be calculated attributes nor have lower case letters in their<br />

names.<br />

2. In the lower area of the Properties tab, select the Information Access category.<br />

3. Set the Freestyle Search property to true.<br />

In the Information Access category, you can make additional search-specific settings.<br />

The Weights for Ranking setting (betwe<strong>en</strong> 0.0 and 1.0, default 0.5) influ<strong>en</strong>ces the ranking of items in the results<br />

list. The higher the weight of the attribute, the higher up in the list an item with a hit in this attribute is positioned.<br />

The Fuzziness Threshold setting (betwe<strong>en</strong> 0.0 and 1.0, default 0.8) defines the grade of error tolerance for a<br />

search on this attribute. The higher the threshold, the more exact the search terms must hit the text to produce a<br />

result.<br />

Note: Do not forget to activate the attribute view.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 309


Related Links<br />

SAP HANA Modeling Views<br />

FUZZY Search [page 252]<br />

Fuzzy Search is a fast and fault-tolerant search feature for SAP HANA. A fuzzy search returns records ev<strong>en</strong> if<br />

the search term contains additional or missing characters or other types of spelling errors.<br />

11.3.6 Connecting Your Source Data<br />

You can connect any search-<strong>en</strong>abled SAP HANA attribute view to the app by refer<strong>en</strong>cing the view and its<br />

attributes directly in your HTML file.<br />

To refer<strong>en</strong>ce the attribute view and its schema in the HTML, <strong>en</strong>ter their names in the workarea widget:<br />

<br />

data-<strong>en</strong>tityset is the view name. data-schema is the database schema (catalog) in which the activated<br />

attribute view resides. The data-aggregationdim<strong>en</strong>sion is used as basis for counting items with distinct<br />

values. Enter an attribute that has unique values, for example, the primary key.<br />

For chart facets that display the aggregates of attribute values, for example the grouped bar chart, <strong>en</strong>ter the<br />

attribute names here:<br />

<br />

In the grouped bar chart example, data-dim<strong>en</strong>sion-line is the attribute whose distinct value count is to be<br />

displayed as the bars. The data-dim<strong>en</strong>sion-x attribute is displayed as an additional dim<strong>en</strong>sion inside the<br />

chart as a group of bars. data-dim<strong>en</strong>sion-y is the measurem<strong>en</strong>t that is displayed on the y-axis defining the<br />

height of the single bars. In the search app, the only measurem<strong>en</strong>t available is the distinct values count ($count)<br />

of the attribute defined in data-dim<strong>en</strong>sion-line.<br />

In a simple bar or pie chart, the data-dim<strong>en</strong>sion parameter contains the attribute whose distinct value count<br />

is to be displayed<br />

To define the attributes to be displayed in a result list <strong>en</strong>try, <strong>en</strong>ter the attribute names here:<br />


11.3.7 Defining the Page Layout<br />

Now that your source data is prepared and connected, you can form your UI using the search.html template.<br />

You may want to start by arranging the available widgets on your site. To place the column, the panes, and the<br />

facets within them, copy, move, or remove the corresponding HTML blocks.<br />

First, place the facet pane and its column(s) as well as the cont<strong>en</strong>t pane. The panes and the columns inside are<br />

displayed from left to right on the UI in the same order as in the HTML. Only one cont<strong>en</strong>t pane is allowed.<br />

Typically, a maximum of three facet columns are used. The facet repository is always last in the HTML.<br />

The search box and the facets inside the facet columns are next. The search box can span the <strong>en</strong>tire pane across<br />

multiple columns. Place as many placeholder work area items as you want to have slots in a column. Inside the<br />

cont<strong>en</strong>t pane, only one placeholder is allowed. Make sure that the data-target-position count is<br />

continuously set across the facet columns and the cont<strong>en</strong>t pane.<br />

The facet repository holds the actual facets, meaning the chart switch boxes and the result list. The datasource-position<br />

parameter defines their position inside the facet repository as well as inside the columns<br />

and the cont<strong>en</strong>t pane at page load.<br />

If the source position equals the target position, the respective facet replaces the placeholder in the columns and<br />

pane. If there are two or more facets with the same source position number, only the first one in the HTML<br />

replaces the placeholder. In the facet repository, all defined facets are available in the order of the source position<br />

or their appearance in the HTML. At runtime, the user can drag and drop the facets.<br />

At least one facet pane and cont<strong>en</strong>t pane are required for the facet repository and free drag-and-drop. However,<br />

you could also build a minimal static UI with a workarea containing just a search box and a result list, for example.<br />

You can ev<strong>en</strong> integrate single widgets into other sites.<br />

Related Links<br />

workareaitem [page 312]<br />

11.3.8 Configuring the Widgets<br />

The widgets are based on jQuery UI. In the HTML, you can customize the single widgets to a certain degree using<br />

parameters. The common parameter data-sap-widget defines the type of the widget.<br />

Each widget type has its own set of parameters. The widgets and their parameters are listed in the order of<br />

appearance in the demo HTML file.<br />

header<br />

Parameter Name Default Value Description<br />

data-title none Title text in the header bar of the UI.<br />

data-helphref none Refer<strong>en</strong>ce to the docum<strong>en</strong>tation for the users of your application.<br />

workarea<br />

Parameter Name Default<br />

Value<br />

Description<br />

data-title none This title is not displayed on the UI.<br />

data-packag<strong>en</strong>ame none Name of the database package in which the attribute view was created.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 311


Parameter Name Default<br />

Value<br />

Description<br />

data-<strong>en</strong>tityset none Name of the attribute view.<br />

data-schema _SYS_BIC Name of the database schema (catalog) in which the activated attribute<br />

view resides. The schema _SYS_BIC is default because your activated<br />

dataaggregationdim<strong>en</strong><br />

sion<br />

dataaggregationsorto<br />

rder<br />

Related Links<br />

Connecting Your Source Data [page 310]<br />

searchbox<br />

attribute views usually <strong>en</strong>d up in this schema.<br />

none Primary key attribute of the items you want to search and display. The<br />

unique key is used to id<strong>en</strong>tify items for the result list and to count items<br />

with distinct values for the charts.<br />

DESC Desc<strong>en</strong>ding or asc<strong>en</strong>ding (ASC) order for sorting the counts in the<br />

Parameter Name Default Value Description<br />

charts. This setting is inherited by all charts if you do not set a sort order<br />

there.<br />

data-maxinputl<strong>en</strong>gth 255 Maximum number of characters that users can <strong>en</strong>ter in the<br />

search box.<br />

workareaitem<br />

Parameter Name Default Value Description<br />

data-title none This title is displayed on the UI as the facet headline. If the<br />

workareaitem is a placeholder, the title is used as<br />

alternative text. The alternative is displayed if the<br />

placeholder is not replaced by an actual workareaitem<br />

at runtime.<br />

data-target-position 0 Position of a placeholder workareaitem on the UI in the<br />

facet or cont<strong>en</strong>t pane. The count starts on the upper left of<br />

the UI.<br />

data-source-position 0 Position of the actual workareaitem on the UI in the<br />

facetrepository<br />

Parameter Name Default Value Description<br />

data-childr<strong>en</strong>-draghandle<br />

312<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

facet repository on the right. On page load, the<br />

workareaitem placeholders are replaced by the actual<br />

workarea items whose source positions match the target<br />

positions.<br />

body Defines the area where a user can grab a facet for drag and drop.<br />

body means the complete facet, header means the facet's<br />

header bar only.<br />

SAP HANA Developer Guide<br />

Enabling Search


switchbox<br />

Parameter Name Default Value Description<br />

data-activeindex 0 Defines which chart contained in the switchbox is displayed on page<br />

load. 0 means the first one, 1 the second, and so on.<br />

chart<br />

Parameter Name Default Value Description<br />

data-toplarge none Defines how many bars or pie segm<strong>en</strong>ts are displayed wh<strong>en</strong> the<br />

chart is <strong>en</strong>larged.<br />

data-dim<strong>en</strong>sion none Attribute whose distinct value count is to be displayed in a<br />

simple bar or pie chart.<br />

data-charttype none Type of the chart (bar, pie, groupbar, or line).<br />

data-color none Color of the chart as hex triplet, for example #FFFFFF for<br />

white, or as standard HTML names, for example blue or<br />

black.<br />

data-dim<strong>en</strong>sion-line none Attribute whose distinct value count is to be displayed in<br />

grouped bar or line chart.<br />

data-dim<strong>en</strong>sion-x none Attribute that is displayed as additional dim<strong>en</strong>sion inside the<br />

chart as group of bars or differ<strong>en</strong>t lines.<br />

data-dim<strong>en</strong>sion-y none Measurem<strong>en</strong>t that is displayed on the y-axis. In a search<br />

sc<strong>en</strong>ario, the only measurem<strong>en</strong>t available is the distinct value<br />

count ($count) of the attribute defined in data-<br />

dataaggregationsortorde<br />

r<br />

dim<strong>en</strong>sion-line.<br />

ASC Desc<strong>en</strong>ding (DESC) or asc<strong>en</strong>ding order for sorting the counts<br />

in the charts. Here you can override the sort order defined<br />

c<strong>en</strong>trally in the workarea widget.<br />

data-topsmall none Defines how many bars or pie segm<strong>en</strong>ts are displayed wh<strong>en</strong> the<br />

chart is small.<br />

dataanimationduration<br />

Related Links<br />

Connecting Your Source Data [page 310]<br />

inaresultlist<br />

1000 Duration of the animation, in milliseconds, wh<strong>en</strong> a chart adapts<br />

(default 1000). 0 means that animation is switched off.<br />

Parameter Name Default Value Description<br />

data-maxresultslarge 10 Maximum number of result items displayed on one<br />

page if the list is <strong>en</strong>larged in the cont<strong>en</strong>t pane.<br />

data-maxresultssmall 5 Maximum number of result items displayed on one<br />

page if the list is small in the facet column.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 313


Parameter Name Default Value Description<br />

data-responseattributes none Attributes to be displayed in a result list <strong>en</strong>try. The<br />

actual scope and layout of the response attributes on<br />

the result list and details pane are defined in the files<br />

refer<strong>en</strong>ced in the data-resulttemplate<br />

parameters.<br />

Note:<br />

Do not leave the dataresponseattributes<br />

parameter empty.<br />

Only use attributes from the main table of the<br />

view or attributes that are joined in 1:1 from<br />

other tables.<br />

Attributes with data type blob are not<br />

supported by the HTTP service.<br />

data-detailwidth 600 Width of the details pop-up in pixels.<br />

data-detailheight 800 Height of the details pop-up in pixels.<br />

data-resulttemplate none Refer<strong>en</strong>ce to HTML and CSS files defining the layouts<br />

data-resulttemplate-css none<br />

of the result lists (small and large) and of the details<br />

pop-up.<br />

data-resulttemplate-small none<br />

data-resulttemplatesmall-css<br />

data-resulttemplatedetail<br />

data-resulttemplatedetail-css<br />

none<br />

none<br />

none<br />

data-scoresortorder DESC By default, the result list is sorted according to the<br />

ranking by relevancy for the search term(s). Leave the<br />

default sort order unchanged.<br />

data-orderby none Attribute by whose values the list is sorted<br />

alphabetically. First choice for sorting is always the<br />

ranking by relevancy for the search term(s). The<br />

data-orderby setting only steps in if there is no<br />

relevancy ranking available, for example before the<br />

first search, or if there are equal ranking values.<br />

data-sortorder ASC Asc<strong>en</strong>ding or desc<strong>en</strong>ding (DESC) order for the dataorderby<br />

parameter.<br />

Related Links<br />

Connecting Your Source Data [page 310]<br />

Defining the Layout of Result Lists and Details [page 315]<br />

314<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Enabling Search


11.3.9 Defining the Layout of Result Lists and Details<br />

You can select which attributes are displayed and how they are displayed in the result lists (small or c<strong>en</strong>tered) and<br />

on the details pop-up. In the search HTML file, the result templates are refer<strong>en</strong>ced in the inaresultlist<br />

widget using the data-resulttemplate parameters.<br />

The templates folder contains the HTML and CSS templates of the demo app for adapting. You can create your<br />

own result layouts from the templates and refer<strong>en</strong>ce them in the parameters. Make sure that the path is correct.<br />

In the HTML templates, you define what is in a result <strong>en</strong>try in the differ<strong>en</strong>t views. You can <strong>en</strong>ter fixed text and<br />

refer<strong>en</strong>ce the response properties and values in double braces.<br />

For a deeper understanding of these HTML templates, familiarize yourself with the Tempo JSON r<strong>en</strong>dering<br />

<strong>en</strong>gine.<br />

Note: If you want to integrate graphics in result list templates, define the exact width and height in pixels.<br />

Use the corresponding CSS files to define the result layouts and the behavior on hover ev<strong>en</strong>ts. To tweak the layout<br />

of the details scre<strong>en</strong> further, you can also use the widgets provided by jQuery UI.<br />

SAP HANA Developer Guide<br />

Enabling Search<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 315


12 Setting Up Roles and<br />

Authorizations<br />

12.1 The Authorization Model<br />

Authorization mechanisms <strong>en</strong>sure that auth<strong>en</strong>ticated users can do only those things they are allowed to do. You<br />

can use the authorization mechanisms of the SAP HANA database to specify who is allowed to access which data<br />

and for which activities.<br />

Authorization mechanisms can also be used to help control who is allowed to execute stored procedures and<br />

functions or execute system-level activities, for example: making backups, creating schema, users, roles, and so<br />

on.<br />

Authorizations are specified by granting privileges to principals. Principals are either users or roles. Roles<br />

repres<strong>en</strong>t collections of privileges that can be granted to users or other roles, which <strong>en</strong>ables you to create a<br />

hierarchy of roles. Privileges are granted to principals by users.<br />

SAP HANA database authorization mechanisms use the following privileges:<br />

● System privileges<br />

Perform system-level operations or administrative tasks<br />

● Object privileges<br />

Perform specified actions on specified database objects<br />

● Analytic privileges<br />

Allow selective access control for database views g<strong>en</strong>erated wh<strong>en</strong> modeled are activated<br />

● Package Privileges<br />

Allow operations on packages, for example, creation and maint<strong>en</strong>ance. Privileges can differ for native and<br />

imported packages.<br />

Other types of privileges <strong>en</strong>able you to provide specific additional authorizations, for example, to users who need<br />

to perform administrative tasks on objects in the repository or to users and cli<strong>en</strong>ts that need access to<br />

applications:<br />

● Repository Privileges<br />

Enable users to perform basic repository operations, for example: import and export packages, and maintain<br />

delivery units (DU)<br />

● Application Privileges<br />

316<br />

Enable users and cli<strong>en</strong>ts to access an application, configure what data to expose, and set rules for exposing<br />

URLs.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


12.2 Auth<strong>en</strong>tication Overview<br />

Auth<strong>en</strong>tication is the process used to validate the id<strong>en</strong>tity of the users who connect to SAP HANA.<br />

Secure auth<strong>en</strong>tication mechanisms <strong>en</strong>sure that the users requesting a connection really are who they claim to be.<br />

Note: For connections to SAP HANA it is important to distinguish betwe<strong>en</strong> SQL- and HTTP-based<br />

connections.<br />

For SQL access to SAP HANA by means of cli<strong>en</strong>t interfaces, for example, JDBC or ODBC, the following<br />

auth<strong>en</strong>tication methods are supported:<br />

● External auth<strong>en</strong>tication:<br />

○ Kerberos services<br />

A standardized service for cli<strong>en</strong>t auth<strong>en</strong>tication in networks. The cli<strong>en</strong>t connects to the Kerberos server to<br />

auth<strong>en</strong>ticate the user and to acquire an auth<strong>en</strong>tication ticket that proves the user’s id<strong>en</strong>tity to the SAP<br />

HANA database. The cli<strong>en</strong>t uses the ticket to connect to the SAP HANA database. Kerberos also <strong>en</strong>sures<br />

the correct id<strong>en</strong>tity of the server.<br />

○ SAML (bearer tok<strong>en</strong>)<br />

SAP HANA can auth<strong>en</strong>ticate users who provide a valid standard-based SAML assertion issued by a<br />

trusted id<strong>en</strong>tity provider.<br />

● Internal auth<strong>en</strong>tication<br />

Users are auth<strong>en</strong>ticated by the SAP HANA database using the database user name and password.<br />

SAP HANA maps the external id<strong>en</strong>tity approved by external auth<strong>en</strong>tication service to the id<strong>en</strong>tity of an internal<br />

database user. This internal database user is th<strong>en</strong> used for authorization checks during the database session.<br />

For HTTP access to SAP HANA by means of SAP HANA XS, the following auth<strong>en</strong>tication methods are supported:<br />

● User name and password:<br />

○ Using HTTP basic auth<strong>en</strong>tication<br />

○ Form-based auth<strong>en</strong>tication<br />

● SAP logon tickets<br />

12.3 Roles<br />

Roles contain privileges that are used to define which data, application, or function can be accessed and in which<br />

manner consumed. Roles are assigned either to users or to other roles at runtime.<br />

SAP delivers some g<strong>en</strong>eric roles with SAP HANA that can be used as they are or as templates (during design time)<br />

for creating roles that meet your company's specific requirem<strong>en</strong>ts. More information about roles, their use at<br />

runtime and in design time are explained in the subsequ<strong>en</strong>t sections.<br />

● Roles<br />

● Roles as Repository Objects<br />

● Creating Roles in the Repository<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 317


12.3.1 Roles<br />

A role is a collection of privileges that can be granted to either a user or another role in runtime.<br />

A role typically contains the privileges required for a particular function or task, for example:<br />

● Business <strong>en</strong>d users reading reports using cli<strong>en</strong>t tools such as Microsoft Excel<br />

● Modelers creating models and reports in the modeler of the SAP HANA studio<br />

● Database administrators operating and maintaining the database and users in the Administration editor of the<br />

SAP HANA studio<br />

Privileges can be granted directly to users of the SAP HANA database. However, roles are the standard<br />

mechanism of granting privileges as they allow you to implem<strong>en</strong>t complex, reusable hierarchies of user access<br />

that can be modeled on business roles. Several standard roles are delivered with the SAP HANA database (for<br />

example, MODELING, MONITORING). You can use these as templates for creating your own roles.<br />

Roles in the SAP HANA database can exist as runtime objects only, or as design-time objects that become<br />

runtime objects on activation.<br />

Role Structure<br />

A role can contain any number of the following privileges:<br />

● System privileges for administrative tasks (for example, AUDIT ADMIN, BACKUP ADMIN, CATALOG READ)<br />

● Object privileges on database objects (for example, SELECT, INSERT, UPDATE)<br />

● Package privileges on repository packages (for example, REPO.READ, REPO.EDIT_NATIVE_OBJECTS,<br />

REPO.ACTIVATE_NATIVE_OBJECTS)<br />

● Analytic privileges on SAP HANA information models<br />

● Application privileges for <strong>en</strong>abling access to SAP HANA XS applications<br />

Note: Application privileges cannot be granted to roles in the SAP HANA studio.<br />

A role can also ext<strong>en</strong>d other roles.<br />

Role Modeling<br />

You can model roles in the following ways:<br />

● As runtime objects on the basis of SQL statem<strong>en</strong>ts<br />

● As design-time objects in the repository of the SAP HANA database<br />

It is recomm<strong>en</strong>ded that you model roles as design-time objects for the following reasons.<br />

Firstly, unlike roles created in runtime, roles created as design-time objects can be transported betwe<strong>en</strong> systems.<br />

This is important for application <strong>dev</strong>elopm<strong>en</strong>t as it means that <strong>dev</strong>elopers can model roles as part of their<br />

application's security concept and th<strong>en</strong> ship these roles or role templates with the application. Being able to<br />

transport roles is also advantageous for modelers implem<strong>en</strong>ting complex access control on analytic cont<strong>en</strong>t. They<br />

can model roles in a test system and th<strong>en</strong> transport them into a productive system. This avoids unnecessary<br />

duplication of effort.<br />

318<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


Secondly, roles created as design-time objects are not directly associated with a database user. They are created<br />

by the technical user _SYS_REPO and granted through the execution of stored procedures. Any user with access<br />

to these procedures can grant and revoke a role. Roles created in runtime are granted directly by the database<br />

user and can only be revoked by the same user. Additionally, if the database user is deleted, all roles that he or she<br />

granted are revoked. As database users correspond to real people, this could impact the implem<strong>en</strong>tation of your<br />

authorization concept, for example, if an employee leaves the organization or is on vacation.<br />

Caution: The design-time version of a role in the repository and its activated runtime version should<br />

always contain the same privileges. In particular, additional privileges should not be granted to the<br />

activated runtime version of a role created in the repository. Although there is no mechanism of<br />

prev<strong>en</strong>ting a user from doing this, the next time the role is activated in the repository, any changes made<br />

to the role in runtime will be reverted. It is therefore important that the activated runtime version of a role<br />

is not changed in runtime.<br />

12.3.2 Roles as Repository Objects<br />

The repository of the SAP HANA database consists of packages that contain design-time versions of various<br />

objects. Being a repository object has several implications for a role.<br />

Grantable Privileges<br />

According to the authorization concept of the SAP HANA database, a user can only grant a privilege to a user<br />

directly or indirectly in a role if the following prerequisites are met:<br />

● The user has the privilege him- or herself<br />

● The user is authorized to grant the privilege to others (WITH ADMIN OPTION or WITH GRANT OPTION)<br />

A user is also authorized to grant SQL object privileges on objects that he or she owns.<br />

The technical user _SYS_REPO is the owner of all objects in the repository, as well as the runtime objects that are<br />

created on activation. This means that wh<strong>en</strong> you create a role as a repository object, you can grant the following<br />

privileges:<br />

● Privileges that have be<strong>en</strong> granted to the technical user _SYS_REPO and that _SYS_REPO can grant further.<br />

This is automatically the case for system privileges, package privileges, analytic privileges, and application<br />

privileges. Therefore, all system privileges, package privileges, analytic privileges, and application privileges<br />

can always be granted in modeled roles.<br />

● Privileges on objects that _SYS_REPO owns.<br />

_SYS_REPO owns all activated objects. Object privileges on non-activated runtime objects must be explicitly<br />

granted to _SYS_REPO. It is recomm<strong>en</strong>ded that you use a technical user to do this to <strong>en</strong>sure that privileges<br />

are not dropped wh<strong>en</strong> the granting user is dropped (for example, because she leaves the company.<br />

The following table summarizes the situation described above:<br />

Privilege Action Necessary to Grant in Repository Role<br />

System privilege None<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 319


Privilege Action Necessary to Grant in Repository Role<br />

Package privilege None<br />

Analytic privilege None<br />

Application privilege None<br />

SQL object on activated object (for example, attribute<br />

view, analytic view)<br />

SQL object privilege on runtime object (for example,<br />

replicated table)<br />

Granting and Revoking<br />

None<br />

Grant privilege to user _SYS_REPO with WITH GRANT<br />

OPTION<br />

It is not possible to grant and revoke activated design-time roles using the GRANT and REVOKE SQL statem<strong>en</strong>ts.<br />

Instead, roles are granted and revoked through the execution of the procedures GRANT_ACTIVATED_ROLE and<br />

REVOKE_ACTIVATED_ROLE. Therefore, to be able to grant or revoke a role, a user must have the SQL object<br />

privilege EXECUTE on these procedures.<br />

WITH ADMIN OPTION and WITH GRANT OPTION<br />

Wh<strong>en</strong> you create a role on the basis of SQL statem<strong>en</strong>ts (that is, as a runtime object), you can grant privileges with<br />

the additional parameters WITH ADMIN OPTION or WITH GRANT OPTION. This allows a user who is granted the<br />

role to grant the privileges contained within the role to other users and roles. However, if you are implem<strong>en</strong>ting<br />

your authorization concept with privileges <strong>en</strong>capsulated within roles created in design time, th<strong>en</strong> you do not want<br />

users to grant privileges using SQL statem<strong>en</strong>ts. Therefore, it is not possible to pass the parameters WITH ADMIN<br />

OPTION or WITH GRANT OPTION with privileges wh<strong>en</strong> you model roles as repository objects.<br />

Similarly, wh<strong>en</strong> you grant an activated role to a user, it is not possible to allow the user to grant the role further<br />

(WITH ADMIN OPTION is not available).<br />

Auditability<br />

The auditing feature of the SAP HANA database allows you to monitor and record selected actions performed in<br />

your database system. One action that is typically audited is changes to user authorization. If you are using roles<br />

created in the repository to grant privileges to users, th<strong>en</strong> it is important to note that the creation of runtime roles<br />

through activation cannot be meaningfully audited.<br />

12.3.3 Creating Roles in the Repository<br />

You model roles in the SAP HANA repository in a domain-specific language (DSL).<br />

● A shared project must exist with a suitable package for storing roles.<br />

● You have the package and system privileges required for modeling and activating objects in the repository.<br />

320<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


Caution: Theoretically, a user with authorization to model and activate repository objects can change<br />

a role that he has be<strong>en</strong> granted. Once the role is activated, the user has the new privileges that he or<br />

she just added. Therefore, it is important that roles in productive systems are imported from a test or<br />

<strong>dev</strong>elopm<strong>en</strong>t system and changes to imported objects are not allowed. This danger is however not<br />

specific to roles but also applies to other repository objects, for example, modeled views.<br />

● You have granted privileges on non-activated runtime objects that you want to grant in the new role to the<br />

technical user _SYS_REPO.<br />

The following g<strong>en</strong>eral conv<strong>en</strong>tions apply wh<strong>en</strong> modeling a role definition using the role DSL:<br />

● Comm<strong>en</strong>ts start with a double-slash (//) or double-dash (--) and run to the <strong>en</strong>d of the line.<br />

● Wh<strong>en</strong> specifying a refer<strong>en</strong>ce to a design-time object, you must always specify the package name as follows:<br />

○ package::object if you are refer<strong>en</strong>cing a design-time role<br />

○ package:object.ext<strong>en</strong>sion if you are refer<strong>en</strong>cing any other design-time object<br />

● Wh<strong>en</strong> specifying multiple privileges on the same object or the same privilege on multiple objects, you can do<br />

so individually line by line, or you can group them on a single line. Separate multiple objects and/or multiple<br />

privileges using a comma.<br />

1. From the main m<strong>en</strong>u in the SAP HANA studio, choose File New Other SAP HANA Repository Role<br />

.<br />

The New Role dialog box appears.<br />

2. In the Container field, <strong>en</strong>ter the path to the package where you want to create the role.<br />

3. In the Role name field, <strong>en</strong>ter the name of the new role.<br />

4. Choose Finish.<br />

The new role appears in the Project Explorer view and op<strong>en</strong>s in the role editor as follows:<br />

// an empty role<br />

role :: {<br />

}<br />

The role is now ready to be defined.<br />

5. Optional: Specify the role(s) that you want to embed within the new role.<br />

You can specify both roles created in runtime and repository roles as follows:<br />

○ ext<strong>en</strong>ds role ::<br />

○ ext<strong>en</strong>ds catalog role "role_name"<br />

Example:<br />

role ::<br />

ext<strong>en</strong>ds role sap.example::role1<br />

ext<strong>en</strong>ds catalog role "CATROLE2"<br />

{<br />

}<br />

6. Model the required privileges.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 321


322<br />

Note: Unlike wh<strong>en</strong> you create a role using SQL statem<strong>en</strong>ts, it is not possible to grant ALL<br />

PRIVILEGES wh<strong>en</strong> creating a role in the repository. You must model every privilege individually.<br />

a) Model system privileges using the keyword "system privilege" as follows: system privilege:<br />

PRIVILEGE;<br />

Example:<br />

role ::<br />

{<br />

// multiple privileges in one line are OK<br />

system privilege: BACKUP ADMIN, USER ADMIN;<br />

}<br />

// you can also split lists into multiple <strong>en</strong>tries<br />

system privilege: LICENSE ADMIN;<br />

b) Optional: Model object privileges on the design-time objects views and procedures using the keyword<br />

"SQL object" as follows: sql object :.ext<strong>en</strong>sion: PRIVILEGE;<br />

Example:<br />

role ::<br />

{<br />

sql object sap.example:MY_VIEW.attributeview: DROP;<br />

// object privileges can be split across lines<br />

sql object sap.example:MY_VIEW.attributeview: DROP;<br />

// a single privilege can be giv<strong>en</strong> on multiple objects in a<br />

single line<br />

sql object sap.example:MY_VIEW.attributeview,<br />

sap.example:MY_OTHER_VIEW.analyticview,<br />

sap.example:MY_THIRD_VIEW.analyticview: SELECT;<br />

}<br />

c) Optional: Model object privileges on catalog objects using the keyword "catalog SQL object" as follows:<br />

catalog sql object "SCHEMA"."CATALOG_OBJECT": PRIVILEGE;<br />

Example:<br />

Note: You must always qualify catalog objects with the schema name. You must also refer<strong>en</strong>ce<br />

catalog objects within double quotes, unlike design-time objects.<br />

role ::<br />

{<br />

// catalog objects must always be qualified with the schema name<br />

catalog sql object "MY_SCHEMA"."MY_VIEW": SELECT;<br />

}<br />

d) Optional: Model schema privileges on schemas using the keywords "catalog schema" or "schema" as<br />

follows dep<strong>en</strong>ding on whether you are referring to an activated schema or a schema in the repository:<br />

○ catalog schema "SCHEMA": PRIVILEGE;<br />

○ schema :.schema: PRIVILEGE;<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


Example:<br />

role ::<br />

{<br />

catalog schema "MY_SCHEMA": SELECT;<br />

schema sap.example:MY_OTHER_SCHEMA.schema: SELECT;<br />

}<br />

e) Optional: Model package privileges using the keywords "package" as follows: package PACKAGE:<br />

PRIVILEGE;<br />

Example:<br />

role ::<br />

{<br />

package sap.example: REPO.READ;<br />

}<br />

f) Optional: Model analytic privileges using the keywords "analytic privilege" or "catalog analytic privilege"<br />

dep<strong>en</strong>ding on whether you are referring to an activated analytic privilege or a runtime analytic privilege<br />

○ analytic privilege: :.analyticprivilege<br />

○ catalog analytic privilege: "analytic_priv_name";<br />

Example:<br />

role ::<br />

{<br />

analytic privilege: sap.example:sp1.analyticprivilege,<br />

sap.example:AP2.analyticprivilege;<br />

catalog analytic privilege: "sp3";<br />

}<br />

g) Optional: Model application privileges using the keyword "application privilege" as follows:<br />

application privilege: ;<br />

Example:<br />

role ::<br />

{<br />

application privilege: sap.example::Execute;<br />

}<br />

Note: Application privileges are implem<strong>en</strong>ted using the application-privileges file<br />

(.xsprivileges).<br />

7. From the main m<strong>en</strong>u, choose File Save .<br />

The role is saved as an .hdbrole file. After it has be<strong>en</strong> saved, the file is committed to the repository<br />

8. Activate the role by right-clicking it in the Project Explorer view and choosing Team Activate .<br />

Note: Any changes made to a previously activated version of the role in runtime will be reverted on<br />

activation. This is to <strong>en</strong>sure that the design-time version of a role in the repository and its activated<br />

runtime version contain the same privileges. It is therefore important that the activated runtime<br />

version of a role is not changed in runtime.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 323


The activated role is now visible in the Navigator view under Security Roles following the naming conv<strong>en</strong>tion<br />

package::role_name and can be granted to users as part of user provisioning.<br />

Complete Role Definition Example<br />

role ::<br />

ext<strong>en</strong>ds role sap.example::role1<br />

ext<strong>en</strong>ds catalog role "CATROLE1", "CATROLE2"<br />

{<br />

// system privileges<br />

system privilege: BACKUP ADMIN, USER ADMIN;<br />

// schema privileges<br />

catalog schema "SYSTEM": SELECT;<br />

schema sap.example:app1.schema: INSERT, UPDATE, DELETE;<br />

// sql object privileges<br />

// privileges on the same object may be split up in several lines<br />

catalog sql object "SYSTEM"."TABLE2": SELECT;<br />

catalog sql object "SYSTEM"."TABLE2": INSERT, UPDATE, DELETE;<br />

// or a list of objects may get a list of privileges (object =<br />

table, view, procedure, sequ<strong>en</strong>ce)<br />

// SELECT, DROP for all objects in list<br />

sql object sap.example:VIEW1.attributeview,<br />

sap.example:PROC1.procedure, sap.example:SEQ1.sequ<strong>en</strong>ce: SELECT, DROP;<br />

// additional INSERT, UPDATE for TABLE1<br />

sql object sap.example:MY_VIEW.attributeview: DROP;<br />

// analytic privileges<br />

analytic privilege: sap.example:sp1.analyticprivilege,<br />

sap.example:AP2.analyticprivilege;<br />

catalog analytic privilege: "sp3";<br />

}<br />

Related Links<br />

// design time privileges<br />

package sap.example: REPO.EDIT_NATIVE_OBJECTS;<br />

package sap.example, sap.co: REPO.READ;<br />

application privilege: sap.example::Execute, sap.example::Save;<br />

Setting up Your Application [page 34]<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), the design-time artifacts that make up your<br />

application are stored in the repository like files in a file system. You first choose a root folder for your<br />

application-<strong>dev</strong>elopm<strong>en</strong>t activities, and within this folder you create additional subfolders to organize the<br />

applications and the application cont<strong>en</strong>t according to your own requirem<strong>en</strong>ts.<br />

The Application-Privileges File [page 59]<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), the application-privileges (.xssprivileges)<br />

file can be used to create or define the authorization privileges required for access to an SAP HANA XS<br />

application, for example, to start the application or to perform administrative actions on an application. These<br />

privileges can be checked by an application at runtime.<br />

SAP HANA Administration Guide<br />

324<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


12.4 Privileges<br />

SAP HANA offers various privileges that can be assigned to users. Users can be a system, an application, a<br />

service, or a person, and each user is assigned specific roles. Privileges can be assigned to users, roles, or both.<br />

There are several privileges that are required either by the SAP HANA studio or by <strong>dev</strong>elopm<strong>en</strong>t tools, such as<br />

SQL. The following types of privileges are explained in the subsequ<strong>en</strong>t sections.<br />

● System privileges<br />

● Object privileges<br />

● Package privileges<br />

● Analytic privileges<br />

This section also contains information for creating and granting privileges to users.<br />

12.4.1 System Privileges<br />

System privileges are required to perform system-level operations or administrative tasks.<br />

The following lists shows some of the most common system-level tasks that administrators regularly must<br />

perform:<br />

● Database schema<br />

Creation and deletion of database schema<br />

● Users/Roles<br />

Maint<strong>en</strong>ance and managem<strong>en</strong>t of users and roles<br />

● Monitor/Trace<br />

Administration of monitoring and tracing<br />

● Backup/Restore<br />

Performance of backup and restore operations<br />

In the SAP HANA database the user SYSTEM has all system privileges. The SYSTEM user can grant system<br />

privileges to other users and roles.<br />

12.4.2 Object Privileges<br />

Object privileges <strong>en</strong>able users to perform specified actions on specified database objects.<br />

Object privileges are not specific to the SAP HANA database; they are part of the SQL standard. You can use the<br />

SQL statem<strong>en</strong>ts GRANT and REVOKE to manage privileges.<br />

Note: . If object privileges (or any other privilege type) are granted to roles created in the repository,<br />

granting and revoking actions happ<strong>en</strong> through the execution of stored procedures.<br />

The set of actions that can be allowed by an object privilege dep<strong>en</strong>ds on the object type. For tables, you can use<br />

actions such as: drop, alter, select, insert and update. An execute action is available for privileges for procedures<br />

and functions. Privileges on a schema level are used to <strong>en</strong>able actions such as: create objects, perform select,<br />

update, delete or execute operations on all objects contained in the schema.<br />

In the SAP HANA database object privileges are not only available for database catalog objects such as tables,<br />

views and procedures. Object privileges can also be granted for non-catalog objects such as <strong>dev</strong>elopm<strong>en</strong>t objects<br />

in the repository of the SAP HANA database.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 325


Some database objects dep<strong>en</strong>d on other objects. Views, for example, are defined as queries on other tables and<br />

views. The authorization for an operation on the dep<strong>en</strong>d<strong>en</strong>t object (the queried tables and views) requires<br />

privileges for the dep<strong>en</strong>d<strong>en</strong>t object and the underlying object. In case of views, the SAP HANA database<br />

implem<strong>en</strong>ts the standard SQL behavior. A user has the authorization for an operation on a view if the following is<br />

true:<br />

● The privilege for operations on the view has be<strong>en</strong> granted to the user or a role assigned to the user.<br />

● The owner of the view has the corresponding privileges on the underlying objects with the option to grant<br />

them to others.<br />

This behavior can be used to grant selective access to a table.<br />

12.4.3 Package Privileges<br />

In the SAP HANA repository, authorizations can be assigned to individual packages.<br />

Authorizations assigned to a repository package are implicitly assigned to the design-time objects in the package<br />

as well as to all sub-packages. Users are only allowed to maintain objects in a repository package if they have the<br />

necessary privileges for the package in which they want to perform an operation, for example to read or write to<br />

an object in that package.<br />

Note: Package authorizations can be set for a specific user or for a role.<br />

If the user-authorization check establishes that a user does not have the necessary privileges to perform the<br />

requested operation in a specific package, the authorization check is repeated on the par<strong>en</strong>t package and<br />

recursively up the package hierarchy to the root level of the repository. If the user does not have the necessary<br />

privileges for any of the packages in the hierarchy chain, the authorization check fails and the user is not<br />

permitted to perform the requested operation.<br />

In the context of repository authorizations, there is a distinction to be made betwe<strong>en</strong> native packages and<br />

imported packages.<br />

● Native Package<br />

A package that is created in the curr<strong>en</strong>t system and expected to be edited in the curr<strong>en</strong>t system. Changes to<br />

package objects must be performed in the original <strong>dev</strong>elopm<strong>en</strong>t system where they were created and<br />

transported into subsequ<strong>en</strong>t systems. The cont<strong>en</strong>t of native packages are regularly edited by <strong>dev</strong>elopers.<br />

● Imported Package<br />

A package that is created in a remote system and imported into the curr<strong>en</strong>t system. Imported packages<br />

should not usually be modified, except wh<strong>en</strong> replaced by new imports during an update. Otherwise, imported<br />

packages should only be modified in exceptional cases, for example, to carry out emerg<strong>en</strong>cy repairs.<br />

To perform every-day, package-related, application-<strong>dev</strong>elopm<strong>en</strong>t tasks in the repository, <strong>dev</strong>elopers typically<br />

need the following privileges for the application packages:<br />

● REPO.READ<br />

Read access to the selected package and design-time objects (both native and imported)<br />

● REPO.EDIT_NATIVE_OBJECTS<br />

Authorization to modify design-time objects in packages originating in the system the user is working in<br />

● REPO.ACTIVATE_NATIVE_OBJECTS<br />

Authorization to activate/reactivate design-time objects in packages originating in the system the user is<br />

working in<br />

● REPO.MAINTAIN_NATIVE_PACKAGES<br />

326<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


Authorization to update or delete native packages, or create sub-packages of packages originating in the<br />

system in which the user is working<br />

SAP HANA Repository Privileges<br />

In addition to the authorizations you can grant users for specific packages (and the design-time objects in those<br />

packages), you can also assign g<strong>en</strong>eral system privileges to users to <strong>en</strong>able them to perform basic repository<br />

operations, for example: importing and exporting cont<strong>en</strong>t, and maintaining delivery units (DU).<br />

If your daily tasks include g<strong>en</strong>eral administration tasks, you need basic system-level privileges in the repository.<br />

To perform basic administration tasks in the repository, you typically need the following privileges:<br />

● REPO.EXPORT<br />

Enables you to export delivery units; exporting a DU transports it to another system<br />

● REPO.IMPORT<br />

Enables you to import delivery units; importing a DU transports it from another system<br />

● REPO.MAINTAIN_DELIVERY_UNITS<br />

Enables you to maintain your own delivery units (the DU-v<strong>en</strong>dor must equal the system-v<strong>en</strong>dor)<br />

● REPO.WORK_IN_FOREIGN_WORKSPACE<br />

Enables you to move objects from a "foreign" inactive workspace into your own workspace<br />

You can grant or revoke basic, repository privileges to users in the following ways:<br />

● SAP HANA Studio<br />

The System Privileges tab page in the Modeler perspective: Catalog -> Authorization -> Roles or Users<br />

Note: If you want to access the repository from the SAP HANA studio, Eclipse, or other cli<strong>en</strong>ts,you need<br />

the EXECUTE privilege for SYS.REPOSITORY_REST, the database procedure through which the REST<br />

API is tunneled.<br />

Defining Repository Package Privileges<br />

In the SAP HANA repository, you can set package authorizations for a specific user or for a role. Authorizations<br />

that are assigned to a repository package are implicitly assigned to all sub-packages, too. You can also specify if<br />

the assigned user authorizations can be passed on to other users.<br />

To set user (or role) authorizations for repository packages, perform the following steps:<br />

1. In the SAP HANA studio, op<strong>en</strong> the Navigator view of the Modeler perspective.<br />

2. In the Navigator view, expand the Security Roles/Users node for the system hosting the repository that<br />

contains the packages you want to grant access to.<br />

You can also define roles via source files; roles defined in this way can be assigned to a delivery unit and<br />

transported to other systems.<br />

3. Double click the user (or role) to whom you want to assign authorizations.<br />

4. Op<strong>en</strong> the Package Privileges tab page.<br />

5. Choose [+] to add one or more packages. Press and hold the Ctrl key to select multiple packages.<br />

6. In the Select Repository Package dialog, use all or part of the package name to locate the repository package<br />

that you want to authorize access to.<br />

7. Select one or more repository packages that you want to authorize access to; the selected packages appear<br />

in the Package Privileges tab page.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 327


8. Select the packages to which you want authorize access and, in the Privileges for scre<strong>en</strong> page, check the<br />

required privileges, for example:<br />

a) REPO.READ<br />

Read access to the selected package and design-time objects (both native and imported)<br />

b) REPO.EDIT_NATIVE_OBJECTS<br />

Authorization to modify design-time objects in packages originating in the system the user is working in<br />

c) REPO.ACTIVATE_NATIVE_OBJECTS<br />

Authorization to activate/reactivate design-time objects in packages originating in the system the user is<br />

working in<br />

d) REPO.MAINTAIN_NATIVE_PACKAGES<br />

Authorization to update or delete native packages, or create sub-packages of packages originating in the<br />

system in which the user is working<br />

12.4.4 Analytic Privileges<br />

SQL privileges impose coarse-grained restrictions at object level only. Users either have access to an object, such<br />

as a table, view or procedure, or they do not. While this is oft<strong>en</strong> suffici<strong>en</strong>t, there are cases wh<strong>en</strong> access to data in<br />

an object dep<strong>en</strong>ds on certain values or combinations of values. Analytic privileges are used in the SAP HANA<br />

database to provide such fine-grained control of which data individual users can see within the same view.<br />

Note: Sales data for all regions are contained within one analytic view. However, regional sales managers<br />

should only see the data for their region. In this case, an analytic privilege could be modeled so that they<br />

can all query the view, but only the data that each user is authorized to see is returned.<br />

Analytic privileges are int<strong>en</strong>ded to control access to SAP HANA information models, that is:<br />

● Attribute views<br />

● Analytic views<br />

● Calculation views<br />

Therefore, all column views modeled and activated in the SAP HANA modeler automatically <strong>en</strong>force an<br />

authorization check based on analytic privileges. Column views created using SQL must be explicitly registered<br />

for such a check (by passing the parameter REGISTERVIEWFORAPCHECK).<br />

Note: Analytic privileges do not apply to database tables or views modeled on row-store tables. Access to<br />

database tables and row views is controlled <strong>en</strong>tirely by SQL object privileges.<br />

You create and manage analytic privileges in the SAP HANA modeler.<br />

Note: Some advanced features of analytic privileges, namely dynamic value filters, can only be<br />

implem<strong>en</strong>ted using SQL. The managem<strong>en</strong>t of such analytic privileges created in SQL also varies to those<br />

created in the SAP HANA modeler.<br />

Structure of Analytic Privileges<br />

An analytic privilege consists of a set of restrictions against which user access to a particular attribute view,<br />

analytic view, or calculation view is verified. Each restriction controls the authorization check on the restricted<br />

view using a set of value filters. A value filter defines a check condition that verifies whether or not the values of<br />

the view (or view columns) qualify for user access.<br />

The specification of these restrictions is contained in an XML docum<strong>en</strong>t that conforms to a defined XML schema<br />

definition (XSD).<br />

The following restriction types can be used to restrict data access:<br />

● View<br />

328<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


● Activity<br />

● Validity<br />

● Attribute<br />

The following operators can be used to define value filters in the restrictions.<br />

Note: The activity and validity restrictions support only a subset of these operators.<br />

● IN <br />

● CP <br />

● EQ (=), LE (=) <br />

● BT <br />

● IS_NULL<br />

● NOT_NULL<br />

All of the above operators, except IS_NULL and NOT_NULL, accept empty strings (“”) as filter operands.<br />

The following are examples of how empty strings can be used with the filter operators:<br />

● For the IN operator: IN (“”, “A”, “B”) to filter on these exact values<br />

● As a lower limit in comparison operators, such as:<br />

○ BT (“”, “XYZ”), which is equival<strong>en</strong>t to NOT_NULL AND LE “XYZ”<br />

○ GT “”, which is equival<strong>en</strong>t to NOT_NULL<br />

○ LE “”, which is equival<strong>en</strong>t to EQ “”<br />

○ LT “”, which will always return false<br />

○ CP “”, which is equival<strong>en</strong>t to EQ “”<br />

The filter conditions CP “*” will also return rows with empty-string as values in the corresponding attribute.<br />

View Restriction<br />

This restriction specifies to which column view(s) the analytic privilege applies. It can be a single view, a list of<br />

views, or all views. An analytic privilege must have exactly one cube restriction.<br />

Example: IN ("Cube1", "Cube2")<br />

Note: Wh<strong>en</strong> an analytic view is created in the SAP HANA modeler, automatically-g<strong>en</strong>erated views are<br />

included automatically in the cube restriction.<br />

Activity Restriction<br />

This restriction specifies the activities that the user is allowed to perform on the restricted view(s), for example,<br />

read data. An analytic privilege must have exactly one activity restriction.<br />

Example: EQ "read", or EQ "edit"<br />

Note: Curr<strong>en</strong>tly, all analytic privileges created in the SAP HANA modeler are automatically configured to<br />

restrict access to READ activity only. This corresponds to SQL SELECT queries. This is due to the fact that<br />

the attribute, analytic, and calculation views are read-only views. This restriction is therefore not<br />

configurable.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 329


Validity Restriction<br />

This restriction specifies the validity period of the analytic privilege. An analytic privilege must have exactly one<br />

validity restriction.<br />

Example: GT 2010/10/01, 01:01:00.000<br />

Note: All analytic privileges automatically become immediately valid and have unlimited validity wh<strong>en</strong><br />

activated in the SAP HANA modeler. This restriction is therefore not configurable.<br />

Attribute Restriction<br />

This restriction specifies the value range that the user is permitted to access. Attribute restrictions are applied to<br />

the actual attributes of a view. Each attribute restriction is relevant for one dim<strong>en</strong>sion attribute, which can contain<br />

multiple value filters. Each value filter repres<strong>en</strong>ts a logical filter condition.<br />

Value filters for attribute restrictions can be static or dynamic.<br />

● A static value filter consists of an operator and either a list of values as the filter operands or a single value as<br />

the filter operand. All data types are supported except those for LOB data types (CLOB, BLOB, and NCLOB).<br />

For example, a value filter (EQ 2006) can be defined for an attribute YEAR in a dim<strong>en</strong>sion restriction to filter<br />

accessible data using the condition YEAR=2006 for pot<strong>en</strong>tial users.<br />

Note: Only attributes, not aggregatable facts (for example, measures or key figures) can be used in<br />

dim<strong>en</strong>sion restrictions for analytic views.<br />

● A dynamic value filter consists of an operator and a stored procedure call that determines the operand value<br />

at runtime.<br />

For example, a value filter (IN (GET_MATERIAL_NUMBER_FOR_CURRENT_USER())) is defined for the<br />

attribute MATERIAL_NUMBER. This filter indicates that a user with this analytic privilege is only allowed to<br />

access material data with the numbers returned by the procedure<br />

GET_MATERIAL_NUMBER_FOR_CURRENT_USER.<br />

Note: If you create an analytic privilege in the SAP HANA modeler, it is not possible to specify a<br />

procedure call wh<strong>en</strong> defining restrictions. If you want to create analytic privileges with dynamic filter<br />

conditions, you must do so using SQL.<br />

It is possible to combine static and dynamic value filters.<br />

An analytic privilege can have multiple attribute restrictions, but it must have at least one attribute restriction. An<br />

attribute restriction must have at least one value filter. Therefore, if you want to permit access to the whole<br />

cont<strong>en</strong>t of a restricted view, th<strong>en</strong> the attribute restriction must specify all attributes.<br />

Similarly, if you want to permit access to the whole cont<strong>en</strong>t of the view with the corresponding attribute, th<strong>en</strong> the<br />

value filter must specify all values.<br />

330<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


The SAP HANA modeler automatically implem<strong>en</strong>ts this specification if you do not select either an attribute<br />

restriction or a value filter. However, if you create the analytic privilege using SQL, you must make the<br />

specification manually.<br />

Example 1:<br />

<br />

<br />

<br />

Example 2:<br />

<br />

<br />

<br />

<br />

<br />

Logical Combination of Restrictions and Filter Conditions<br />

The result of user queries on restricted views is filtered according to the conditions specified by the analytic<br />

privileges granted to the user as follows:<br />

● Multiple analytic privileges are combined with the logical operator OR.<br />

● Within one analytic privilege, all attribute restrictions are combined with the logical operator AND.<br />

● Within one attribute restriction, all value filters on the attribute are combined with the logical operator OR.<br />

You create two analytic privileges AP1 and AP2. AP1 has the following attribute restrictions:<br />

● Restriction R11 restricting the attribute Year with the value filters (EQ 2006) and (BT 2008,<br />

2010)<br />

● Restriction R12 restricting the attribute Country with the value filter (IN ("USA", "Germany"))<br />

Giv<strong>en</strong> that multiple value filters are combined with the logical operator OR and multiple attribute<br />

restrictions are combined with the logical operator AND, AP1 g<strong>en</strong>erates the condition:<br />

((Year = 2006) OR (Year BT 2008 and 2010)) AND (Country IN ("USA",<br />

"Germany"))<br />

AP2 has the following restriction:<br />

Restriction R21 restricting the attribute Country with the value filter (EQ "France")<br />

AP2 g<strong>en</strong>erates the condition:<br />

(Country = "France")<br />

Any query of a user who has be<strong>en</strong> granted both AP1 and AP2 will therefore be app<strong>en</strong>ded with the following<br />

WHERE clause:<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 331


((Year = 2006) OR (Year BT 2008 and 2010)) AND (Country IN ("USA",<br />

"Germany"))) OR (Country = "France")<br />

Dynamic Value Filters in the Attribute Restriction of Analytic Privileges<br />

The attribute restriction of an analytic privilege specifies the value range that the user is permitted to access using<br />

value filters. In addition to static scalar values, stored procedures can be used to define filters. This allows userspecific<br />

filter conditions to be determined dynamically in runtime, for example, by querying specified tables or<br />

views. As a result, the same analytic privilege can be applied to many users, while the filter values for authorization<br />

can be updated and changed indep<strong>en</strong>d<strong>en</strong>tly in the relevant database tables. In addition, application <strong>dev</strong>elopers<br />

have full control not only to design and manage such filter conditions, but also to design the logic for obtaining the<br />

relevant filter values for the individual user at runtime.<br />

Procedures used to define filter conditions must have the following properties:<br />

● They must be DEFINER procedures.<br />

● They must be read-only procedures.<br />

● A procedure with a predefined signature must be used. The following conditions apply:<br />

○ No input parameter<br />

○ Only 1 output parameter as table type with one single column for the IN operator<br />

○ Only 1 output parameter of a scalar type for all unary operators, such as EQUAL<br />

○ Only 2 output parameters of a scalar type for the binary operator BETWEEN<br />

● Only the following data types are supported as the scalar types and the data type of the column in the table<br />

type:<br />

○ Date/Time types DATE, TIME, SECONDDATE, and TIMESTAMP<br />

○ Numeric types TINYINT, SMALLINT, INTEGER, BIGINT, DECIMAL, REAL, and DOUBLE<br />

○ Character string types VARCHAR and NVARCHAR<br />

○ Binary type VARBINARY<br />

Wh<strong>en</strong> the procedure is executed as part of the authorization check in runtime, the following constraints apply:<br />

● The user who must be authorized is the database user who executes the query accessing a secured view. This<br />

is the session user. The database table or view used in the procedure should therefore contain a column to<br />

store the user name of the session user. The procedure can th<strong>en</strong> filter by this column using the SQL function<br />

SESSION_USER. This table or view should only be accessible to the procedure owner.<br />

● The user executing the procedure is the _SYS_REPO user. In the case of procedures activated in the SAP<br />

HANA modeler, _SYS_REPO is the owner of the procedures. For procedures created in SQL, the EXECUTE<br />

privilege on the procedure must be granted to the _SYS_REPO user.<br />

● If the procedure fails to execute, the user’s query stops processing and a “Not authorized” error is returned .<br />

The root cause can be investigated in the error trace file of the indexserver,<br />

indexserver_alert_.trc.<br />

Wh<strong>en</strong> designing and implem<strong>en</strong>ting procedures as filter for dynamic analytic privileges, bear the following in mind:<br />

● To avoid a recursive analytic privilege check, the procedures should only select from database tables or views<br />

that are not subject to an authorization check based on analytic privileges. In particular, views activated in the<br />

SAP HANA modeler are to be avoided completely as they are automatically registered for the analytic<br />

privilege check.<br />

● The execution of procedures in analytic privileges slows down query processing compared to analytic<br />

privileges containing only static filters. Therefore, procedures used in analytic privileges must be designed<br />

carefully.<br />

332<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


Runtime Authorization Check of Analytic Privileges<br />

Wh<strong>en</strong> a user requests access to data stored in an attribute, analytic, or calculation view, an authorization check<br />

based on analytic privileges is performed and the data returned to the user is filtered accordingly. Access to a<br />

view and the way in which results are filtered dep<strong>en</strong>d on whether the view is indep<strong>en</strong>d<strong>en</strong>t or associated with other<br />

modeling views (dep<strong>en</strong>d<strong>en</strong>t views).<br />

Indep<strong>en</strong>d<strong>en</strong>t Views<br />

The authorization check for a view that is not defined on another modeling view is as follows:<br />

1. The user requests access to an individual view, for example with a SELECT query.<br />

This is possible if the both of the following prerequisites are met:<br />

○ The user has be<strong>en</strong> granted the SQL privilege SELECT on the view or the schema in which it is located.<br />

○ The user has be<strong>en</strong> granted an analytic privilege that is applicable to the view. An analytic privilege is<br />

applicable to a view if it contains the view in the view restriction and at least one filter on one attribute of<br />

the view.<br />

Note: The user does not require the SELECT privilege on the underlying base tables or views of the<br />

modeling view.<br />

2. The authorization check determines the analytic privileges that are relevant for the curr<strong>en</strong>t user and view.<br />

Relevant analytic privileges are those that met all of the following criteria:<br />

○ Analytic privileges previously granted to the user, either directly or indirectly through a role<br />

○ Analytic privileges with a view restriction that includes the accessed view<br />

○ Analytic privileges with a curr<strong>en</strong>tly valid validity restriction<br />

Note: This check is always positive for analytic privileges created and activated in the SAP HANA<br />

modeler.<br />

○ Analytic privileges with an activity restriction covering the activity requested by the query are considered<br />

Note: This check is always positive for analytic privileges created and activated in the SAP HANA<br />

modeler.<br />

○ Analytic privileges with dim<strong>en</strong>sion restrictions covering some of the view’s attributes<br />

3. If no relevant analytic privileges are found, the user’s queries are rejected with a “Not authorized” error.<br />

This means that ev<strong>en</strong> though the user has the SELECT privilege on the view, access is not possible.<br />

If the user does have a relevant analytic privilege but does not have the SELECT privilege on the view, access<br />

is also not possible. If relevant analytic privileges are found, the authorization check evaluates the value filters<br />

specified in the dim<strong>en</strong>sion restrictions and pres<strong>en</strong>ts the appropriate data to the user.<br />

Note: Multiple dim<strong>en</strong>sion restrictions and/or multiple value filters are combined as described in the<br />

section on the structure of analytic privileges.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 333


Dep<strong>en</strong>d<strong>en</strong>t Views<br />

Analytic views can be defined on attribute views, and calculation views that are defined on other modeling views. If<br />

a user requests access to such a view that is dep<strong>en</strong>d<strong>en</strong>t on another view, the behavior of the authorization check<br />

varies as follows:<br />

● Analytic view associated with attribute view(s)<br />

A user can access an analytic view with associated attribute view(s) if one of the following prerequisites is<br />

met:<br />

○ The user has be<strong>en</strong> granted an analytic privilege on the analytic view itself.<br />

○ The user has be<strong>en</strong> granted an analytic privilege on an underlying attribute view.<br />

Result filtering is performed by a logical OR combination of all analytic privileges found on the analytic view<br />

and on its underlying attribute views.<br />

An analytic privilege on an analytic view with dep<strong>en</strong>d<strong>en</strong>t attributes therefore does not restrict data access to<br />

the view, but rather increases it because the privilege on the analytic view is combined with privileges defined<br />

on the associated attribute views using logical OR.<br />

● Calculation view based on other view(s)<br />

A user can access a calculation view based on other view(s) if both of the following prerequisites are met:<br />

○ The user has be<strong>en</strong> granted an analytic privilege on the calculation view.<br />

○ The user has be<strong>en</strong> granted an analytic privilege on all underlying views if they are attribute, analytic, or<br />

calculation views.<br />

Result filtering is performed for each individual view. The underlying attribute, analytic, calculation views are<br />

authorized and filtered using the analytic privileges relevant for these views. The result of the top-level<br />

calculation view is th<strong>en</strong> filtered using the analytic privileges defined on the calculation view itself.<br />

An analytic privilege on a calculation view based on other view(s) therefore further restricts data access to the<br />

calculation view as the privilege is evaluated on top of the result filtered by the analytic privileges defined on<br />

the underlying views (corresponding to a logical AND combination).<br />

Creation and Managem<strong>en</strong>t of Analytic Privileges<br />

Analytic privileges can be created, dropped, and changed in the SAP HANA modeler and using SQL statem<strong>en</strong>ts.<br />

The SAP HANA modeler should be used in all cases except if you are creating analytic privileges that use<br />

dynamic procedure-based value filters.<br />

To create analytic privileges, the system privilege CREATE STRUCTURED PRIVILEGE is required. To drop analytic<br />

privileges, the system privilege STRUCTUREDPRIVILEGE ADMIN is required.<br />

In the SAP HANA modeler, repository objects are technically created by the technical user _SYS_REPO, which by<br />

default has the system privileges for both creating and dropping analytic privileges. To be able to create, activate,<br />

drop, and redeploy analytic privileges in the SAP HANA modeler therefore, a database user requires the package<br />

privileges REPO.EDIT_NATIVE_OBJECTS and REPO.ACTIVATE_NATIVE_OBJECTS for the relevant package.<br />

334<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


Implications of Creating Analytic Privileges Using SQL<br />

The SAP HANA modeler is the recomm<strong>en</strong>ded method for creating and managing analytic privileges. However, it is<br />

necessary to use SQL to implem<strong>en</strong>t those features of analytic privileges not available in the modeler, that is,<br />

dynamic, procedure-based value filters as attribute restrictions.<br />

In the SAP HANA modeler, analytic privileges are created as design-time repository objects owned by the<br />

technical user _SYS_REPO. They must be activated to become runtime objects available in the database. Analytic<br />

privileges created using SQL statem<strong>en</strong>ts are activated immediately. However, they are also owned by the<br />

database user who executes the SQL statem<strong>en</strong>ts. This is the main disadvantage of using SQL to create analytic<br />

privileges. If the database user who created the analytic privilege is deleted, all objects owned by the user will also<br />

be deleted. Therefore, if you are using SQL to create analytic privileges, we recomm<strong>en</strong>d that you create a<br />

dedicated database user (that is, a technical user) for this purpose to avoid the pot<strong>en</strong>tial loss of complex modeled<br />

privileges.<br />

An additional disadvantage of creating analytic privileges using SQL is that these analytic privileges are not in the<br />

SAP HANA repository and they cannot be transported betwe<strong>en</strong> differ<strong>en</strong>t systems.<br />

Granting and Revoking Analytic Privileges<br />

Analytic privileges are granted and revoked as part of user provisioning.<br />

If the analytic privilege was created and activated using the SAP HANA modeler, the analytic privilege is owned by<br />

the _SYS_REPO user. Therefore, to be able to grant and revoke the analytic privilege, a user needs the privilege<br />

EXECUTE on the procedures GRANT_ACTIVATED_ANALYTICAL_PRIVILEGE and<br />

REVOKE_ACTIVATED_ANALYTICAL_PRIVILEGE respectively.<br />

If the analytic privilege was created using SQL, only the owner (that is, the creator) of the analytic privilege can<br />

grant and revoke it.<br />

Related Links<br />

SAP HANA Administration Guide<br />

SAP HANA Developer Guide<br />

Example: Creating an Analytic Privilege with Dynamic Value Filter<br />

This example shows you how to create an analytic privilege that contains a dynamic procedure-based value filter<br />

and a fixed value filter in the attribute restriction.<br />

Assume you want to restrict access to product data in secured views as follows:<br />

● Users should only see products beginning with ELECTRO, or<br />

● Users should only see products for which they are specifically authorized. This information is contained in the<br />

database table PRODUCT_AUTHORIZATION_TABLE in the schema AUTHORIZATION.<br />

To be able to implem<strong>en</strong>t the second filter condition, you need to create a procedure that will determine which<br />

products a user is authorized to see by querying the table PRODUCT_AUTHORIZATION_TABLE.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 335


1. Create the table type for the output parameter of the procedure:<br />

CREATE TYPE "AUTHORIZATION"."PRODUCT_OUTPUT" AS TABLE("PRODUCT" int);<br />

2. Create the table that the procedure will use to check authorization:<br />

CREATE TABLE "AUTHORIZATION","PRODUCT_AUTHORIZATION_TABLE" ("USER_NAME"<br />

NVARCHAR(128), "PRODUCT" int);<br />

3. Create the procedure that will determine which products the database user executing the query is authorized<br />

to see based on information contained in the product authorization table:<br />

CREATE PROCEDURE "AUTHORIZATION"."DETERMINE_AUTHORIZED_PRODUCT_FOR_USER"<br />

(OUT VAL "AUTHORIZATION"."PRODUCT_OUTPUT")<br />

LANGUAGE SQLSCRIPT SQL SECURITY DEFINER READS SQL DATA AS<br />

BEGIN<br />

VAL = SELECT PRODUCT FROM<br />

"AUTHORIZATION"."PRODUCT_AUTHORIZATION_TABLE” WHERE USER_NAME =<br />

SESSION_USER;<br />

END;<br />

Note: The session user is the database user who is executing the query to access a secured view. This<br />

is therefore the user whose privileges must be checked. For this reason, the table or view used in the<br />

procedure should contain a column to store the user name so that the procedure can filter on this<br />

column using the SQL function SESSION_USER.<br />

4. Create the analytic privilege:<br />

336<br />

CREATE STRUCTURED PRIVILEGE '<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

';<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


Now wh<strong>en</strong> a database user requests access to a secured view containing product information, the data returned<br />

will be filtered according to the following condition:<br />

(product LIKE "ELECTRO*" OR product IN<br />

(AUTHORIZATION.DETERMINE_AUTHORIZED_PRODUCT_FOR_USER())<br />

12.4.5 Creating Analytic Privileges<br />

● To create, activate and drop the privilege you have system privileges CREATE STRUCTURED PRIVILEGE and<br />

STRUCTUREDPRIVILEGE ADMIN.<br />

● Make sure that both CREATE STRUCTURED PRIVILEGE and STRUCTUREDPRIVILEGE ADMIN are correctly<br />

owned by SYS_REPO user.<br />

● To activate and redeploy analytic privileges in the Modeler, a database user requires corresponding repository<br />

privileges, namely REPO.EDIT_NATIVE_OBJECTS and REPO.ACTIVATE_NATIVE_OBJECTS<br />

You apply analytic privileges wh<strong>en</strong> business users access values with certain combinations of dim<strong>en</strong>sion<br />

attributes. You can use analytic privileges to partition data among various users sharing the same data<br />

foundation. You can define restrictions for a selected group of models or apply them to all cont<strong>en</strong>t models across<br />

packages.<br />

After activation, an analytic privilege needs to be assigned to a user before taking any effect. The user views the<br />

filtered data based on the restrictions defined in the analytic privilege. If no analytic privilege applicable for models<br />

is assigned to a user, he cannot access the model. If a user is assigned to multiple analytic privileges, the<br />

privileges are combined with OR conditions.<br />

Remember: In addition to the analytic privileges, a user needs SQL Select privileges on the g<strong>en</strong>erated<br />

column views.<br />

The g<strong>en</strong>erated column views adhere to the following naming conv<strong>en</strong>tions:<br />

For a view “MyView” in package “p1.p2” (i.e. subpackage p2 of package p1) the g<strong>en</strong>erated column view lies in<br />

schema _SYS_BIC and is named “_SYS_BIC”.”p1.p2/MyView”. Ensure that the users who are allowed to see the<br />

view have select privileges on the view (or the <strong>en</strong>tire schema _SYS_BIC).<br />

Note: Multiple restrictions applied on the same column are combined by OR. However, restrictions across<br />

several columns are always combined by AND.<br />

1. Set Parameters for the Analytic Privilege<br />

a) In the Modeler perspective, expand the system node from the Navigator panel.<br />

b) Expand the Cont<strong>en</strong>t node.<br />

c) Select the required package.<br />

d) From the context m<strong>en</strong>u, choose New Analytic Privilege .<br />

1. Enter a name and description for the analytic privilege, and choose Next.<br />

2. Select the information models that you want to use for applying restrictions.<br />

3. Choose Finish.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

Tip: You can choose to add more models in the editor pane.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 337


2. Add Attributes<br />

a) If you want to add restrictions for all models, select the Applicable to all Information Models option.<br />

Note: If you do not select this option, the restrictions you create apply only to the secured list of<br />

models available in the Refer<strong>en</strong>ce Models panel that you selected above.<br />

b) In the Associated Attributes Restrictions panel, choose Add to select the attributes for defining<br />

restrictions.<br />

c) Choose OK.<br />

3. Assign Restrictions<br />

Note: If you do not add any attributes for restrictions there will be unrestricted access to the<br />

selected models or to all the models (if Applicable to all the Information Models option is selected).<br />

a) In the Assign Restrictions pane, choose Add to add value restriction for the selected attributes.<br />

b) Select the required operator and <strong>en</strong>ter a value (manually or via Value Help dialog).<br />

Remember: To activate the analytic privilege, you must assign a minimum of one restriction to each<br />

attribute.<br />

4. Activate the analytic privilege using the Save and Activate option in the editor.<br />

Note: Select the Save and Activate All option to activate the privilege along with all the required<br />

objects.<br />

5. Assign the privilege to a user<br />

338<br />

a) In the Navigator panel, navigate the Security Authorizations Users node.<br />

b) Select a user.<br />

c) In the context m<strong>en</strong>u, choose Op<strong>en</strong>.<br />

d) Choose Analytic Privileges tab page, and add the privilege.<br />

e) From the editor toolbar, choose Deploy.<br />

● Consider an analytic view (without fields coming from attribute views) or a calculation view SALES,<br />

which is added as part of an analytic privilege’s secured models having the following data.<br />

CUST_ID CUST_GROUP SALES<br />

1 GRP1 1000<br />

2 GRP2 1500<br />

3 GRP3 1200<br />

1 GRP4 1300<br />

If you create a restriction on column CUST_ID to filter data for CUST_ID 1 and 2, the conditions are<br />

combined with OR and the data available for a user is:<br />

CUST_ID CUST_GROUP SALES<br />

1 GRP1 1000<br />

2 GRP2 1500<br />

1 GRP4 1300<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


If you create restrictions on columns CUST_ID and CUST_GROUP such as CUST_ID = 1 and<br />

CUST_GROUP = 1, the conditions are combined with AND, and the data available for a user is:<br />

CUST_ID CUST_GROUP SALES<br />

1 GRP1 1000<br />

Note:<br />

○ The technical name used for attributes of calculation views and private attributes of<br />

analytic views, is the same as that of the attribute name. H<strong>en</strong>ce any restriction applied to<br />

a private attribute of an analytic or calculation view attribute is also applied to any other<br />

private attribute of an analytic view and calculation view attribute having the same name.<br />

In the above example, if there is any other analytic view or calculation view, which is part<br />

of a privilege’s secured list of models, and has a field called “CUST_ID” (not coming from<br />

any attribute view), the data for these privileges also gets restricted.<br />

○ If Applicable to all information models is selected, any analytic view/calculation view (ev<strong>en</strong><br />

if not part of the secured models) which has a (private) attribute called “CUST_ID”, the<br />

data for these privileges also get restricted.<br />

○ The behavior for the calculation view is the same as that of the analytic view described<br />

above.<br />

● Consider an attribute view CUSTOMER which is part of an analytic privilege’s secured list of models<br />

having the following data.<br />

CUST_ID COUNTRY MANDT<br />

1 IN 1<br />

2 IN 1<br />

3 US 1<br />

1 DE 2<br />

If you create a restriction on column CUST_ID to filter data for CUST_ID 1 and 2, the conditions are<br />

combined with OR and the data is shown as follows:<br />

CUST_ID COUNTRY MANDT<br />

1 IN 1<br />

2 IN 1<br />

1 DE 2<br />

If you create restrictions on columns CUST_ID and COUNTRY such as CUST_ID = 1 and COUNTRY =<br />

IN, the conditions are combined with AND, and the data available for a user is:<br />

CUST_ID COUNTRY MANDT<br />

1 IN 1000<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 339


Related Links<br />

Note:<br />

○ The technical name used for an attribute view attribute is /$. H<strong>en</strong>ce, in the above example, the technical name for<br />

CUST_ID is mypackage/CUSTOMER$CUST_ID. This implies that if there is any other<br />

attribute view “STORE” which is a part of the analytic privilege and has CUST_ID as its<br />

attribute, it will not get restricted.<br />

○ Any analytic view that is part of the privilege’s secured list of models and has this attribute<br />

view as its required object, gets restricted using the technical name. In the example<br />

above, if an analytic view contains the attribute views CUSTOMER and STORE, both<br />

CUST_ID attributes are handled indep<strong>en</strong>d<strong>en</strong>tly, because their internal technical name<br />

used for the privilege check are mypackage/CUSTOMER$CUST_ID and<br />

myotherpackage/STORE$UST_ID.<br />

○ If Applicable to all information models is selected, any analytic view (ev<strong>en</strong> if not part of the<br />

secured models) having this attribute view as its required object, also gets restricted.<br />

Structure of Analytic Privileges [page 328]<br />

An analytic privilege consists of a set of restrictions against which user access to a particular attribute view,<br />

analytic view, or calculation view is verified. Each restriction controls the authorization check on the restricted<br />

view using a set of value filters. A value filter defines a check condition that verifies whether or not the values<br />

of the view (or view columns) qualify for user access.<br />

Runtime Authorization Check of Analytic Privileges [page 333]<br />

Wh<strong>en</strong> a user requests access to data stored in an attribute, analytic, or calculation view, an authorization<br />

check based on analytic privileges is performed and the data returned to the user is filtered accordingly.<br />

Access to a view and the way in which results are filtered dep<strong>en</strong>d on whether the view is indep<strong>en</strong>d<strong>en</strong>t or<br />

associated with other modeling views (dep<strong>en</strong>d<strong>en</strong>t views).<br />

Dynamic Value Filters in the Attribute Restriction of Analytic Privileges [page 332]<br />

The attribute restriction of an analytic privilege specifies the value range that the user is permitted to access<br />

using value filters. In addition to static scalar values, stored procedures can be used to define filters. This<br />

allows user-specific filter conditions to be determined dynamically in runtime, for example, by querying<br />

specified tables or views. As a result, the same analytic privilege can be applied to many users, while the filter<br />

values for authorization can be updated and changed indep<strong>en</strong>d<strong>en</strong>tly in the relevant database tables. In<br />

addition, application <strong>dev</strong>elopers have full control not only to design and manage such filter conditions, but also<br />

to design the logic for obtaining the relevant filter values for the individual user at runtime.<br />

Creation and Managem<strong>en</strong>t of Analytic Privileges [page 334]<br />

Analytic privileges can be created, dropped, and changed in the SAP HANA modeler and using SQL<br />

statem<strong>en</strong>ts. The SAP HANA modeler should be used in all cases except if you are creating analytic privileges<br />

that use dynamic procedure-based value filters.<br />

Example: Creating an Analytic Privilege with Dynamic Value Filter [page 335]<br />

This example shows you how to create an analytic privilege that contains a dynamic procedure-based value<br />

filter and a fixed value filter in the attribute restriction.<br />

340<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


12.4.6 Granting Privileges to Users<br />

Privileges can be granted to database users either directly, or indirectly through roles that they have be<strong>en</strong><br />

granted. In this case, the privileges are inherited. Roles are the standard mechanism of granting privileges to<br />

users.<br />

To be able to grant and revoke privileges and roles to and from users and roles, the following prerequisites must<br />

be met:<br />

Action Prerequisite<br />

Grant system privilege, object privilege, or package<br />

privilege to user or role<br />

Granting user must have the privilege being granted<br />

and be authorized to grant it to other users and roles<br />

Grant analytic privilege to user or role Granting user must have the object privilege EXECUTE<br />

Grant object privilege on activated modeled objects,<br />

such as calculation views, to user or role<br />

on the procedure<br />

GRANT_ACTIVATED_ANALYTICAL_PRIVILEGE<br />

Granting user must have the object privilege EXECUTE<br />

on the procedure<br />

GRANT_PRIVILEGE_ON_ACTIVATED_CONTENT<br />

Grant role created in runtime to user or role ● Granting user must have the role being granted<br />

and be authorized to grant it to other users and<br />

roles, or<br />

● Granting user must be have the system privilege<br />

ROLE ADMIN<br />

Grant role created in the repository to user or role Granting user must have the object privilege EXECUTE<br />

on the procedure GRANT_ACTIVATED_ROLE<br />

Grant application privilege Granting user must have the object privilege EXECUTE<br />

Grant object privilege on schema containing activated<br />

modeled objects, such as calculation views, to user or<br />

role<br />

Revoke system privilege, object privilege, or package<br />

privilege from user or role<br />

Revoke object privilege on schema activated<br />

containing modeled objects, such as calculation views,<br />

from user or role<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

on the procedure GRANT_APPLICATION_PRIVILEGE<br />

Granting user must have the object privilege EXECUTE<br />

on the procedure<br />

GRANT_SCHEMA_PRIVILEGE_ON_ACTIVATED_CONT<br />

ENT<br />

Revoking user must be the user who granted the<br />

privilege<br />

Revoking user must have the object privilege EXECUTE<br />

on the procedure<br />

REVOKE_SCHEMA_PRIVILEGE_ON_ACTIVATED_CON<br />

TENT<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 341


Action Prerequisite<br />

Revoke analytic privilege from user or role Revoking user must have the object privilege EXECUTE<br />

on the procedure<br />

REVOKE_ACTIVATED_ANALYTICAL_PRIVILEGE<br />

Revoke role created in runtime from user or role Revoking user must be the user who granted the role<br />

Revoke role created in the repository from user or role Revoking user must have the object privilege EXECUTE<br />

on the procedure REVOKE_ACTIVATED_ROLE<br />

Revoke application privilege Revoking user must have the object privilege EXECUTE<br />

Revoke object privilege on activated modeled objects,<br />

such as calculation views from user or role<br />

1. In the Navigator view, choose Security Users .<br />

on the procedure REVOKE_APPLICATION_PRIVILEGE<br />

Revoking user must have the object privilege EXECUTE<br />

on the procedure<br />

REVOKE_PRIVILEGE_ON_ACTIVATED_CONTENT<br />

2. Op<strong>en</strong> the relevant user and grant the required roles and privileges (object privileges, analytic privileges,<br />

system privileges, and package privileges) to the user.<br />

To grant a role or privilege, choose the button and search for the required role or privilege.<br />

To allow the user to pass on his or her privileges to other users, select Grantable to other users and roles.<br />

Note: This option is not available if you are granting a role that was created in the repository.<br />

Note: You cannot grant application privileges directly to users in the SAP HANA studio. It is<br />

recomm<strong>en</strong>ded that you grant application privileges to roles created in the repository and th<strong>en</strong> grant<br />

the role to the user.<br />

3. Choose the (Deploy) button to save the changes.<br />

Related Links<br />

SAP HANA Administration<br />

12.5 Application Access<br />

Wh<strong>en</strong> you <strong>dev</strong>elop and deploy applications in the context of SAP HANA Ext<strong>en</strong>ded Application Services (SAP<br />

HANA XS), you must define the application descriptors, which describe the framework in which the application<br />

runs. This application framework includes the root point in the package hierarchy where cont<strong>en</strong>t is to be served to<br />

cli<strong>en</strong>t requests, whether or not the application is permitted to expose data to cli<strong>en</strong>t requests, what kind of access<br />

to the data is allowed, and what if any privileges are required to perform actions on application-related packages<br />

and package cont<strong>en</strong>t. The application descriptors include the following files:<br />

● Application-descriptor file<br />

342<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations


The location of the application-descriptor file defines the root path of the resources exposed to cli<strong>en</strong>t<br />

requests by the application you <strong>dev</strong>elop. You can further restrict access using the application-access and<br />

application-privileges files.<br />

● Application-Access File<br />

The application-access file <strong>en</strong>ables you to specify who or what is authorized to access the cont<strong>en</strong>t exposed by<br />

a SAP HANA XS application package and what cont<strong>en</strong>t they are allowed to see. You can use keywords in the<br />

application-access file to set auth<strong>en</strong>tication rules, define package-privilege levels (for example, EXECUTE or<br />

ADMIN), specify the connection security level (for example, SSL/HTTPS), allow or prev<strong>en</strong>t the creation of<br />

<strong>en</strong>tity tags (Etags), and so on. You can also define rewrite rules for URLs exposed by an application, for<br />

example, to hide internal details of URL paths from external users, cli<strong>en</strong>ts, and search <strong>en</strong>gines.<br />

● Application-Privileges File<br />

The application-privileges file <strong>en</strong>ables you to define the authorization privileges required for access to an SAP<br />

HANA XS application, for example, to start the application (EXECUTE) or to perform administrative actions on<br />

an application (ADMIN). The privileges defined here are activated for a particular application in the<br />

application-access file. These privileges can be checked by an application at runtime. Privileges defined apply<br />

to the package where the privileges file is located as well as any packages further down the package hierarchy<br />

unless an additional privileges file is pres<strong>en</strong>t, for example, in a subpackage.<br />

Related Links<br />

Note: An additional access-related file, the SQL-connection configuration file, <strong>en</strong>ables you to execute SQL<br />

statem<strong>en</strong>ts from inside your SAP HANA XS JavaScript application with cred<strong>en</strong>tials that are differ<strong>en</strong>t to the<br />

cred<strong>en</strong>tials of the requesting user. Each SQL-connection configuration object has a unique name, and the<br />

administrator can assign specific, individual database users to this configuration.<br />

The Application-Descriptor File [page 49]<br />

Each application that you want to <strong>dev</strong>elop and deploy on SAP HANA Ext<strong>en</strong>ded Application Services (SAP<br />

HANA XS) must have an application descriptor file. The application descriptor is the core file that you use to<br />

describe an application's framework within SAP HANA XS.<br />

The Application-Access File [page 50]<br />

SAP HANA XS <strong>en</strong>ables you to define access to each individual application package that you want to <strong>dev</strong>elop<br />

and deploy.<br />

The Application-Privileges File [page 59]<br />

In SAP HANA Ext<strong>en</strong>ded Application Services (SAP HANA XS), the application-privileges (.xssprivileges)<br />

file can be used to create or define the authorization privileges required for access to an SAP HANA XS<br />

application, for example, to start the application or to perform administrative actions on an application. These<br />

privileges can be checked by an application at runtime.<br />

SAP HANA Developer Guide<br />

Setting Up Roles and Authorizations<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 343


13 Implem<strong>en</strong>ting Lifecycle<br />

Managem<strong>en</strong>t<br />

13.1 SAP HANA Delivery Units<br />

In SAP HANA, the delivery unit (DU) is the vehicle that lifecycle managem<strong>en</strong>t (LCM) uses to ship one or more<br />

software compon<strong>en</strong>ts from SAP (or a partner) to a customer .<br />

Delivery Units correspond to an "application" with versions, for which support packages and patches are<br />

delivered. Delivery units are not an equival<strong>en</strong>t to <strong>dev</strong>elopm<strong>en</strong>t classes; they are similar to Software Compon<strong>en</strong>t<br />

Versions in the Product Availability Matrix (PAM). You can also use the delivery unit to transport repository<br />

cont<strong>en</strong>t betwe<strong>en</strong> SAP HANA systems, for example, betwe<strong>en</strong> <strong>dev</strong>elopm<strong>en</strong>t systems or betwe<strong>en</strong> <strong>dev</strong>elopm<strong>en</strong>t and<br />

productive systems.<br />

Note: A governance plan exists for the naming of delivery units and the package structure.<br />

A delivery unit is id<strong>en</strong>tified by the following key properties:<br />

● V<strong>en</strong>dor<br />

Used primarily to define the id<strong>en</strong>tity of the company producing the software compon<strong>en</strong>t to deliver, for<br />

example, "sap". However, v<strong>en</strong>dor can also be used to specify any customer implem<strong>en</strong>ting SAP HANA. To<br />

create a delivery unit, it is a prerequisite to maintain a v<strong>en</strong>dor in your system.<br />

● Name<br />

Used to id<strong>en</strong>tify the software compon<strong>en</strong>t to be delivered<br />

Although a v<strong>en</strong>dor might provide multiple versions of a delivery unit in parallel, only one version of a delivery unit<br />

can be installed in a HANA system at any one time. In addition, duplicate names are not allowed for delivery units.<br />

SAP HANA treats delivery units and their versions as software compon<strong>en</strong>ts and software-compon<strong>en</strong>t versions.<br />

Software compon<strong>en</strong>ts and software-compon<strong>en</strong>t versions are usually shipped as part of a product (product<br />

version).<br />

Note: If you try to create a delivery unit using a name that already exists in your system, you will receive a<br />

validation error. A validation error also occurs if the check for a valid v<strong>en</strong>dor ID does not find a suitable<br />

<strong>en</strong>try.<br />

13.2 The SAP HANA Delivery-Unit Lifecycle<br />

In SAP HANA, lifecycle managem<strong>en</strong>t (LCM) includes all the activities you need to plan and perform to <strong>en</strong>sure that<br />

the software compon<strong>en</strong>ts you <strong>dev</strong>elop for SAP HANA Application Services are produced and shipped in a<br />

regulated way that meets the requirem<strong>en</strong>ts laid out for the SAP HANA platform.<br />

344<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Implem<strong>en</strong>ting Lifecycle Managem<strong>en</strong>t


For example, you need to plan, manage, and maintain the application versions you want to ship, and you need to<br />

<strong>en</strong>sure that a stable plan exists to provide support for existing and all future versions of your application.<br />

SAP HANA lifecycle managem<strong>en</strong>t uses the delivery unit (DU) is a vehicle to ship one or more software<br />

compon<strong>en</strong>ts from SAP (or a partner) to a customer. Delivery Units correspond to an "application" with versions,<br />

for which support packages and patches are delivered. You can also use the delivery unit to transport cont<strong>en</strong>t<br />

betwe<strong>en</strong> SAP HANA systems, for example, betwe<strong>en</strong> <strong>dev</strong>elopm<strong>en</strong>t systems or betwe<strong>en</strong> <strong>dev</strong>elopm<strong>en</strong>t and<br />

productive systems.<br />

Note: Delivery units are not to be confused with <strong>dev</strong>elopm<strong>en</strong>t classes; delivery units are similar to<br />

software compon<strong>en</strong>t versions in the Product Availability Matrix (PAM).<br />

The Application-Developm<strong>en</strong>t Lifecycle<br />

Application <strong>dev</strong>elopm<strong>en</strong>t on SAP HANA requires a server-c<strong>en</strong>tric life cycle for design-time objects, which are the<br />

<strong>dev</strong>elopm<strong>en</strong>t artifacts that you store in the SAP HANA repository. As an application <strong>dev</strong>eloper, you check out<br />

design-time cont<strong>en</strong>t from the repository and edit a copy of the checked-out artifact in the local file system on the<br />

your personal computer (PC). The following steps provide a brief, high-level overview of the <strong>dev</strong>elopm<strong>en</strong>t lifecycle<br />

for design-time cont<strong>en</strong>t:<br />

1. Check out design-time cont<strong>en</strong>t.<br />

Check out the package containing the design-time artifacts you want to work on (if the package already<br />

exists).<br />

2. Edit the design-time cont<strong>en</strong>t.<br />

Edit the copies of the design-time artifacts, which are stored in your SAP HANA repository "workspace" on<br />

your local file system; the local copies of the design-time artifacts are created during the checkout process.<br />

3. Commit changes to design-time cont<strong>en</strong>t.<br />

Committing the changes you have made to the design-time artifacts creates new versions of the artifacts in<br />

the SAP HANA repository. Note that id<strong>en</strong>tical (unchanged) versions of a file are not committed.<br />

4. Activate changes to design-time cont<strong>en</strong>t.<br />

Activating the changes you have made to the design-time artifacts makes these changes available to<br />

applications and other users, creating runtime objects where necessary.<br />

13.3 Exporting Delivery Units<br />

Exporting a delivery unit (with all packages and dep<strong>en</strong>d<strong>en</strong>cies) is the mechanism SAP HANA uses to <strong>en</strong>able the<br />

transfer of delivery units betwe<strong>en</strong> systems, for example, to transport application cont<strong>en</strong>t betwe<strong>en</strong> <strong>dev</strong>elopm<strong>en</strong>t<br />

systems of from a <strong>dev</strong>elopm<strong>en</strong>t system to a consolidation system.<br />

The SAP HANA studio includes a mechanism that <strong>en</strong>ables you to export and import delivery units. You can use the<br />

export feature to create an image of a delivery unit, which you can store either on the SAP HANA server or in the<br />

file system of a selected cli<strong>en</strong>t for future import to another system. You can also export <strong>dev</strong>elopm<strong>en</strong>t objects as<br />

an archive that you can s<strong>en</strong>d to SAP support or share with other members of the <strong>dev</strong>elopm<strong>en</strong>t team.<br />

SAP HANA Developer Guide<br />

Implem<strong>en</strong>ting Lifecycle Managem<strong>en</strong>t<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 345


To export a delivery unit, perform the following steps:<br />

1. Start the SAP HANA studio.<br />

Ensure that the SAP HANA studio is connected to the SAP HANA system hosting the delivery unit you want to<br />

export. If this is not the case, choose Select System... and change the system.<br />

2. In the File m<strong>en</strong>u, choose Export....<br />

3. Select the export destination.<br />

The export destination <strong>en</strong>ables you to specify the purpose for which you want to export the packages that<br />

make up the export archive. The option you choose determines the cont<strong>en</strong>ts of the export archive. In most<br />

cases, you would choose the Delivery Unit option, which includes everything you need to transport the<br />

application-<strong>dev</strong>elopm<strong>en</strong>t structure to another system . However, you can choose from the following<br />

additional export destination options:<br />

○ Developer Mode<br />

Includes most objects and data, but does not include translatable text bundles<br />

○ SAP Support Mode<br />

Includes only the active version of objects and any data required by SAP Support to reproduce an issue<br />

you have <strong>en</strong>countered and reported<br />

Specify the Delivery Unit option, for example, SAP HANA Cont<strong>en</strong>t > Delivery Unit<br />

4. Select the source system; the system you want to export the delivery unit from.<br />

In the Systems for export scre<strong>en</strong> area of the Delivery Unit dialog, select the SAP HANA system hosting the<br />

repository in which the delivery unit is located that you want to export and choose Next to confirm the<br />

selection..<br />

5. Select the delivery unit to export.<br />

For example, HANA_XS_DOCS<br />

6. Filter the cont<strong>en</strong>ts of the export package according to a specified time stamp.<br />

This step is optional. You can choose to export a complete delivery unit, or only those parts of a delivery unit<br />

that were changed during a specified time interval, which you define in the Filter by Time scre<strong>en</strong> area.<br />

7. Select a location for the exported delivery unit:<br />

a) Server<br />

The SAP HANA studio automatically selects a file location to export the delivery unit to.<br />

b) Cli<strong>en</strong>t<br />

Browse to the location in the local file-system where you want to store the exported delivery unit.<br />

8. Choose Next to confirm the settings.<br />

9. Choose Finish to start the export operation.<br />

10. Confirm the export operation succeeded.<br />

346<br />

You can browse to the location in the file system and examine the package cont<strong>en</strong>ts in a file explorer to make<br />

sure the package contains the required cont<strong>en</strong>t.<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Implem<strong>en</strong>ting Lifecycle Managem<strong>en</strong>t


13.4 Importing Delivery Units<br />

Importing a delivery-unit archive is the mechanism SAP HANA uses to <strong>en</strong>able you to transport delivery units<br />

betwe<strong>en</strong> systems, for example, to upload a delivery unit that was exported from another <strong>dev</strong>elopm<strong>en</strong>t system or<br />

saved as an archive on a local file system.<br />

The SAP HANA studio includes a mechanism that <strong>en</strong>ables you to export and import delivery units. To import a<br />

delivery unit, perform the following steps:<br />

1. Start the SAP HANA studio.<br />

Ensure that the SAP HANA studio is connected to the SAP HANA system hosting the delivery unit you want to<br />

export. If this is not the case, choose Select System... and change the system.<br />

2. In the File m<strong>en</strong>u, choose Import...<br />

3. Select the import mode. The choice you make determines the information you need to <strong>en</strong>ter in the next steps.<br />

The import mode <strong>en</strong>ables you to specify the purpose for which you want to import the packages that make up<br />

the import archive. In most cases, you would choose the Delivery Unit option, which includes everything you<br />

need to transport the application-<strong>dev</strong>elopm<strong>en</strong>t structure from another system . However, you can choose<br />

from the following additional import destination options:<br />

○ Data from local file<br />

Imports data from a comma-separated-list (CSV) file or a Microsoft Excel file stored on the local file<br />

system into a new or an existing table (and schema).<br />

○ Developer Mode<br />

Includes most objects and data, but does not include translatable text bundles. The import operation<br />

obeys the following rules regarding the cont<strong>en</strong>ts of the imported archive:<br />

○ If a package with the same name as the one to be imported already exists on the target system, but<br />

the package languages differ, objects are imported with a warning message.<br />

○ If a package with the same name as the one to be imported does not already exist on the target<br />

system, th<strong>en</strong> the respective package with its original language (fetched from the properties file) is<br />

created.<br />

○ For old objects where no related properties file exists, a package is created with its language set to<br />

the logon language of the curr<strong>en</strong>t import session.<br />

○ Import SAP NetWeaver BW Models<br />

Imports SAP NetWeaver Business Warehouse (SAP NetWeaver BW) models that are InfoCubes<br />

optimized forSAP HANA, SAP HANA-optimized DataStore objects, and Query Snapshot InfoProviders to<br />

the SAP HANA modeling <strong>en</strong>vironm<strong>en</strong>t.<br />

Note: With this option, you must maintain connection details for the BW system you want to<br />

import from, for example, host name, instance ID, cli<strong>en</strong>t number and so on. You can test the<br />

connection before continuing with the import operation.<br />

Specify the mode in which you want the data to be imported, for example, SAP HANA Cont<strong>en</strong>t > Delivery<br />

Unit .<br />

4. Select the target system; the system you want to import the delivery unit into.<br />

In the Systems for export scre<strong>en</strong> area of the Delivery Unit dialog, select the SAP HANA system hosting the<br />

repository into which you want to import the delivery unit and choose Next to confirm the selection.<br />

SAP HANA Developer Guide<br />

Implem<strong>en</strong>ting Lifecycle Managem<strong>en</strong>t<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 347


5. Select the file containing the delivery unit you want to import.<br />

a) Server<br />

The SAP HANA studio automatically displays a list of available files stored in the default location; use the<br />

drop-down list to choose the file you want to import.<br />

b) Cli<strong>en</strong>t<br />

Browse to the location in the local file-system where the file you want to import is stored.<br />

Before starting the import operation, the SAP HANA studio compares the cont<strong>en</strong>ts of the delivery unit<br />

selected for imported with the curr<strong>en</strong>t status of the repository on the target system and displays the results in<br />

the Object import simulation scre<strong>en</strong> area. Hover the cursor over the icons in the Status column for a brief<br />

description of the indicated status.<br />

6. Choose Finish to start the import operation.<br />

Use the Actions scre<strong>en</strong> area to specify what action to take if an imported object already exists in the target<br />

repository, for example:<br />

○ Overwrite inactive versions<br />

Overwrite inactive versions in your inactive workspace with objects from the imported delivery unit.<br />

○ Activate objects<br />

Activate objects imported from the delivery unit.<br />

○ Bypass validation<br />

Do not perform the cli<strong>en</strong>t-side validation check on imported objects.<br />

7. Check the status bar in the SAP HANA studio to follow the progress of the import operation.<br />

You can also check progress in the Curr<strong>en</strong>t tag page of the Job Log view.<br />

8. Confirm the import operation succeeded.<br />

13.5 Translating Delivery Units<br />

SAP HANA includes features that <strong>en</strong>able you to translate package-related metadata texts, for example labels and<br />

m<strong>en</strong>u items in the user interface. The translation typically occurs on a separate dedicated system.<br />

If you plan to translate the cont<strong>en</strong>ts of the new delivery unit you create, you must maintain translation details. The<br />

details include the connection to the translation system that the translation team use to store the localized<br />

versions of the translated data. The text to be translated is uploaded from the SAP HANA repository to the<br />

translation system and th<strong>en</strong> reimported to the repository after the translated text are complete. As part of the<br />

translation process for delivery units, you typically perform the following tasks<br />

1. Maintain translation details for each delivery unit<br />

Translation details includes both mandatory and optional information. Mandatory details to maintain include<br />

the terminology domain, for example, Financial Accounting (FI), or Production Planning (PP) and the name<br />

space for the text collection, which is used by the translation systems.<br />

2. Maintain the connection with the remote translation system<br />

You need to be able to exchange the translation texts betwe<strong>en</strong> SAP HANA and the translation system.<br />

3. Upload translation data to the translation system<br />

348<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Implem<strong>en</strong>ting Lifecycle Managem<strong>en</strong>t


4. Download translated text to the SAP HANA repository<br />

13.5.1 SAP HANA Delivery-Unit Translation Details<br />

The SAP HANA repository includes features for translating package-related metadata texts. If you plan to<br />

translate the cont<strong>en</strong>ts of the new delivery unit you create, you must maintain translation details.<br />

Translation details provide a brief overview of the type and curr<strong>en</strong>t status of the text objects to be translated, for<br />

example, by specifying the technical area of the new delivery unit and indicating the curr<strong>en</strong>t status of translation<br />

texts.<br />

Note: Translation text can include the following elem<strong>en</strong>ts: UI strings (m<strong>en</strong>us, dialog titles), error<br />

messages, and docum<strong>en</strong>tation, amongst other things. Package names and descriptions are also relevant<br />

for translation purposes as are the names and descriptions of database views, tables, columns, and so on.<br />

To make things easier for the translation team, you should maintain the following metadata for translation<br />

purposes; the metadata must be maintained at the package level:<br />

● Terminology domain (mandatory)<br />

The technical/product area with which your delivery unit (application) is associated, for example: AC<br />

(Accounting G<strong>en</strong>eral), FI (Financial Accounting), or PP (Production Planning and Control). This <strong>en</strong>ables<br />

translator teams to assign work to the most suitable experts, and allows the translators to make use of<br />

existing terminology databases. The terminology domain is used by SAP internal translation systems.<br />

● Text collection (mandatory)<br />

The name space for the text objects in the translation system. Technically, you can use any value, but the<br />

text-collection name space is similar to the package namespace used in SAP HANA, for example:<br />

"sap.<strong>hana</strong>.xs.docs". The value assigned to the Text collection field is used by SAP internal translation systems.<br />

● Hint<br />

An optional field that customers and partners can use to pass on notes concerning the text objects tagged for<br />

translation.<br />

● Text status<br />

An optional field that customers and partners can use to pass on information indicating the curr<strong>en</strong>t stage in<br />

the translation-review process of the text objects, for example: "New", "In review", "Reviewed", "Approved",<br />

"Published", and so on.<br />

13.5.2 Maintaining Translation Details<br />

Translation details provide a brief overview of the type and curr<strong>en</strong>t status of the text objects to be translated, for<br />

example, by specifying the technical area of the new delivery unit and indicating the curr<strong>en</strong>t status of translation<br />

texts.<br />

If you plan to translate the cont<strong>en</strong>ts of a delivery unit, you must maintain translation details. You can maintain the<br />

translation details wh<strong>en</strong> you create a new delivery unit or for existing delivery units. It is mandatory to maintain<br />

the following translation-related details:<br />

● Terminology domain<br />

The technical/product area with which your delivery unit (application) is associated, for example: AC<br />

(Accounting G<strong>en</strong>eral), FI, or PP.<br />

● Text collection<br />

SAP HANA Developer Guide<br />

Implem<strong>en</strong>ting Lifecycle Managem<strong>en</strong>t<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 349


The name space for the text objects in the translation system, for example, "sap.<strong>hana</strong>.xs.docs".<br />

1. In the SAP HANA studio, start the Modeler perspective.<br />

2. In the Navigator view, select the SAP HANA instance where the repository containing the delivery unit is<br />

located.<br />

3. Expand the Cont<strong>en</strong>t node until you can see the package whose translation details you want to maintain.<br />

4. Maintain the translation details for the selected delivery unit, as follows:<br />

a) Right-click the package whose translation details you want to maintain and choose Edit.<br />

b) Choose Translation >> to display the Translation Details scre<strong>en</strong> area at the bottom of the Edit Package<br />

Details dialog.<br />

c) Select a Terminology Domain from the drop-down list.<br />

d) Enter a Text collection name.<br />

e) Save the changes to the translation details.<br />

5. Save the changes to the delivery unit.<br />

6. Commit and activate the changes in the SAP HANA repository.<br />

350<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Implem<strong>en</strong>ting Lifecycle Managem<strong>en</strong>t


14 Using Database Cli<strong>en</strong>t Interfaces<br />

SAP HANA provides cli<strong>en</strong>t interfaces for connecting applications so they can retrieve and update data.<br />

SAP HANA provides many methods for applications to access its data. For example, a spreadsheet application<br />

could use ODBO to consume analytic views and <strong>en</strong>able users to create pivot tables, or a Web application could use<br />

OData interfaces to access the data and display it.<br />

SAP HANA can expose data with the following interfaces:<br />

● Cli<strong>en</strong>t interfaces, which are available as long as the SAP HANA cli<strong>en</strong>ts are installed:<br />

○ ODBC<br />

○ ODBO<br />

○ JDBC<br />

● Web-based interfaces, which must be defined by the application <strong>dev</strong>eloper, who determines what data to<br />

expose and to whom:<br />

○ OData<br />

○ XMLA<br />

○ Server-Side JavaScript<br />

Related Links<br />

SAP HANA Database - Cli<strong>en</strong>t Installation Guide<br />

Defining Web-based Data Access [page 164]<br />

SAP HANA ext<strong>en</strong>ded application services (SAP HANA XS) provide applications and application <strong>dev</strong>elopers<br />

with access to the SAP HANA database using a consumption model that is exposed via HTTP.<br />

14.1 Connecting via ODBC<br />

SAP HANA provides an ODBC driver for connecting applications to the database.<br />

Note: Make sure to use the 32-bit ODBC driver for 32-bit applications, and the 64-bit driver for 64-bit<br />

applications.<br />

1. Install the ODBC driver. The driver is installed as part of the SAP HANA cli<strong>en</strong>t installation.<br />

2. Write code to create a connection to the database. You can use one of the following methods:<br />

○ Connection String (SQLDriverConnect): Use a connection string in the form:<br />

DRIVER={};UID=;PWD=;<br />

SERVERNODE=:;<br />

should be one of the following:<br />

○ HDBODBC: For 64-bit applications<br />

○ HDBODBC32: For 32-bit applications<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 351


should be 315, for example, 30015, if the instance is 00.<br />

The following is an example of a connection string:<br />

DRIVER={HDBODBC};UID=myUser;PWD=myPassword;SERVERNODE=myServer:30015;<br />

○ DSN (SQLConnect): Create a data source by running the odbcad32.exe tool. You can run this via a<br />

Related Links<br />

command line or via the Control Panel /Administrative Tools /Data Sources (ODBC) .<br />

Note:<br />

○ The application is located in the system32 directory. To create a data source for the 32-bit<br />

driver on a 64-bit Microsoft Windows machine, run the tool from the SysWOW64 directory.<br />

In the DSN tab, choose Add, select the SAP HANA driver, and select Finish. The following appears:<br />

You cannot <strong>en</strong>ter a user name and password here. For the server and port, you can either <strong>en</strong>ter a key<br />

created using the SAP HANA user store (which defines the server, port, user name and password), or you<br />

can <strong>en</strong>ter a server and port (e.g., myServer:30015). If you <strong>en</strong>ter a server and port, th<strong>en</strong> the application<br />

must supply the user name and password wh<strong>en</strong> connecting.<br />

SAP HANA Database - Cli<strong>en</strong>t Installation Guide<br />

Using the User Store [page 352]<br />

14.1.1 Using the User Store<br />

The SAP HANA user store <strong>en</strong>ables you to store connection information for connecting to an SAP HANA system.<br />

Instead of <strong>en</strong>tering connection information each time you make a connection, you store the information, assign it<br />

a key, and use this key wh<strong>en</strong> making connections.<br />

This makes it easier to move betwe<strong>en</strong> systems (for example, wh<strong>en</strong> executing SQL from the command line), and<br />

also keeps connection information, including user names and passwords, in a secure place.<br />

The SAP HANA user store is part of the cli<strong>en</strong>t installation.<br />

352<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces


1. In a command line, run the following:<br />

hdbuserstore.exe set : <br />

The server, port, user name and password are now stored in the user store. The key is a string you use to refer<br />

to this set of connection information.<br />

2. Use the key to refer<strong>en</strong>ce a connection to a particular system. Always precede the key with an @, for example,<br />

@mykey.<br />

Use the key in the following ways:<br />

○ In the connection string, use the key for the SERVERNODE parameter, and do not include a user name<br />

and password, for example:<br />

SERVERNODE={@mykey};DRIVER={hdbodbc};<br />

○ In creating a DSN, <strong>en</strong>ter the key (for example, @mykey) for the server and port.<br />

○ In testing your connection (by running odbcreg -t hdbodbc), use the key (for example, @mykey) for<br />

the server and port. If the connection is successful, you get something like this:<br />

The response includes a sample connection string using the key.<br />

Related Links<br />

Testing the ODBC Installation [page 353]<br />

You can test the installation of the ODBC driver and your ability to connect by using the odbcreg tool, which<br />

is part of the ODBC installation.<br />

14.1.2 Testing the ODBC Installation<br />

You can test the installation of the ODBC driver and your ability to connect by using the odbcreg tool, which is<br />

part of the ODBC installation.<br />

1. Op<strong>en</strong> a command window.<br />

2. Start the odbcreg tool by <strong>en</strong>ter a command in the form: odbcreg -t hdbcodbc (for 64-bit driver) or<br />

odbcreg32 -t hdbcodbc32 (for 32-bit driver).<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 353


If the driver is installed properly, you should get the ODBC login scre<strong>en</strong>.<br />

Note: You can also run the command odbcreg -g or odbcreg32 -g to get a list of installed<br />

drivers. The SAP HANA driver is called HDBODBC.<br />

3. Test your ability to connect by <strong>en</strong>tering connection information (system, port, user name and password) and<br />

select OK. The tool closes and the results of the test are printed in the command window.<br />

You can also run odbcreg -g to get a list of installed ODBC drivers, and check to make sure that the SAP HANA<br />

driver (either HDBODBC or HDBODBC32) is installed.<br />

14.2 Connecting via JDBC<br />

SAP HANA provides a JDBC driver for connecting Java applications to the database.<br />

1. Install the JDBC driver.<br />

The driver (ngdbc.jar) is installed as part of the SAP HANA cli<strong>en</strong>t installation and is located at:<br />

○ C:\Program Files\sap\hdbcli<strong>en</strong>t\ on Microsoft Windows platforms<br />

○ /usr/sap/hdbcli<strong>en</strong>t/ on Linux and UNIX platforms<br />

2. Add ngdbc.jar to your classpath.<br />

3. If you are on a version of Java earlier than Java 6, load the JDBC driver class, which is called<br />

com.sap.db.jdbc.Driver.<br />

4. Write Java code to create a connection to the database and execute SQL commands. Use a connection string<br />

in the form of jdbc:sap://:[/?]. For example:<br />

354<br />

jdbc:sap://myServer:30015/?autocommit=false<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces


The port should be 315, for example, 30015, if the instance is 00.<br />

You can specify one or more failover servers by adding additional hosts, as in the following example:<br />

jdbc:sap://myServer:30015,failover1:30015,failover2:30015/?<br />

autocommit=false<br />

Related Links<br />

The following is an example of connecting to an SAP HANA server called myhdb, which was installed as<br />

instance 07, with user name myname and password mysecret. Make sure to change these for your<br />

system, and add the JDBC driver (ngdbc.jar) to your classpath.<br />

import java.sql.*;<br />

public class jdemo {<br />

public static void main(String[] argv) {<br />

Connection connection = null;<br />

try {<br />

connection = DriverManager.getConnection(<br />

"jdbc:sap://myhdb:30715/?<br />

autocommit=false",myname,mysecret);<br />

} catch (SQLException e) {<br />

System.err.println("Connection Failed. User/Passwd Error?");<br />

return;<br />

}<br />

if (connection != null) {<br />

try {<br />

System.out.println("Connection to HANA successful!");<br />

Statem<strong>en</strong>t stmt = connection.createStatem<strong>en</strong>t();<br />

ResultSet resultSet = stmt.executeQuery("Select 'hello<br />

world' from dummy");<br />

resultSet.next();<br />

String hello = resultSet.getString(1);<br />

System.out.println(hello);<br />

} catch (SQLException e) {<br />

System.err.println("Query failed!");<br />

}<br />

}<br />

}<br />

}<br />

SAP HANA Database - Cli<strong>en</strong>t Installation Guide<br />

14.2.1 Tracing JDBC Connections<br />

You can activate the JDBC trace to find errors while your application is connected to a database via JDBC.<br />

You must be logged on as the operating system user who started (or will start) the JDBC application.<br />

Note:<br />

● You always activate the JDBC trace for all JDBC applications that the curr<strong>en</strong>t operating system user<br />

has started.<br />

● Configuration changes have an effect on all JDBC applications that the curr<strong>en</strong>t operating system user<br />

has started.<br />

Wh<strong>en</strong> the JDBC trace is activated, the JDBC driver logs on the cli<strong>en</strong>t the following information:<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 355


● JDBC API calls called by the JDBC application<br />

● JDBC API call parameters<br />

● Executed SQL statem<strong>en</strong>ts and their results<br />

The location of the trace file is determined by the trace options.<br />

Tracing via GUI<br />

You can start tracing by running the tracing configuration tool that includes a graphical user interface (GUI).<br />

Tracing via the GUI <strong>en</strong>ables you to start and configure tracing without stopping and restarting your application<br />

that is connected via JDBC.<br />

1. On the cli<strong>en</strong>t, <strong>en</strong>ter the following command on the command line: java -jar <br />

\ngdbc.jar.<br />

2. Select Trace <strong>en</strong>abled.<br />

3. Select and modify the tracing options.<br />

4. Select OK.<br />

Tracing via Command Line<br />

You can start tracing by running the tracing configuration tool and s<strong>en</strong>ding commands via the command line.<br />

Tracing via the command line <strong>en</strong>ables you to start and configure tracing without stopping and restarting your<br />

application that is connected via JDBC.<br />

1. Display the curr<strong>en</strong>t configuration by running the command java -jar <br />

\ngdbc.jar.<br />

2. Select trace options by running the command java -jar \ngdbc.jar<br />

.<br />

3. Start tracing by running the command java -jar \ngdbc.jar TRACE ON.<br />

Related Links<br />

Trace Options<br />

Tracing via Connection String<br />

You can start tracing by adding an option in the connection string wh<strong>en</strong> creating a JDBC connection.<br />

Tracing via the connection string requires you to stop and restart your application that is making the JDBC<br />

connection. Also, with the connection string, you cannot turn off tracing or set any options except setting the<br />

trace fil<strong>en</strong>ame.<br />

Add the trace option to the connection wh<strong>en</strong> creating a JDBC connection.<br />

Here is an example connection string that starts tracing:<br />

jdbc:sap://localhost:30015/?autocommit=false&trace=traceFile.txt<br />

The location of the trace file is determined by the trace options.<br />

Trace Options<br />

Options wh<strong>en</strong> <strong>en</strong>abling JDBC tracing.<br />

356<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces


The first column shows the field name in the GUI-based tracing configuration tool, and the second column shows<br />

the command to <strong>en</strong>ter wh<strong>en</strong> using the command-line tool.<br />

Table 16: Trace Options<br />

Option Command Line Option Description<br />

Trace <strong>en</strong>abled TRACE ON | OFF Starts and stops tracing<br />

Trace file folder No command-line option. The folder can be specified<br />

with the FILENAME option.<br />

Sets the directory where the system<br />

writes the trace files.<br />

Wh<strong>en</strong> no folder is specified, the files<br />

are saved in the working directory of<br />

the application.<br />

Trace file name TRACE FILENAME [] Sets the name of the trace file.<br />

Limit file size TRACE SIZE [KB|MB|GB]<br />

To remove the size limit, use the following option:<br />

TRACE SIZE UNLIMITED<br />

Stop on error TRACE STOP ON ERROR <br />

To no longer stop on the specified error, use the<br />

following option:<br />

TRACE STOP ON ERROR OFF<br />

The system assigns each trace file<br />

an additional unique ID, so the file<br />

name is:<br />

_.prt<br />

The default file name is<br />

jdbctrace.<br />

Limits the size of each trace file.<br />

Stops writing the JDBC trace wh<strong>en</strong><br />

the specified error code occurs.<br />

14.2.2 Valid Java-to-SQL Conversions<br />

SAP HANA allows each Java object to be converted to specific SQL types using the JDBC method<br />

PreparedStatem<strong>en</strong>t.setObject or RowSet.setObject.<br />

Some conversions may fail at runtime if the value passed is invalid.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 357


14.3 Connecting via ODBO<br />

SAP HANA provides an ODBO driver for connecting applications to the database and executing MDX statem<strong>en</strong>ts.<br />

1. Install the ODBO driver. The driver is installed as part of the SAP HANA cli<strong>en</strong>t installation.<br />

2. Specify in your cli<strong>en</strong>t the provider name: SAPNewDBMDXProvider<br />

3. Create a connection string in the form of:<br />

;User ID=;Password=


3. In the Connection tab of the Data Link Properties window, <strong>en</strong>ter the SAP HANA server name, instance number,<br />

user name and password.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 359


4. Select the cube from which you want to import data. SAP HANA analytic and calculation views are exposed as<br />

cubes.<br />

360<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces


SAP HANA supports the following Microsoft Excel features:<br />

● Drilling down<br />

● Selection filtering<br />

● Top/bottom filters<br />

● Report filters<br />

● Member properties<br />

● Refresh cube<br />

● Convert PivotTable into formulas<br />

● Server formatting<br />

● Pre-modeled calculated members<br />

● Show/hide fields<br />

● Enhanced value and label filters<br />

● Insert slicer<br />

● Text search in report filter<br />

● PivotTable filter<br />

● Creation of named sets<br />

14.3.2 Multidim<strong>en</strong>sional Expressions (MDX)<br />

Multidim<strong>en</strong>sional Expressions (MDX) is a language you can use to query multidim<strong>en</strong>sional data stored in OLAP<br />

cubes.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 361


MDX uses a multidim<strong>en</strong>sional data model to <strong>en</strong>able navigation in multiple dim<strong>en</strong>sions, levels, and up and down a<br />

hierarchy. With MDX, you can access pre-computed aggregates at specified positions (levels or members) in a<br />

hierarchy.<br />

Note: MDX is an op<strong>en</strong> standard. However, SAP has <strong>dev</strong>eloped ext<strong>en</strong>sions to MDX that are designed to<br />

<strong>en</strong>able faster and more effici<strong>en</strong>t access to multidim<strong>en</strong>sional data, for example, to serve specific SAP<br />

HANA application requirem<strong>en</strong>ts and to optimize the resultset for SAP HANA cli<strong>en</strong>ts.<br />

MDX is implicitly a hierarchy-based paradigm. All members of all dim<strong>en</strong>sions must belong to a hierarchy. Ev<strong>en</strong> if<br />

you do not explicitly create hierarchies in your SAP HANA data model, the SAP HANA modeler implicitly<br />

g<strong>en</strong>erates default hierarchies for each dim<strong>en</strong>sion. All id<strong>en</strong>tifiers that are used to uniquely id<strong>en</strong>tify hierarchies,<br />

levels and members in MDX statem<strong>en</strong>ts (and metadata requests) embed the hierarchy name within the id<strong>en</strong>tifier.<br />

In SAP HANA, the standard use of MDX is to access SAP HANA models (for example, analytical and attribute<br />

views) that have be<strong>en</strong> designed, validated and activated in the modeler in the SAP HANA studio. The studio<br />

provides a graphical design <strong>en</strong>vironm<strong>en</strong>t that <strong>en</strong>ables detailed control over all aspects of the model and its<br />

language-context-s<strong>en</strong>sitive runtime repres<strong>en</strong>tation to users.<br />

MDX in SAP HANA uses a runtime cube model, which usually consists of an analytical (or calculation) view that<br />

repres<strong>en</strong>ts data in which dim<strong>en</strong>sions are modeled as attribute views. You can use the analytical view to specify<br />

whether a giv<strong>en</strong> attribute is int<strong>en</strong>ded for display purposes only or for aggregation. The key attributes of attribute<br />

views are linked to private attributes in an analytical view in order to connect the <strong>en</strong>tities. One b<strong>en</strong>efit of MDX in<br />

SAP HANA is the native support of hierarchies defined for attribute views.<br />

Note: MDX in SAP HANA includes native support of hierarchies defined for attribute views. SAP HANA<br />

supports level-based and par<strong>en</strong>t-child hierarchies and both types of hierarchies are accessible with MDX.<br />

SAP HANA supports the use of variables in MDX queries; the variables are a SAP-specific <strong>en</strong>hancem<strong>en</strong>t to<br />

standard MDX syntax. You can specify values for all mandatory variables that are defined in SAP HANA studio to<br />

various modeling <strong>en</strong>tities. The following example illustrates how to declare SAP HANA variables and their values:<br />

MDX<br />

Select<br />

From [MINI_C1_VAR]<br />

Where [Measures].[M2_1_M3_CONV]<br />

SAP VARIABLES [VAR_VAT] including 10,<br />

[VAR_K2] including 112,<br />

[VAR_TARGET_CURRENCY] including 'EUR',<br />

14.3.3 MDX Functions<br />

MDX in SAP HANA supports a variety of standard MDX functions.<br />

Table 17: Supported MDX Functions<br />

Function Description<br />

Aggregate Returns a calculated value using the appropriate aggregate function, based on the<br />

aggregation type of the member.<br />

Ancestor Returns the ancestor of a member at a specified level or at a specific distance away<br />

in the hierarchy.<br />

Ancestors Returns a set of all ancestors of a member at a specified level or at a specific<br />

distance away in the hierarchy.<br />

Asc<strong>en</strong>dants Returns the set of the asc<strong>en</strong>dants of the member.<br />

362<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces


Function Description<br />

Avg Returns the average value of a numeric expression evaluated over a set.<br />

BottomCount Returns a specified number of items from the bottom of a set, optionally sorting<br />

the set first.<br />

Childr<strong>en</strong> Returns the childr<strong>en</strong> of a member.<br />

ClosingPeriod Returns the last sibling among the desc<strong>en</strong>dants of a member at a specified level.<br />

Count Counts the number of members in the tuple.<br />

Cousin Returns the child member with the same relative position under a par<strong>en</strong>t member<br />

as the specified child member.<br />

Crossjoin Returns the cross product of two sets.<br />

Curr<strong>en</strong>tMember Returns the curr<strong>en</strong>t member along a hierarchy.<br />

DefaultMember Returns the default member of a hierarchy.<br />

Desc<strong>en</strong>dants Returns the set of desc<strong>en</strong>dants of a member at a specified level or at a specific<br />

distance away in the hierarchy.<br />

Dim<strong>en</strong>sion Returns the hierarchy that contains a specified member or level.<br />

Dim<strong>en</strong>sions Returns a hierarchy specified by a numeric or string expression.<br />

Distinct Returns a set, removing duplicate tuples from a specified set.<br />

DistinctCount Returns the number of distinct tuples in a set.<br />

DrillDownLevel Drills down the members of a set one level below the lowest level repres<strong>en</strong>ted in the<br />

set, or to one level below an optional level of a member repres<strong>en</strong>ted in the set.<br />

DrillDownLevelBottom Drills down the members of a specified count of bottom members of a set, at a<br />

specified level, to one level below.<br />

DrillDownLevelTop Drills down a specified count of top members of a set, at a specified level, to one<br />

level below.<br />

DrillDownMember Drills down the members in a specified set that are pres<strong>en</strong>t in a second specified<br />

set.<br />

DrillDownMemberBottom Drills down the members in a specified set that are pres<strong>en</strong>t in a second specified<br />

set, limiting the result set to a specified number of bottommost members.<br />

DrillDownMemberTop Drills down the members in a specified set that are pres<strong>en</strong>t in a second specified<br />

set, limiting the result set to a specified number of topmost members.<br />

DrillUpLevel Drills up the members of a set that are below a specified level.<br />

DrillUpmember Drills up the members in a specified set that are pres<strong>en</strong>t in a second specified set.<br />

Except Finds the differ<strong>en</strong>ce betwe<strong>en</strong> two sets, optionally retaining duplicates.<br />

Filter Returns the set resulting from filtering a set based on a search condition.<br />

FirstChild Returns the first child of a specified member.<br />

FirstSibling Returns the first child of the par<strong>en</strong>t of a specified member.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 363


Function Description<br />

G<strong>en</strong>erate Applies a set to each member of another set, and th<strong>en</strong> joins the resulting sets by<br />

union. Alternatively, this function returns a concat<strong>en</strong>ated string created by<br />

evaluating a string expression over a set.<br />

Head Returns the first specified number of elem<strong>en</strong>ts in a set.<br />

Hierarchize Orders the members of a specified set in a hierarchy in natural or, optionally, postnatural<br />

order.<br />

Hierarchy<br />

Instr The InStr function finds the starting location of a substring within a specified string.<br />

Intersect Returns the intersection of two sets, optionally retaining duplicates.<br />

IsAncestor Returns true if the first member specified is an ancestor of the second member<br />

specified, else returns false.<br />

IsG<strong>en</strong>eration Returns true if the member specified is a leaf, else returns false.<br />

IsLeaf Returns true if the first member specified is an ancestor of the second member<br />

specified, else returns false.<br />

IsSibling Returns true if the first member specified is an sibling of the second member<br />

specified, else returns false.<br />

Item If an integer is specified, the Item function returns the tuple that is in the zerobased<br />

position specified by Index.<br />

IIF Returns one of values determined by a logical test.<br />

Lag Returns the member that is a specified number of positions prior to a specified<br />

member along the dim<strong>en</strong>sion of the member.<br />

LastChild Returns the last child of a specified member.<br />

LastPeriods Returns a set of members prior to and including a specified member.<br />

LastSibling Returns the last child of the par<strong>en</strong>t of a specified member.<br />

Lead Returns the member that is a specified number of positions following a specified<br />

member along the dim<strong>en</strong>sion of the member.<br />

Leaves If a dim<strong>en</strong>sion name is specified, returns a set that contains the leaf members of<br />

the key attribute for the specified dim<strong>en</strong>sion.If a dim<strong>en</strong>sion name is not specified,<br />

the function returns a set that contains the leaf members of the <strong>en</strong>tire cube.<br />

Left The Left function returns a string of a specified number of characters from the left<br />

side (beginning) of a specified string.<br />

Level Returns the level of a member.<br />

Levels Returns the level whose zero-based position in a dim<strong>en</strong>sion is specified by a<br />

numeric expression.<br />

Max Returns the maximum value of a numeric expression evaluated over a set.<br />

Member_caption Returns the caption of a member<br />

Members Returns the set of all members in a specified hierarchy.<br />

364<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces


Function Description<br />

MembersAsc<strong>en</strong>dantsDesc<br />

<strong>en</strong>dants<br />

Returns the set of specified members in a giv<strong>en</strong> hierarchy.<br />

Mid The Mid function returns a substring of a string argum<strong>en</strong>t.<br />

Min Returns the minimum value of a numeric expression evaluated over a set<br />

MTD Returns a set of members from the Month level in a Time dim<strong>en</strong>sion starting with<br />

the first period and <strong>en</strong>ding with a specified member.<br />

Name Returns the name of a specified hierarchy or member.<br />

NextMember Returns the next member in the level that contains a specified member.<br />

NOT Performs a logical negation on a numeric expression.<br />

Op<strong>en</strong>ingPeriod Returns the first sibling among the desc<strong>en</strong>dants of a specified level, optionally at a<br />

specified member.<br />

OR Performs a logical disjunction on two numeric expressions.<br />

Ordinal Returns the zero-based ordinal value associated with a specified level.<br />

ParallelPeriod Returns a member from a prior period in the same relative position as a specified<br />

member.<br />

Par<strong>en</strong>t Returns the par<strong>en</strong>t of a specified member.<br />

PeriodsToDate Returns a set of members (periods) from a specified level starting with the first<br />

member and <strong>en</strong>ding with a specified member.<br />

PrevMember Returns the previous member in the level that contains a specified member.<br />

Properties Returns a string containing the value of the specified member property.<br />

QTD Returns a set of members from the Quarter level in a Time dim<strong>en</strong>sion starting with<br />

the first period and <strong>en</strong>ding with a specified member.<br />

Range Performs a set operation that returns a naturally ordered set, with the two<br />

specified members as <strong>en</strong>dpoints, and all members betwe<strong>en</strong> the two specified<br />

members included as members of the set<br />

Right The Right function returns a string of a specified number of characters from the<br />

right side (<strong>en</strong>d) of a specified string.<br />

Siblings Returns the set of siblings of a specified member, including the member itself.<br />

StrToMember Returns a member from a string expression in MDX format.<br />

StrToSet Constructs a set from a specified string expression in MDX format.<br />

StrToTuple Constructs a tuple from a specified string expression in MDX format.<br />

StrToValue Returns a value from a string expression<br />

Subset Returns a subset of tuples from a specified set.<br />

Sum Returns the sum of a numeric expression evaluated over a specified set.<br />

Tail Returns the last specified number of elem<strong>en</strong>ts in a set.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 365


Function Description<br />

TopCount Returns a specified number of items from the topmost members of a specified set,<br />

optionally ordering the set first.<br />

Union Performs a set operation that returns a union of two sets, removing duplicate<br />

members.<br />

UniqueName Returns the unique name of a specified hierarchy.<br />

WTD Returns a set of members from the Week level in a Time dim<strong>en</strong>sion starting with<br />

the first period and <strong>en</strong>ding with a specified member.<br />

YTD Returns a set of members from the Year level in a Time dim<strong>en</strong>sion starting with the<br />

first period and <strong>en</strong>ding with a specified member.<br />

14.3.4 MDX Ext<strong>en</strong>sions<br />

SAP HANA supports several ext<strong>en</strong>sions to the MDX language, for example, additional predefined functions and<br />

support for variables.<br />

Sibling_Ordinal Intrinsic Property<br />

The object Member includes a property called Sibling_Ordinal, that is equal to the 0-based position of the<br />

member within its siblings.<br />

WITH<br />

MEMBER [Measures].[Termination Rate] AS<br />

[Measures].[NET_SALES] / [Measures].[BILLED_QUANTITY]<br />

SELECT<br />

{<br />

[Measures].[NET_SALES],<br />

[Measures].[BILLED_QUANTITY],<br />

[Measures].[Termination Rate]<br />

} ON COLUMNS,<br />

Desc<strong>en</strong>dants<br />

(<br />

[MDX_TEST_10_DISTRIBUTION_CHANNEL].<br />

[MDX_TEST_10_DISTRIBUTION_CHANNEL].[All].[(all)],<br />

1,<br />

SELF_AND_BEFORE<br />

)<br />

DIMENSION PROPERTIES SIBLING_ORDINAL ON ROWS<br />

FROM MDX_TEST_10_ITELO_SALES_DATA<br />

MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants Function<br />

SAP HANA includes a new function called MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants that <strong>en</strong>ables you to get, for<br />

example, all asc<strong>en</strong>dants and desc<strong>en</strong>dants of a specific member. This function improves on the standard MDX<br />

functions Asc<strong>en</strong>dants and Desc<strong>en</strong>dants.<br />

The function can be called as follows:<br />

MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants (, )<br />

● set: A set of members from a single hierarchy<br />

● flag: Indicates which related members to return, and can be one of the following:<br />

366<br />

○ MEMBERS_AND_ASCENDANTS_AND_DESCENDANTS<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces


○ MEMBERS_AND_ASCENDANTS<br />

○ MEMBERS_AND_DESCENDANTS<br />

○ ASCENDANTS_AND_DESCENDANTS<br />

○ ONLY_ASCENDANTS<br />

○ ONLY_DESCENDANTS<br />

SELECT<br />

{ [Measures].[SALES] }<br />

ON COLUMNS,<br />

NON EMPTY<br />

{ Hierarchize( MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants([JUICE_TIME].[TimeHier].<br />

[QUARTER].[3]:[JUICE_TIME].[TimeHier].[QUARTER].[4],<br />

MEMBERS_AND_ASCENDANTS_AND_DESCENDANTS )) }<br />

ON ROWS<br />

FROM [JUICE]<br />

SELECT<br />

{ [Measures].[SALES] }<br />

ON COLUMNS,<br />

NON EMPTY<br />

{ Hierarchize( MembersAsc<strong>en</strong>dantsDesc<strong>en</strong>dants([JUICE_TIME].[TimeHier].<br />

[QUARTER].[3]:[JUICE_TIME].[TimeHier].[QUARTER].[4],<br />

ONLY_ASCENDANTS )) }<br />

ON ROWS<br />

FROM [JUICE]<br />

Variables<br />

An MDX SELECT statem<strong>en</strong>t in SAP HANA <strong>en</strong>ables you to s<strong>en</strong>d values for variables defined within modeling views.<br />

Analytic and calculation views can contain variables, that can be bound to specific attributes. Wh<strong>en</strong> calling the<br />

view, you can s<strong>en</strong>d values for those variables. These variables can be used, for example, to filter the results.<br />

SAP HANA supports an ext<strong>en</strong>sion to MDX whereby you can pass values for variables defined in views by adding a<br />

SAP Variables clause in your select statem<strong>en</strong>t. Here is the syntax for a Select statem<strong>en</strong>t:<br />

: [WITH ]<br />

SELECT [[,...]]<br />

FROM <br />

[WHERE <br />

SAP VARIABLES: [[,] …]]<br />

: [] <br />

: INCLUDING | EXCLUDING<br />

: = | > | >= | < |


[VAR_K2] including 112,<br />

[VAR_TARGET_CURRENCY] including 'EUR'<br />

The following specifies an interval for variable VAR_K2.<br />

SELECT NON EMPTY<br />

{<br />

[K2].[K2].Members<br />

}ON ROWS<br />

FROM [MINI_C1_VAR_SIMPLE]<br />

WHERE [Measures].[M3_CONV]<br />

SAP VARIABLES [VAR_K2] including [K2].[K2].&[122]:[K2].[K2].&[221]<br />

Metadata on Variables in Views<br />

SAP HANA includes the following set of tables that contain information about the variables defined for views:<br />

● BIMC_VARIABLE<br />

● BIMC_VARIABLE_ASSIGNMENT<br />

● BIMC_VARIABLE_VALUE<br />

● BIMC_VARIABLE_ODBO (virtual table)<br />

The tables <strong>en</strong>able, for example, an application to retrieve the variables defined for a view and create a user<br />

interface so the user can <strong>en</strong>ter values.<br />

368<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved.<br />

SAP HANA Developer Guide<br />

Using Database Cli<strong>en</strong>t Interfaces


15 SAP HANA Developer Refer<strong>en</strong>ces<br />

The SAP HANA Developer's Guide comes with the following language, API and other refer<strong>en</strong>ces.<br />

Name Link<br />

SAP HANA SQL Refer<strong>en</strong>ce http://help.sap.com/<strong>hana</strong>/html/sqlmain.html<br />

SAP HANA SQLScript Refer<strong>en</strong>ce http://help.sap.com/<strong>hana</strong>/<strong>hana</strong>_<strong>dev</strong>_sqlscript_<strong>en</strong>.pdf<br />

SAP HANA System Tables and Monitoring Views<br />

Refer<strong>en</strong>ce<br />

http://help.sap.com/<strong>hana</strong>/html/monitor_views.html<br />

SAP HANA R Integration Guide http://help.sap.com/<strong>hana</strong>/<strong>hana</strong>_<strong>dev</strong>_r_emb_<strong>en</strong>.pdf<br />

SAP HANA Business Function Library (BFL) Refer<strong>en</strong>ce http://help.sap.com/<strong>hana</strong>/<strong>hana</strong>_<strong>dev</strong>_bfl_<strong>en</strong>.pdf<br />

SAP HANA Predictive Analysis Library (PAL) Refer<strong>en</strong>ce http://help.sap.com/<strong>hana</strong>/<strong>hana</strong>_<strong>dev</strong>_pal_<strong>en</strong>.pdf<br />

SAP HANA XS JavaScript Refer<strong>en</strong>ce http://help.sap.com/<strong>hana</strong>/jsapi/index.html<br />

SAP HANA Developer Guide<br />

SAP HANA Developer Refer<strong>en</strong>ces<br />

P U B L I C<br />

© 2012 SAP AG. All rights reserved. 369


www.sap.com/contactsap<br />

© 2012 SAP AG. All rights reserved.<br />

No part of this publication may be reproduced or transmitted in<br />

any form or for any purpose without the express permission of<br />

SAP AG.<br />

The information contained herein may be changed without prior<br />

notice.<br />

Some software products marketed by SAP AG and its distributors<br />

contain proprietary software compon<strong>en</strong>ts of other software<br />

v<strong>en</strong>dors.<br />

Microsoft, Windows, Excel, Outlook, and PowerPoint are<br />

registered trademarks of Microsoft Corporation.<br />

IBM, DB2, DB2 Universal Database, System ads, System i5,<br />

System p, System p5, System x, System z, System z10, System<br />

z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM,<br />

z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel<br />

Enterprise Server, PowerVM, Power Architecture, POWER6+,<br />

POWER6, POWER5+, POWER5, POWER, Op<strong>en</strong>Power, PowerPC,<br />

BatchPipes, BladeC<strong>en</strong>ter, System Storage, GPFS, HACMP,<br />

RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex,<br />

MVS/ESA, AIX, Intellig<strong>en</strong>t Miner, WebSphere, Netfinity, Tivoli and<br />

Informix are trademarks or registered trademarks of IBM<br />

Corporation.<br />

Linux is the registered trademark of Linus Torvalds in the U.S. and<br />

other countries.<br />

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are<br />

either trademarks or registered trademarks of Adobe Systems<br />

Incorporated in the United States and/or other countries.<br />

Oracle is a registered trademark of Oracle Corporation.<br />

UNIX, X/Op<strong>en</strong>, OSF/1, and Motif are registered trademarks of the<br />

Op<strong>en</strong> Group.<br />

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame,<br />

VideoFrame, and MultiWin are trademarks or registered<br />

trademarks of Citrix Systems, Inc.<br />

HTML, XML, XHTML and W3C are trademarks or registered<br />

trademarks of W3C ® , World Wide Web Consortium,<br />

Massachusetts Institute of Technology.<br />

Java is a registered trademark of Sun Microsystems, Inc.<br />

JavaScript is a registered trademark of Sun Microsystems, Inc.,<br />

used under lic<strong>en</strong>se for technology inv<strong>en</strong>ted and implem<strong>en</strong>ted by<br />

Netscape.<br />

SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, PartnerEdge,<br />

ByDesign, SAP Business ByDesign, and other SAP products and<br />

services m<strong>en</strong>tioned herein as well as their respective logos are<br />

trademarks or registered trademarks of SAP AG in Germany and<br />

in several other countries all over the world. All other product and<br />

service names m<strong>en</strong>tioned are the trademarks of their respective<br />

companies. Data contained in this docum<strong>en</strong>t serves informational<br />

purposes only. National product specifications may vary.<br />

These materials are subject to change without notice. These<br />

materials are provided by SAP AG and its affiliated companies<br />

("SAP Group") for informational purposes only, without<br />

repres<strong>en</strong>tation or warranty of any kind, and SAP Group shall not<br />

be liable for errors or omissions with respect to the materials. The<br />

only warranties for SAP Group products and services are those<br />

that are set forth in the express warranty statem<strong>en</strong>ts<br />

accompanying such products and services, if any. Nothing herein<br />

should be construed as constituting an additional warranty.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!