Вы находитесь на странице: 1из 32

SAP NetWeaver

How-To Guide

How to Create OData Service for


Analytic Queries

Applicable Releases:
SAP NetWeaver Gateway 2.0

Version 1.0
December 2012

Copyright 2012 SAP AG. All rights reserved.


No part of this publication may be reproduced or transmitted in any
form or for any purpose without the express permission of SAP AG.
The information contained herein may be changed without prior
notice.
Some software products marketed by SAP AG and its distributors
contain proprietary software components of other software vendors.
Microsoft, Windows, Excel, Outlook, PowerPoint, Silverlight, and
Visual Studio are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p,
System p5, System x, System z, System z10, z10, z/VM, z/OS,
OS/390, zEnterprise, PowerVM, Power Architecture, Power Systems,
POWER7, POWER6+, POWER6, POWER, PowerHA, pureScale,
PowerPC, BladeCenter, System Storage, Storwize, XIV, GPFS,
HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, AIX,
Intelligent Miner, WebSphere, Tivoli, Informix, and Smarter Planet
are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the United
States and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are
trademarks or registered trademarks of Adobe Systems Incorporated
in the United States and other countries.
Oracle and Java are registered trademarks of Oracle and its affiliates.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the
Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame,
VideoFrame, and MultiWin are trademarks or registered trademarks
of Citrix Systems Inc.
HTML, XML, XHTML, and W3C are trademarks or registered
trademarks of W3C, World Wide Web Consortium, Massachusetts
Institute of Technology.
Apple, App Store, iBooks, iPad, iPhone, iPhoto, iPod, iTunes, MultiTouch, Objective-C, Retina, Safari, Siri, and Xcode are trademarks or
registered trademarks of Apple Inc.
IOS is a registered trademark of Cisco Systems Inc.
RIM, BlackBerry, BBM, BlackBerry Curve, BlackBerry Bold,
BlackBerry Pearl, BlackBerry Torch, BlackBerry Storm, BlackBerry
Storm2, BlackBerry PlayBook, and BlackBerry App World are
trademarks or registered trademarks of Research in Motion Limited.
Google App Engine, Google Apps, Google Checkout, Google Data
API, Google Maps, Google Mobile Ads, Google Mobile Updater,
Google Mobile, Google Store, Google Sync, Google Updater, Google
Voice, Google Mail, Gmail, YouTube, Dalvik and Android are
trademarks or registered trademarks of Google Inc.
INTERMEC is a registered trademark of Intermec Technologies
Corporation.
Wi-Fi is a registered trademark of Wi-Fi Alliance.

Business Objects and the Business Objects logo,


BusinessObjects, Crystal Reports, Crystal Decisions, Web
Intelligence, Xcelsius, and other Business Objects products and
services mentioned herein as well as their respective logos are
trademarks or registered trademarks of Business Objects
Software Ltd. Business Objects is an SAP company.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL
Anywhere, and other Sybase products and services mentioned
herein as well as their respective logos are trademarks or
registered trademarks of Sybase Inc. Sybase is an SAP company.
Crossgate, m@gic EDDY, B2B 360, and B2B 360 Services are
registered trademarks of Crossgate AG in Germany and other
countries. Crossgate is an SAP company.
All other product and service names mentioned are the
trademarks of their respective companies. Data contained in this
document serves informational purposes only. National product
specifications may vary.
These materials are subject to change without notice. These
materials are provided by SAP AG and its affiliated companies
("SAP Group") for informational purposes only, without
representation or warranty of any kind, and SAP Group shall not
be liable for errors or omissions with respect to the materials.
The only warranties for SAP Group products and services are
those that are set forth in the express warranty statements
accompanying such products and services, if any. Nothing herein
should be construed as constituting an additional warranty.
These materials are provided as is without a warranty of any
kind, either express or implied, including but not limited to, the
implied warranties of merchantability, fitness for a particular
purpose, or non-infringement.
SAP shall not be liable for damages of any kind including without
limitation direct, special, indirect, or consequential damages that
may result from the use of these materials.
SAP does not warrant the accuracy or completeness of the
information, text, graphics, links or other items contained within
these materials. SAP has no control over the information that
you may access through the use of hot links contained in these
materials and does not endorse your use of third party web pages
nor provide any warranty whatsoever relating to third party web
pages.
SAP NetWeaver How-to Guides are intended to simplify the
product implementation. While specific product features and
procedures typically are explained in a practical business
context, it is not implied that those features and procedures are
the only approach in solving a specific business problem using
SAP NetWeaver. Should you wish to receive additional
information, clarification or support, please refer to SAP
Consulting.
Any software coding and/or code lines / strings (Code)
included in this documentation are only examples and are not
intended to be used in a productive system environment. The
Code is only intended better explain and visualize the syntax and
phrasing rules of certain coding. SAP does not warrant the
correctness and completeness of the Code given herein, and SAP
shall not be liable for errors or damages caused by the usage of
the Code, except if such damages were caused by SAP
intentionally or grossly negligent.

Bluetooth is a registered trademark of Bluetooth SIG Inc.


Motorola is a registered trademark of Motorola Trademark Holdings
LLC.
Computop is a registered trademark of Computop
Wirtschaftsinformatik GmbH.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP
BusinessObjects Explorer, StreamWork, SAP HANA, and other SAP
products and services mentioned herein as well as their respective
logos are trademarks or registered trademarks of SAP AG in
Germany and other countries.

Disclaimer:
Some components of this product are based on Java. Any code
change in these components may cause unpredictable and severe
malfunctions and is therefore expressively prohibited, as is any
decompilation of these components.
Any Java Source Code delivered with this product is only to be
used by SAPs Support Services and may not be modified or
altered in any way.

Document History
Document Version

Description

1.00

Draft Version of this guide

ii

Typographic Conventions
Type Style

Description

Example Text

Words or characters quoted


from the screen. These
include field names, screen
titles, pushbuttons labels,
menu names, menu paths,
and menu options.
Cross-references to other
documentation

Example text

Emphasized words or
phrases in body text, graphic
titles, and table titles

Example text

File and directory names and


their paths, messages,
names of variables and
parameters, source text, and
names of installation,
upgrade and database tools.

Example text

User entry texts. These are


words or characters that you
enter in the system exactly as
they appear in the
documentation.

<Example
text>

Variable user entry. Angle


brackets indicate that you
replace these words and
characters with appropriate
entries to make entries in the
system.

EXAMPLE TEXT

Keys on the keyboard, for


example, F2 or ENTER.

Icons
Icon

Description
Caution
Important
Note
Recommendation or Tip
Example

iii

Table of Contents
1.

Introduction .......................................................................................................................... 1

2.

Business Scenario............................................................................................................... 1

3.

Prerequisites ........................................................................................................................ 1

4.

Creating EasyQuery on BW ................................................................................................ 2

5.

Generating OData Service for EasyQuery ........................................................................ 3

6.

Registration and Activation of the Generated Service .................................................... 6

7.

Terminology ......................................................................................................................... 7

8.

Service Document ............................................................................................................... 9


8.1 Service Document for a simple Query .......................................................................... 9
8.2 Metadata for an EasyQuery with Advanced Selection Options .................................... 9

9.

Metadata with Analytical Extension ................................................................................. 11


9.1 Metadata for a simple EasyQuery .............................................................................. 11
9.2 Metadata for an EasyQuery with Advanced Selection Options .................................. 12

10.

Consuming the Service ..................................................................................................... 15


10.1 Interacting with a simple Query .................................................................................. 15
10.2 Interacting with a Query with Advanced Selection Options ........................................ 21

11.

References ......................................................................................................................... 24

12.

Supported Features ........................................................................................................... 25

13.

Related Links ..................................................................................................................... 27

iv

How to Create OData Service for Analytic Queries

1. Introduction
This document focuses on generating SAP NetWeaver Gateway services for SAP BW queries
exposed via Easy Queries. Easy Query is one of the integrated services supported by SAP NetWeaver
Gateway.
SAP NetWeaver Gateways SAP BW integration provides a generic tool allowing an administrator at
customer side to easily expose existing SAP BW content as OData services.
NOTE: Prior knowledge of the working of SAP NetWeaver Gateway is required to understand the
information provided in this document.
Now that you are here, we assume you are well aware of SAP NetWeaver Gateway. Read on to know
more on one of the integrated services supported by Gateway, Easy Query!
We will see how to generate SAP NetWeaver Gateway service for SAP BW queries exposed via Easy
Queries. Gateways SAP BW integration shall provide a generic tool allowing an administrator at
customer side to easily expose existing SAP BW content as OData services.

2. Business Scenario
With the advent of the smartphone and multi-touch tablet, entrepreneurs and customers have
recognized the potential benefits of people centric applications for empowering employees with the
right to instantly access data.
People-centric applications very often include pieces of analytical information, which provides better
understanding of the business context, increase process efficiency, and support decision-making. It is
therefore important to make the analytical data and functions in our business systems available as
consumption models accessible via OData. Analytic queries are the main tools for consuming
analytical data.
SAP NetWeaver Gateway and SAP Business Warehouse (BW) Integration enables the SAP BW
content to be exposed as OData for SAP Analytic services for light weight mobile consumption.
SAP NetWeaver Gateway:
Provides an easy way of integrating SAP BW functionalities by using Multidimensional
expressions (MDX) and Easy Query.
Enables the adoption of existing analytical content in consumption scenarios based on OData.
Provides a simple representation of analytical data sets.
Provides support for simple interactions.

3. Prerequisites
The Supported Release Information of SAP NetWeaver Gateway with Easy Query:

GW SP05

BW 730 SP08 and above. BW 731 SP05


and above

Note: SAP NetWeaver Gateway with EasyQuery is also supported in GW SP04 and BW 730 SP05,
SP06, SP07. BW 731 SP00 to SP04, but with limited features.

How to Create OData Service for Analytic Queries

4. Creating EasyQuery on BW
The Query Design: BEx Query Designer is used to choose or define an EasyQuery.
To define a query as EasyQuery proceed as follows:
1. Define an EasyQuery using BEx Query Designer. While defining choose one of the following
options:

EasyQuery Without Advanced Selection Options

EasyQuery With Advanced Selection Options: Here Input parameters are provided by
Characteristic Value Variable of processing type manual input / default value In simple
words, User will be prompted to enter value for the Input Variable to fetch the Result.

2. Select By EasyQuery under Properties -> Extended tab, (refer the snapshot below for more
details).

More Details on EasyQuery on BW:

Details on Configuring Easy Queries

Details on Consuming Easy Queries

Details on BEx Query designer

How to Create OData Service for Analytic Queries

5. Generating OData Service for EasyQuery


This section guides you to generate an OData service for an EasyQuery using the Service Builder
application.
To generate an OData services for an Easy Query proceed as follows:
1. Go to the transaction SEGW. Choose

to create a new project.

2. Enter the details for the Project, Description, and Generation Strategy. In case the project
needs to be transported the package should not be $TMP.

3. In the context menu of the Data Model (of the new project), select Redefine BW Query
Service.
.

4. Enter the details as explained below in the Wizard to Redefine BW Query service:
Select Access Type as Controller for Easy Queries (SAP BW)
Enter the RFC Destination (F4 is also available to select the RFC Destination)
Enter the Query Name or Press F4 to select the EasyQuery from the defined BW System

How to Create OData Service for Analytic Queries

5. Click
to navigate to the second step of the wizard.
6. Enter the details for the Model Provider Class, Data Provider Class, Model Name and Service
Name along with the descriptions.
Note: Version of Model and Service will be suggested by wizard itself.

7. Click Next.
8. Now the Model provider, Data Provider, Model and Service for BW Query is generated. You
can view the generation status by clicking on (Display Log Icon) available in the Toolbar.
9. In the third step of the Wizard, select all artifacts.
Note: In the Wizard step 3 of 3: Redefine Service, user can select/deselect the artifacts . This
is called as Redefinition of the service. For more details refer Redefining Services from
External Framework (SPI, BW Query, and GenIL) under Related links

How to Create OData Service for Analytic Queries

10. Click
to complete the wizard.
The message Project XXX' has been checked; no errors were found is displayed.
11. After the creation of the project, you have an option to change the names and labels of the
artifacts.
To Change the Node Names, Property Names and Labels follow the below steps:
1. Switch to edit mode.
2. Choose the Redefine Attribute button
.
3. The Node Name, Property Names and the Label fields can be edited.
12. Click
to generate the runtime objects.
1. The model and service definition screen opens with pre-filled details of Model Provider,
Data Provider classes and Service Registration Details.
2. Under service registration, select the option to overwrite the extended service and click on
continue.
3. After successful generation, message Runtime objects for project XXX were generated
successfully is displayed.

...

How to Create OData Service for Analytic Queries

6. Registration and Activation of the Generated


Service
Note: Before Service Registration, user should check if Gateway system is configured or not. If not
configured, refer to Connection Settings to SAP NetWeaver Gateway and Creating the SAP System
Alias for Applications under Related Links.
To register an OData Service, double click on the Service Maintenance node. The ALV grid showing
the configured systems is displayed.
1. Select the Gateway System where this service needs to be registered and click
register the service.

to

2. Click Yes when the warning popup. Provide the system alias configured from Gateway HUB to
backend. Click Enter to continue.
For more details on system alias refer Service Maintenance under Related Links.
3. Add Service screen is displayed. Enter the package as $TMP and enter to continue.
Note: In case the registered service needs to be transported, then package details need to be
entered.

4. The registration status changes to a green node indicating the service is activated.

5. In Service Builder, Click


Maintain Services.

to maintain the service. A new screen opens to Activate and

6. Click
to open the service document in the browser. The URL is as follows
http://<HOSTNAME>:<PORT>/sap/opu/OData/sap/<SERVICENAME>/?$format=xml
7. Open the metadata by changing the above URL as below
http://<HOSTNAME>:<PORT>/sap/opu/OData/sap/<SERVICENAME>/$metadata

How to Create OData Service for Analytic Queries

7. Terminology
When an EasyQuery is generated as an OData Service, the metadata of the OData Service will
display OData specific terms. This section provides a list of EasyQuery terms and also OData specific
terms for EasyQuery.
Basic EasyQuery Terminologies
Terms

Description

Query

Access point for consuming logical data organized in


a multi-dimensional cube structure.
Query element used for creating perspectives on
data via drill-down and slicing.
Finite set of classifications representing the possible
instances of a characteristic.
A member has an ID, an associated text, and
attributes.
Facts for a combination of characteristic members.
Facts are key figure values with a defined
aggregation behavior.
Example, summation, average, minimum, maximum,
etc.
Placeholders for values assigned by the consumer
that may trigger extra logic before query execution,
Example, Determines a certain perspective on the
data cube by setting a filter for some characteristic.

QueryCharacteristic : key, Text


Characteristic members : Key, Text and
Attribute

Key Figures

Characteristic Value Variables

OData Specific terms for EasyQuery


EasyQuery Terms

OData Terms

OData Terms (GW)

Annotations

Semantics

Query with
advanced Selection

Query
parameters

<Query>Parameter
s entity

sap: semantics=
"parameters

Query result
Structures

Query Result

<Query>Result
entity

sap:
semantics=aggre
gate

Characteristic

Dimension

Property of a Result
Entity

sap: aggregationRole="dimension"

Key Figures

Measure

Property of a Result
Entity

sap: aggregationRole="measure"

Query Variables

Parameter
Property

Property of the
Parameter Entity

Can be either
sap: parameter=
"mandatory
sap: parameter=
"optional

Is Total

Totaled
Properties

Totaled Properties

sap: aggregationrole="totaledproperties-list"

How to Create OData Service for Analytic Queries

RowID

Entity Key

Entity Key Here it


is ID for each result
entity

How to Create OData Service for Analytic Queries

8. Service Document
8.1 Service Document for a simple Query
Let us analyze how a service document for a simple easy query is represented in OData (GW). In this
case we shall consider a query which does not require input parameter to get the results.
Below is the pictorial representation of the Service Document.

The Service document for an EasyQuery without Input Parameter:


1.

Lists only the Query result Entity set


Indicates that the Result Entity type represents the Query Result Structure

Below is the OData representation of the above EasyQuery

8.2 Metadata for an EasyQuery with Advanced Selection Options


Let us analyze how a service document looks in OData (GW) for an easy query which requires input
for determining the Result. Below is the pictorial representation of the Service Document.

The Service document for an EasyQuery with Input Parameter


1. Lists the query parameter entity set.

How to Create OData Service for Analytic Queries

2. Indicates that the Parameter Entity type represents Query Parameters.


3. Identifies the properties of Parameter entity and creates a new entity for Value Help. Also lists the
entity sets for Query Parameters
4. Lists the Query result Entity set.
5. Indicates that the Result Entity type represents Query Result Structure
Below is the OData representation of an Easy Query

How to Create OData Service for Analytic Queries

9. Metadata with Analytical Extension


9.1 Metadata for a simple EasyQuery
Let us consider an easy query which does not have any advanced selection options. It just consists of
four characteristics and two key figures.
EasyQuery in Query Designer:

OData representation of the above EasyQuery


Metadata URI: http://<HOSTNAME>:<PORT>/sap/opu/OData/sap/<SERVICENAME>/$metadata
http://<HOST>:<PORT>/sap/opu/odata/sap/ZCL_SALESORDERHISTORY_SRV/$metadata

In OData (GW) metadata shown above, apart from four characteristics and key figures you can see
there is more information like

ID -> Unique Identification of an Row in entity

Totaled Properties -> List of properties on which result is totaled

Formatted Property of the Key Figure-> Contains the formatted value of the key figure

How to Create OData Service for Analytic Queries

9.2 Metadata for an EasyQuery with Advanced Selection Options


Let us consider an easy query with advanced selection options. It just consists of three characteristics
and three key figures. Also an advanced selection option Vendors which is a Characteristic Value
Variable of processing type manual input / default value.
EasyQuery in Query Designer:

OData representation Of the above EasyQuery


Metadata URI: http://<HOSTNAME>:<PORT>/sap/opu/OData/sap/<SERVICENAME>/$metadata
http:// <Host> :< Port>/sap/opu/odata/sap/BUSINESSPARTNERORDERS/$metadata

How to Create OData Service for Analytic Queries

OData (GW) metadata shown above represents:

Query result structures in a result entity. This entity has Dimension, key Figures and
Formatted Key Figures.

Query result structures also contains ID (Unique Identification of a Row in an entity) and
Totaled Properties (List of properties on which result is totaled).

Query Variables in a Parameters entity. This entity has Query Variable and Query Variable
text.

Parameters entity also contains Navigation Property Results which will enable for the
navigation from parameters entity to Result entity. Below snapshots depicts the Navigation
from Parameters to Result.

How to Create OData Service for Analytic Queries

Value help for Query Variable is represented as a different entity. Below snapshot depicts the
Association from Query Parameters Value Help entity.

How to Create OData Service for Analytic Queries

10. Consuming the Service


Now that we have metadata, we will analyze BW data in OData (GW) representation.

10.1 Interacting with a simple Query


Here is a use case where the store Manager would like to analyze the sales order History
(transactions) of an outlet. For easy understanding, below is the comparison between the Sales order
history as seen in the SAP BW system and in OData (GW) format. Below is the Table and Chart
representation of Sales Order history

How to Create OData Service for Analytic Queries

Now we will see how to analyze the same from OData (GW) generated service. To create a Query
Operation URI follow the below mentioned steps:
Open the Ser vice Document of the OData (GW) gener ated ser vic e.

1. Open the Service Document of the OData (GW) generated service as explained in section 6.
Service Document for the EasyQuery in OData (GW) which has only Characteristics and Key
Figures looks similar to the snapshot given below:

2. Create a Query URI for the Query Result entity.


Add "href" attribute value to the URL i.e. <QueryName+Results>, forms the Query result
Collection
For example,
http://<Host>:<Port>/sap/opu/odata/sap/<ServiceName>/<QueryName+Results>
Final URI for a Query Result entity looks like the link given below :
http:// <Host>:<Port>/sap/opu/odata/sap/ZCL_SALESORDERHISTORY_SRV/
SALESORDERHISTORYResults
3. Once the above URL is executed, all the non-aggregated values of the measures are returned in
OData format.

Below is the mapping of data in SAP BW System and the same data in OData format.

How to Create OData Service for Analytic Queries

Now that we have results in OData format, let us see different cases of using the OData service:
Case 1: Sales manager would like to fetch the Salesorder History for an Outlet (Fetch Nonaggregated Results on a Single Dimension ) .
OData Request: In the above URL, add the $select OData command specifing the properties
representing measure (annotated as "sap: aggregation-role=measure") and the property representing
a dimension (annotated as "sap: aggregation-role=dimension").
For example:
http://<Host>:<Port>/sap/opu/odata/sap/ZCL_SALESORDERHISTORY_SRV/SALESORDERHISTOR
YResults?$select=A4S3XRZGY594U6GMJ3SAB0BTQ4,A4S3XRZOMO7QJP35Z9MCNADSFW,A0V
C_2STOR_T
By executing the above URL, aggregated measure values of an outlet is returned in OData format
which is shown below:

Case 2: Sales manager would like to see the SalesOrderHistory of the Customers of an outlet
(Fetch Aggregated Measure Values on more than one Dimension)
OData Request: In the $select OData command specifing the properties representing measure
(annotated as "sap: aggregation-role=measure") and more than property representing a dimension
(annotated as "sap: aggregation-role=dimension").
For example:

How to Create OData Service for Analytic Queries

http:// <Host>:<Port>/sap/opu/odata/sap/ZCL_SALESORDERHISTORY_SRV/
SALESORDERHISTORYResults?$select=A4S3XRZGY594U6GMJ3SAB0BTQ4,A4S3XRZOMO7QJP
35Z9MCNADSFW,A0VC_2STOR_T,A0VC_2CUST
By executing the above URL, the aggregated measure values i.e Salesorder of the Customers
belonging to an outlet and also the Salesorder history of an outlet is returmed in OData format. Same
is shown below :

Case 3: Sales manager would like to see the PurchaseOrderHistory of a particular Customer of
an outlet . (Fetch Aggregated Measure Values on a Dimension restricted to certain condition)
OData Request: You could filter out the result set by using $filter OData Command. $filter OData
command can be applied on those properties that are annotated "sap: aggregation-role=dimension".
Note:
$filter cannot be applied on those properties that are annotated as "sap: aggregation
role=measure" .
$filter can be applied only on those propertiesfor which filterable enabled.
For example:

How to Create OData Service for Analytic Queries

http:// <Host>:<Port>/sap/opu/odata/sap/ZCL_SALESORDERHISTORY_SRV/
SALESORDERHISTORYResults?$select=A4S3XRZGY594U6GMJ3SAB0BTQ4,A4S3XRZOMO7QJP
35Z9MCNADSFW,A0VC_2STOR_T,A0VC_2DPMT_T&$filter=A0VC_2CUST eq '10176982900'
Tip:

You could get the list of values for any dimension or dimension attribute by specifying them in
$select OData command without any Measures. This gives you the list of members for the
dimension.

If you like to slice the aggregated values for a particular dimension, use ne operator with
$filter OData command.

In this usecase, the records belonging to Customer 10176982900 is retrieved first and then the
aggregated value of each ProductCategory of an outlet is displayed. Same can be seen in the
snapshot shown below .

How to Create OData Service for Analytic Queries

How to Create OData Service for Analytic Queries

Case 4: To fetch top N aggregated Values


You could apply OData commands $top, $skip to your OData query request to fetch the top N
aggregated value.
OData Request :
http:// <Host>:<Port>/sap/opu/odata/sap/ZCL_SALESORDERHISTORY_SRV/
SALESORDERHISTORYResults?$select=A4S3XRZGY594U6GMJ3SAB0BTQ4,A4S3XRZOMO7QJP
35Z9MCNADSFW,A0VC_2STOR_T,A0VC_2DPMT_T&$filter=A0VC_2CUST eq
'10176982900'&$top=3&$skip=1
Note: OData Command $orderby is not supported.
Case 5: Sum of aggregated Measure Values
You could apply OData command $select on measure values and totaledproperties (annotated as
'sap-aggregation-role="totaled-properties-list"' in the Results Entity)
OData Request:
http://Host>:<Port>/sap/opu/odata/sap/ZCL_SALESORDERHISTORY_SRV/SALESORDERHISTORY
Results?$select=A4S3XRZGY594U6GMJ3SAB0BTQ4,A4S3XRZOMO7QJP35Z9MCNADSFW&Total
edProperties

10.2 Interacting with a Query with Advanced Selection Options


In this use case we have a business partner (referred as BP) who has ordered for a product with
product ID and receives the Purchase Order details for the same. Now the BP likes to analyze the
Purchase Order history of the products which was ordered.
The below snapshot depicts the table and chart representation of the purchase order history details in
SAP BW system.

How to Create OData Service for Analytic Queries

Now we will see how to analyze the same from OData (GW) generated service. To create a Query
Operation URI follow the below mentioned steps:
Open the Ser vice Document of the OData (GW) gener ated ser vic e.

1. Open the Service Document of the OData (GW) generated service as explained in section 6.
Service Document for the EasyQuery in OData (GW) which has only Characteristics and Key
Figures and Characteristic Value Variables looks similar to the snapshot given below:

2. Below is the step by step procedure of forming the Query URL.

Search for Parameters in the service document and add the "href" attribute value to the
URL.
For example:
http://<Host>:<Port>/sap/opu/odata/sap/<ServiceName>/< href attribute value >/
http:// <Host>:<Port>/sap/opu/odata/sap/BUSINESSPARTNERORDERS/
BUSINESSPARTNERORDERS
Now add $select = <Query Variable> to the above URI. This will display List of Entries for
the selected <Query Variable>
http:// Host>:<Port>/sap/opu/odata/sap/BUSINESSPARTNERORDERS/
BUSINESSPARTNERORDERS?$select=A0P_BP_SUPP

From the response choose one entry and replace < href attribute value >?$select=<
Query Variable> with value of "<link href="EntitySetName('Value') >
For example:
http://<Host>:<Port>/sap/opu/odata/sap/<ServiceName>/EntitySetName('Value')
http:// <Host>:<Port>/sap/opu/odata/sap/BUSINESSPARTNERORDERS/
BUSINESSPARTNERORDERS('100000025')
Adding "/Results" to the above link forms the query result Collection
For example:

How to Create OData Service for Analytic Queries

http://<Host>:<Port>/sap/opu/odata/sap/<ServiceName>/EntitySetName(P1 = V1)/Results
http:// <Host>:<Port>/sap/opu/odata/sap/BUSINESSPARTNERORDERS/
BUSINESSPARTNERORDERS('100000025')/Results
Note:
URL always first identifies values for the parameters in the parameter entity set and then
navigates to the query results for this parameterization. Example, service/Query (p1 ==
v1)/Results.
Even if a query parameter is annotated with sap:parameter="optional", the Query
Parameter should be part of the URL .
3. Once the above URL is executed, the results are aggregated based on the Input Variables and the
aggregated results is displayed in OData format as shown below :

Below is the mapping of data in SAP BW System and the same data in OData format

How to Create OData Service for Analytic Queries

Now lets see some of the usecases for the above generated OData service .
Case 1: To Fetch the list of Values for a Query Variable
You could apply OData command $select on an any Query Parameres (annotated as
sap:parameter="optional" or sap:parameter="mandatory") to fetch the list of values .
OData Request:
http:// <Host>:<Port>/sap/opu/odata/sap/BUSINESSPARTNERORDERS/
BUSINESSPARTNERORDERS? $select=A0P_BP_SUPPText,A0P_BP_SUPP
Note: At a time $select can be applied only on one Query Parameter and the associated text.
Case 2: To fetch the list of Values for a dependent dimension (Query parameter)
You could apply $select OData command on the QueryParameter for which you would like to fetch list
of values and apply $filter on the dependant dimension .
Now how do you identify if a Query parameter has a dependant diimension.
Well you can identify this by checking if the Queryparameter has an annotation sap:superordinate="Dependant Dimension"
For example:
<Property Name="P1" Type="Edm.String" Nullable="false" MaxLength="10" sap:parameter="optional"
sap:super-ordinate="Dependant dimension sap:filterable="false"/>
OData Request:
http:// <Host>:<Port>/sap/opu/odata/sap/BUSINESSPARTNERORDERS/
BUSINESSPARTNERORDERS? $select=P1&$filter=P2 eq V1
Note: $filter can be applied only on those parameters which are filterable.

11. References
After the creation of OData service , for the consumption of BW Queries via OData refer the
consumption part explained in the below given link :
http://www.youtube.com/watch?v=8TtHudIl_As

How to Create OData Service for Analytic Queries

12. Supported Features


All the features that are supported in OData (GW) for EasyQuery are listed below:
Topic

Feature

Catalog

Metadata

Description

OData Terms

OData(GW)

List of available
Queries/Resourc
es

Resource
repository - no
SAP Data Spec
topic

Implicitly provided
via the metadata
document

Query Result
Entity

Query Result
Entity

Description

Query/resource
description

Structure

Query Result
structure

Variables

Fields for
restrictions, which
are not contained
in result set

Value Help

List of available
values for Query
Variables

Query variable
Entity

Query variable
Entity

Characteristics in
rows

When
Characteristic is
configured to be
displayed as key

sap: aggregationrole="dimension"

sap: aggregationrole="dimension"

Only
Characteristic
Text in rows

When
Characteristic is
configured to be
displayed as Text

sap: aggregationrole="dimension"

sap: aggregationrole="dimension"

Base
Characteristic

Context is
provided by the
value of an
another property

sap: superordinate

sap: superordinate

Characteristic
Attributes

Attributes of a
characteristic

sap: attribute-for

sap: attribute-for

Characteristic:
Unit

sap: unit

sap: unit

key figures : raw


value

sap:
aggregationrole="measure"

sap:
aggregationrole="measure"

key figures:
formatted value

sap: text for key


figures- raw value

sap: text for key


figures- raw value

key figures: unit

sap: unit

totals, subtotals

sap: totals

Texts for
dimensions

sap: text

Query Input
Entity

Transform BW
tag to OData
annotation

Date Property

Date Property of
a Characteristic
or Query Variable

sap: displayformat=DATE

sap: displayformat=DATE

Mandatory or
Option Query
Variables

Represents if the
parameter
property is
mandatory or
Optional

Can be either
sap: parameter=
"mandatory
sap: parameter=

Can be either
sap: parameter=
"mandatory
sap: parameter=

How to Create OData Service for Analytic Queries

"optional

"optional

Can be
<parameter>
<ParameterTo>
annotated as
sap: upperboundary=
<
Lower Interval
Parameter>
or
sap-lowerboundary= <
Upper Interval
Parameter>

Can be either
sap: upperboundary=
<
Lower Interval
Parameter>
or
sap-lowerboundary= <
Upper Interval
Parameter>

Single Query
Variable
Interval Query
Variables

Runtime
Operations

Filter

Filter

$filter

$filter (Supported
on both Query
Variables and
Dimension)

Select

Select

$select

$select
(Supported on
both Query
Variables and
Properties of
Query Structure)

Top N

Top

$top

$top
(
Supported only
on Query
Structure)

Paging

Skip

$skip

$skip
( Supported only
on Query
Structure)

Count

Count

Count

Inline Count

InlineCount

$InlineCount

How to Create OData Service for Analytic Queries

13. Related Links


Help Document Links:
Creating the SAP System Alias for Applications
http://help.sap.com/nwgateway->Development Information ->Developers Guide ->SAP
NetWeaver Gateway Configuration Guide ->OData Channel Configuration -> Connection Settings:
SAP NetWeaver Gateway to SAP Systems -> Creating the SAP System Alias for Applications
Connection Settings to SAP NetWeaver Gateway
http://help.sap.com/nwgateway->Development Information ->Developers Guide ->SAP
NetWeaver Gateway Configuration Guide ->OData Channel Configuration -> Connection Settings
on the Backend System-> Connection Settings to SAP NetWeaver Gateway
Service Maintenance
http://help.sap.com/nwgateway->Development Information ->Developers Guide ->SAP
NetWeaver Gateway Developer Guide -> SAP NetWeaver Gateway Service Builder-> Service
Maintenance
Redefining Services from External Framework (SPI, BW Query, and GenIL).
http://help.sap.com/nwgateway->Development Information ->Developers Guide ->SAP
NetWeaver Gateway Developer Guide ->OData Channel -> SAP NetWeaver Gateway Cookbooks
-> OData Channel Cookbooks ->Getting Started with the Service Builder -> Redefining Services ->
Redefining Services from External Framework (SPI, BW Query, GenIL).
Redefining the Gateway services
http://help.sap.com/nwgateway->Development Information ->Developers Guide ->SAP
NetWeaver Gateway Developer Guide ->OData Channel -> SAP NetWeaver Gateway Cookbooks
-> OData Channel Cookbooks ->Getting Started with the Service Builder -> Redefining Services >Redefining Gateway Services

SCN Links:
http://scn.sap.com/people/zoltan.albrecht/blog/2012/02/13/OData-consumption-of-easy-queries
http://scn.sap.com/people/uwe.fischer/blog/2011/12/12/easy-queries-on-sap-netweaver-bw
http://scn.sap.com/community/netweaver-gateway/blog/2012/12/08/transform-sap-bw-queries-intoodata-service-generation-and-activation