You are on page 1of 17

How-To Guide:

Expose SAP HANA Live Query Views


Using OData to Create
SAP CRM HANA Live Reports
Based on SAP CRM EHP 3 SP 04

Version: 1.0 April 7 2014

2013 SAP AG How-To Guide: Expose SAP HANA Page 1 of 17


Dietmar-Hopp-Allee 16 Live Query Views via OData to Create
69190 Walldorf SAP CRM HANA Live Reports

SAP How-To Guide

1 Overview .......................................................................................... 3
2 Prerequisites ................................................................................... 4
3 SAP HANA Modelling Guidelines ......................................................... 5
3.1 Text / ID Mapping on Attributes .......................................................................... 5
3.2 Representation of Amounts with Currency ......................................................... 6
3.3 Modelling of Compounded Attributes ................................................................. 6
3.4 SAP HANA SQL Data Types and Filter Operators ................................................. 8
3.5 Value Help for View Input Parameters ................................................................ 9
3.6 Multi Tenancy Handling ....................................................................................... 9

4 OData Service Definition in SAP HANA XS ............................... 10


4.1 Set Up SAP HANA XS Project .............................................................................. 10
4.2 Define Basic OData Service ................................................................................ 11
4.3 Enhance OData Service with Value Help............................................................ 12
4.4 Test OData Service in the Browser..................................................................... 13

5 CRM Customizing: Maintain SAP HANA Live Query ............... 14


5.1 Insight-To-Action Navigation Customizing ......................................................... 14

6 Create a SAP HANA Live Report ................................................ 15


6.1 Dynamic Filtering with Value Expressions ......................................................... 17

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 2 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

1 Overview
This document describes the steps required to use both SAP HANA Live query views and
query views that you define to create SAP HANA Live Reports in the WebClient UI.

This is done using OData services in SAP HANA Extended Application Services (SAP HANA
XS) that are exposed for usage by the CRM ABAP Server and the Web Client UI.

This document is an enhanced version of the how-to document in SAP Note 1915516. It
describes SAP HANA Live reporting as of SAP Enhancement Package 3 for SAP CRM 7.0
Support Package 04 or higher.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 3 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

2 Prerequisites
You are using SAP Enhancement Package 3 for SAP CRM 7.0 Support Package 04 or a
higher release or support package.
You have activated the business function SAP HANA Live Reporting
(CRM_ANA_OR_ODATA). For more information, see SAP Library for SAP CRM at
http://help.sap.com/crm -> Application Help -> Business Functions for SAP Customer
Relationship Management -> Analytics -> SAP CRM HANA Live Reporting.
You can either reuse an existing SAP HANA Live query view or have developed your own
view.

Note:

In the remainder of this document, the following example query view is used
tmp.hanalive.crm.sample.LostOpportunitiesQuery:

The view is based on the SAP HANA Live for SAP CRM reuse view Opportunity. It
defines additional filters to select only the opportunities that are lost and have no errors.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 4 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

3 SAP HANA Modelling Guidelines


To achieve the best user experience and optimum use of the SAP HANA Live reporting
functions, the associated SAP HANA view should be modeled according to specific
guidelines. These are discussed in detail in the following sections.

3.1 Text / ID Mapping on Attributes


A label column can be referenced in the output structure of a SAP HANA view for a specific
attribute. This has some impact on the resulting OData service, the representation of the
attribute on the reporting UI, and the filter definition for this attribute.

The screenshot above is taken from the example calculation view tmp.hanalive.crm.sample.-
LostOpportunitiesQuery. It is generally good practice to reference a label column to each
semantic type code or identifier field. The label column contains a language-dependent text.
For example, the code field OpportunityType has a label column OpportunityTypeName that
references the language-dependent text for the opportunity type. This has the following
impact:

1. Users only see the language-dependent text and not the technical code or identifier of
such an attribute on the reporting user interface.
2. When defining a sort order for this type of attribute, the sorting is applied to the text field
rather than the code or identifier.
3. When defining a filter for this type of attribute, you can only use the following basic
operators: equal, not equal, is empty, is not empty and calculated value. You cannot enter
any free text value. The user must use the value help to specify a filter value.

In some cases it makes sense to display identifiers or codes on the user interface instead of
descriptions, and to be able to filter using these technical data or sort according to the
identifier instead of the language-dependent text. In the above example, the opportunity
identifier is such a field. To achieve this behavior in the example, the opportunity identifier is
duplicated in the output structure of the view. No label column is defined for the first field
OpportunityID, whereas the second field Opportunity references the label column
OpportunityName. This produces two attributes Opportunity ID and Opportunity that can be
selected in the report. The first contains the technical identifier and the second one contains
the description.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 5 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

3.2 Representation of Amounts with Currency


When modelling amounts with currency, it is
important to reference the corresponding
currency field in the properties dialog for the
amount.

The screenshot shows the semantics of the


amount measure field from the example
view. It also contains the properties used to
perform a currency conversion of the
amount in the display currency.

The given input parameter P_Display-


Currency is also defined as an output field
for the view with the name DisplayCurrency.
This naming convention is also important for
the value help for the input parameter.
When referencing the value help view
sap.hba.crm.CurrencyValueHelp from the
SAP HANA Live for SAP CRM content as an OData association, the number of decimal
places for the amount values is currency-dependent. The number of decimal places for
amounts in the currency JPY (Japanese Yen) is for example zero. For more information about
value helps, see Enhance OData Service with Value Help.

3.3 Modeling of Compounded Attributes


The concept of compounded attributes, which is for example familiar from SAP BW, is
currently not implemented in SAP HANA views. It is not possible to express a compounding
relationship between attributes. The standard example for compounded attributes is country
and region, where region has the superordinate attribute country.

Filtering by compounded attributes is not easy, because all dependent attributes also need to
be filtered. See the following example with two countries Germany and USA. Each of them
has two regions with the same identifier:

Region Region Name Country

1 Berlin DE

2 Hamburg DE

1 Arizona US

2 Florida US

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 6 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

When defining a filter region is Berlin OR Arizona, the country must also be taken into
account. The default behavior when defining filters is that filters for the same field are
combined with a logical OR and filters for different fields are combined with a logical AND.
Bearing this in mind, the resulting filter expression is:

(Region = 1 OR Region = 2) AND (Country = DE OR Country = US)

This filter expression is incorrect because it will return all four values instead of only two. The
correct filter expression can only be constructed observing the compounding:

(Region = 1 AND Country = DE) OR (Region = 2 AND Country = US).

This issue means that filtering for the field


region is disabled as a default for all OData
services in the package
sap.hba.apps.crmhlq.

To work around the compounding behavior,


a calculated field can be used that
concatenates all compounding keys in a
calculated column. In the region example
above, a calculated column
RegionCountry, which concatenates the
region and the country key, can be used for
filtering.

The screenshot on the right shows the


definition of the calculated column
RegionCountry. This concatenation needs
to be defined both in the value help view
and in the corresponding query result view.
The definition of the value help annotations
for the OData service also needs to be adapted to create the association between the two
calculated fields instead of the Region field.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 7 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

3.4 SAP HANA SQL Data Types and Filter Operators


It is important to understand the interconnection between SAP HANA SQL data types and the
impact on the reporting user interface.

One common example is date fields. Most of them are saved as strings of length 8 (in the
format YYYYMMDD) in the database tables. To recognize the field as a date on the user
interface, the data type has to be converted to the SQL SAP HANA data type DATE. The
output fields for query views in the SAP HANA Live content often contain such fields with the
suffix _E to indicate the external format, for example PostingDate_E contains the date in the
external representation with data type DATE. On the reporting user interface, this attribute is
correctly formatted as a date, the value help for such a field is a date picker control, and the
filter operators for dates, for example between, greater than or less than, are available.

Another example would be numeric attributes that are saved as strings in the database, for
example ChanceOfSuccessPercent in the reuse view sap.hba.crm.Opportunity. This field has
the type VARCHAR. You cannot define filters such as Greater than 50% because this
operator is not available for text attributes. In your own SAP HANA view, you can convert the
field into an INTEGER (by using a calculated column with an integer cast). All numeric
operators can be used to define filter expressions in this field.

The following table shows an overview of the SAP HANA data types and the available filter
operators in SAP HANA Live reports.

Logical Data Type Data Type of SAP HANA Field Available Filter Operators

Text VARCHAR, NVARCHAR, For text attributes:


CHAR, NCHAR (Not) Equal, Is (not) empty,
Expression

For identifier / code attributes:


(Not) Equal, Is (not) empty,
Contains, Starts with, Ends with,
Expression

Date DATE, SECONDDATE, (Not) Equal, Is (not) empty,


LONGDATE, TIMESTAMP Greater than (or equal),
Less than (or equal),
Numeric DECIMAL, SMALDECIMAL Between, Expression
DOUBLE, REAL, FLOAT
SMALLINT, INTEGER,
BIGINT, TINYINT

Binary BINARY, VARBINARY (Not) Equal, Is (not) empty,


Expression

Filters for attributes with the SAP HANA data type TIME are not currently available.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 8 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

3.5 Value Help for View Input Parameters


To enable value help for input parameters, the associated SAP HANA view must adhere to
additional guidelines: The input parameter must start with the prefix P_, followed by the
name of the parameter, for example P_Country for an input parameter for the field Country.
The view must also have a field Country in the output structure of the view. A value help entity
and a corresponding OData association can be defined in the *.xsodata file in this field.

3.6 Multi Tenancy Handling


In general, the SAP HANA Live for SAP CRM content is cross-client. This means that all
views return data for all clients in the database system. All client-specific views have the
output field SAPClient that contains the client information. However, the query views contain a
mandatory input parameter P_SAPClient that is used to filter the data for a specific client.

When modeling your own SAP HANA views for consumption using SAP HANA Live reporting,
make sure you filter directly in the view for the correct client, or expose an input parameter
with the name P_SAPClient to filter according to the client. In the SAP HANA Live reporting
user interface, the parameter P_SAPClient is never displayed to the user but contains the
current logon client. The field SAPClient is also not visible and cannot be used.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 9 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

4 OData Service Definition in SAP HANA XS


4.1 Set Up SAP HANA XS Project
You need to create a SAP HANA XS project to develop your own OData services. In the SAP
HANA modeler, switch to the SAP HANA Development view. Use the wizard to create a local
SAP HANA XS project and connect to the SAP HANA repository. In this example, we have
put it in the SAP HANA package tmp.hanalive.crm.sample.

You have to create the following application descriptor files in the main directory of your SAP
HANA XS project to enable access to your application:

.xsapp: marks the point in the package hierarchy at which an application's content is
available to clients. The file has no name and no content.
.xsaccess: the application access file in a JSON-compliant format; example:
{
"exposed" : true,
"prevent_xsrf" : true,
"force_ssl" : true,
"cache_control": "no-cache, no-store"
}
.xsprivileges: [optional] lists the authorization levels that are available to access an
application package.

For more information about application descriptors and how to setup a SAP HANA XS project,
see the SAP HANA Developer Guide at http://help.sap.com/hana_platform.

The definition of an OData service in the SAP HANA XS consists of the following steps as
described in the following sections.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 10 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

4.2 Define Basic OData Service


Define an OData service for the query view. In your SAP HANA XS project, create a file with
the suffix .xsodata (for example LostOpportunitiesQuery.xsodata) that contains the definition.
You can use the example below as a blueprint.

Exchange the view name and the service name according to your requirements (second line).
Since an OData service must point to an existing SAP HANA view, this means that you have
to replace "tmp.hanalive.crm.sample::LostOpportunitiesQuery" with the path and name of the
actual view you want to expose.

service namespace "tmp.hanalive.crm.sample" {


entity "tmp.hanalive.crm.sample::LostOpportunitiesQuery" as
"LostOpportunitiesQuery"
keys generate local "GeneratedID"
aggregates always
parameters via entity;
}
annotations {
enable OData4SAP;
}

If your view does not contain parameters, the line parameters via entity has to be omitted.

Save and activate the file.

For more information, see the SAP HANA Developer Guide at


http://help.sap.com/hana_platform.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 11 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

4.3 Enhance OData Service with Value Help


In addition to the basic OData service definition, you can also leverage SAP HANA Live for
SAP CRM content by reusing the value help views to enable fast and easy filtering according
to SAP HANA Live reports.

The following example shows how to reference the value help view
sap.hba.crm.OpportunityTypeValueHelp as an OData entity in the service definition file
together with an association between the value help view entity and the query result entity.

entity "sap.hba.crm::OpportunityTypeValueHelp"
as "OpportunityTypeValueHelp"
key( "OpportunityType" );

association "OpportunityQuery_OpportunityTypeValueHelp"
principal "OpportunityTypeValueHelp"( "OpportunityType" )
multiplicity "1"
dependent "LostOpportunitiesQuery "( "OpportunityType" )
multiplicity "*";

This value help definition is performed for all filterable dimensions in the exposed SAP HANA
view. This approach ensures that the end user is able to select all possible values to define a
filter criterion. You can use this example as a blueprint or you can refer to the existing OData
services delivered by SAP with the SAP HANA delivery unit HCO_HBA_APPS_CRMHLQ in
package sap.hba.apps.crmhlq.odata.

If this enhancement to the OData service is not performed, the end user would also see a
value help on the user interface. However, in this case, the suggested values come from the
query result directly instead of a separate entity. This means that only the values that are part
of the query result can be selected for filtering. It also has a negative impact on the
performance of the value help.

For more information, see the SAP HANA Developer Guide at


http://help.sap.com/hana_platform.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 12 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

4.4 Test OData Service in the Browser


Test your OData service definition using a web browser by replacing the server and port
information for your SAP HANA database in the following URL:

https://<server>:<port>/tmp/hanalive/crm/sample/LostOpportunitiesQuery.xsodata/$metadata

Note:

The port number for HTTPS is usually 43xx; for HTTP it is usually 80xx. (xx = Instance
number of SAP HANA installation, for example 00 or 02). Ensure that the path points to your
OData service definition file.

The result shows the metadata document for your OData service. In addition to the standard
OData V2 annotations, the metadata contains SAP-specific information in the context of
analytical services such as sap:aggregation-role and sap:semantics.

For a detailed description of the SAP-specific enhancements for OData version 2.0, see the
SAP community network article: http://scn.sap.com/docs/DOC-44986.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 13 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

5 CRM Customizing: Maintain SAP HANA Live


Query
The new OData service defined must be published in the CRM ABAP backend. To do this,
maintain the following information in Customizing for Customer Relationship Management
under CRM Analytics -> SAP HANA Live Reporting -> Maintain SAP HANA Live Queries.

Create a new entry to define a new SAP HANA Live Query. The following screenshot
contains the information required for the example:

5.1 Insight-To-Action Navigation Customizing


SAP HANA Live Reporting offers the ability to navigate directly from the report result to the
corresponding business object. The reporting user interface contains links in the table cells for
attributes that support insight-to-action navigation.

Currently, the Customizing settings for navigation cannot be changed by the customer. A
fixed number of fields are available for navigation. To reuse these Customizing settings for
your own SAP HANA calculation view, you must observe the naming convention for your field.
For example, to enable navigation to the details of an employee responsible in your reporting
result, you must name your SAP HANA field ResponsibleEmployee.

For a list of all available fields for navigation, check the content of the SAP CRM database
table CRMC_ANA_OD_NAV. The field ELEMENT_NAME in the table contains the SAP
HANA field names that can be used for navigation.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 14 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

6 Create a SAP HANA Live Report


Start the WebClient UI and log on using the role ANALYTICSPRO. Ensure that you are using
a SAP Web Dispatcher as described in the business function documentation, so that you can
create and execute SAP HANA Live reports.

The report creation application reuses most parts of the report execution user interface. The
main difference is the ability to save the report and to perform additional tasks, such as
sharing the report or assigning it to specific business roles. However, the main use cases,
such as adding or removing attributes and measures, defining filters or changing the layout
and the chart type to the report are identical in both scenarios (report creation and execution).

1. Choose Create SAP HANA Live Report from the shortcut menu
2. On the dialog box, enter the report name, description and SAP HANA Live Query that you
have specified in Customizing
3. Choose Ok

After confirming the basic data dialog box, the reporting user interface is launched. A
corresponding filter row is displayed on the initial screen for all input parameters for the
associated SAP HANA view:

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 15 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

The example query view contains two input parameters:

P_SAPClient for filtering according to the current reporting client


P_DisplayCurrency to define the target currency for currency conversion

The input parameter P_SAPClient is hidden from the user interface and the system ensures
that the correct value is transferred to the OData service from the logon data. The input
parameter P_DisplayCurrency is shown on the UI in the section Query Parameters.

After confirming the parameter definition dialog box, you see an empty report that can be
defined step by step (for example add attributes and measures, define additional filters and
select the layout and chart type for the report). Once you have defined the report, choose
Save or Save and Back.

Choose Manage Reports and search for the new SAP HANA Live Report you have created.

Check that it works as expected.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 16 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

SAP How-To Guide

6.1 Dynamic Filtering with Value Expressions


When defining report filters, a common requirement is to specify dynamic filter values that are
evaluated each time the report is executed rather than hard-coding fixed values during design
time for a report.

Common examples of such dynamic filters are current year or last four quarters. You can
reuse or create your own value expressions to define these types of dynamic filters.

To create your own expression, you must create an ABAP class with a static method that
returns a string value that represents the evaluated filter value.

In Customizing for Customer Relationship Management under CRM Analytics -> SAP HANA
Live Reporting -> Define Value Expressions, you can create your own expression with a
name, description, category and a reference to your ABAP class and method name.

On the reporting user interface, you can select the operator calculated value to assign an
expression in a filter or parameter dialog. The value help shows you all defined expressions
with the category that matches the filter field. For example, a filter field with the date data type
only allows expressions with the category Date. The screenshot below shows the process of
defining a filter for the attribute Posting Date using an expression. The value help for
expressions is shown in the screenshot.

2014 SAP AG How-To Guide: Expose SAP HANA Live Page 17 of 17


Dietmar-Hopp-Allee 16 Query Views via OData to Create SAP
69190 Walldorf CRM HANA Live Reports on EhP3 SP4

You might also like