You are on page 1of 18

27/1/2019 BEx queries and OData in BW 7.

4 | SAP Blogs

Products
Products Industries
Industries Support
Support Training
Training Community
Community Developer
Developer Partner
Partner

About
About

 
Ask a Question Write a Blog Post Login

Miguel Peredo Zurcher


February 8, 2016 5 minute read

BEx queries and OData in BW 7.4


Follow RSS feed

2 Likes 13,355 Views 19 Comments

This is a post about how easy it is to release a BEx query for OData consumption.

Let’s say that your Ecommerce solution needs to get the quantity available in stock for a speci c material at
a speci c plant. This can be achieved by making the Ecommerce solution call to an OData enabled BEx query in
your BW.

Most “modern” applications can speak OData, for example SAP Fiori, SAP NW, and Microsoft Azure. More
info and some nice diagrams about OData and BEx queries can be found here.

These are the steps to follow to make a BEx query available for OData consumption:

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 1/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

1. Setup the integrated SAP Gateway in your Netweaver 7.4


2. Mark the query as Odata enabled, and publish it
3. Find a test client to check the structure and values

To demonstrate step 3 I’lll use a ready made solution on the BW side, and a Python program as my
Ecommerce solution.

Security note: in this example I’m using plain text authentication, meaning that the credentials will travel
through the network without encryption. This is not suitable for production use.

Let’s start:

Setup the integrated SAP Gateway in your Netweaver 7.4


For this, I could not nd a speci c note related to OData and BEx queries, but I found this note: “2113675 –
RSPCM_WEB transaction error with 403 Forbidden” which talks about another nice feature about 7.4 which
is the new APP for Process chain monitoring in UI5. Since this APP is based on UI5 which uses OData for
communicating to the back-end, we can use this note also for our purpose.

Follow only the three steps in the st part of the note: “I.Con guration of Gateway”.

Mark the query as Odata enabled and publish it


 

Note that the following is a simple query that just returns the stock quantity for material and plant, it does
not have any input ready variables. The date is handled via a non input ready variable.

While testing you can put some static lters in your query, like 5 materials, and 2 plants, to avoid getting the
list of all materials and all plants. In the nal version the lter for material and plant will come from the
OData query string.
https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 2/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

The query looks like this:

Note that “By Odata” ag is turned on.

When saving the query check that there are no error messages, usually those are authorization related.
When you save a query with the OData ag on, the system auto-generates some things related to OData.

In this case the query name is: Z_ODATA_INVENTORY

Now we need to release the service for OData, we can follow the instructions from here.

Go to transaction: /IWFND/MAINT_SERVICE and press add service:

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 3/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Then from the list (if the list is empty you can press “Get services” button) select the line that contains the
query with a _SRV su x and press “Add selected services”

Accept the default values, and press OK.

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 4/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Note: If by any reason you cannot see the new service, you can force the generation of the service
for the query using function module: RSEQ_NAT_GENERATION in SE37. Just ll the the technical name of
the query in the input structure.

Now you can go to this URL:http://host:port/sap/opu/odata/sap/Z_ODATA_INVENTORY_SRV/$metadata

And you should be able to see the XML de nition of the query/service:

The relevant information here are the two characteristics from Rows section that can be found by key and
text, with the “_T” su x. The key gures from the Columns section are
A00O2TM5ZRDCVNYBZ57LAF99TM and A00O2TM5ZRDCVNYBZ57LAF99TM_F (the “_F” su x means
formatted, in this case with Unit).

Now the query is ready to be consumed by any OData system.

Find a test client to check the structure and values

I’ve been playing around with OData in Azure before, and the best client I could nd (this was in November
2015) is: XOData®: OData Visualizer and Explorer – PragmatiQa available here. Note that I’m using the paid
version.
At the end I will also call this OData service from Python.

Let´s open XOData and choose this options:

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 5/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Then press the “Use this Setup” button

In the next screen:

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 6/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Choose OData Metadata URL, then enter the URL of our query, and press Get. Then you can switch to the
next tab.

Here you can see again the elds that the service is returning. Now let’s go the next tab “Query builder”. Play
a little and do a query like this:

In (A) you have the OData query that can be used to get the inventory quantity for a speci c material and
plant. You just need to replace the values in quotes with your material and plant key.

At the bottom is the result:

B -> Material key

C -> Material text

D -> Plant key

E -> Plant text

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 7/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

F -> Key gure without format or unit

G -> Key gure with format and unit.

And that’s it, any application that speaks OData can request the inventory quantity for any material and
plant.

Now let´s try to do the same from Python:

I used PyCharm Community Edition and Python 3.5. I also added these two modules with from command
prompt:

>pip install requests

>pip install feedparser

import requests

import feedparser

# These are the elds from the XML le in the URL of the query.

elds = {‘d_a0material_t’
‘d_a0material_t’: ”, ‘d_a0material’
‘d_a0material’: ”, ‘d_a0plant’
‘d_a0plant’: ”, ‘d_a0plant_t’
‘d_a0plant_t’: ”,
‘d_a00o2tm5zrdcvnybz57laf99tm_f’: ”}
‘d_a00o2tm5zrdcvnybz57laf99tm_f’

# Replace the values for your host, port, user and password, plant and material

r=
requests.get(‘‘http://host:port/sap/opu/odata/sap/Z_ODATA_INVENTORY_SRV/Z_ODATA_INVENTORYRes

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 8/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

ults?$top=20&$ lter=A0PLANT eq \’
\’YOURPLANT
YOURPLANT\’
\’ and A0MATERIAL eq \’
\’YOURMATERIAL
YOURMATERIAL\’
\’‘‘, auth=
(‘youruser’
‘youruser’, ‘yourpass’
‘yourpass’))

if r.status_code == 200:

d = feedparser.parse(r.content)

data = d[‘entries’
‘entries’][0]

for item in elds:

elds[item] = data[item]

for item in elds:

print ( elds[item])

else:
else

print(r.status_code)

This is the output:

In line 1 we get the material description, on the next line we see “1.0 PC” that is the formatted quantity, on
line 2 we get the plant description, on line 3 we get the material key, and on line 4 is the plant key.

This is it!

Hope you enjoyed this example. If you have managed to use OAUTH for this queries, please share.

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 9/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Thanks!

Tested on BW 7.4 SP11

Other great blogs about OData: OData – Everything that you need to know (Part 1)

Like Alert Moderator

Assigned tags

BW (SAP Business Warehouse) | NW ABAP Gateway (OData) | bex | odata | python |

View more...

Related Blogs

SAP BW – Feature Overview and Platform Availibilty


By Former Member , Jan 28, 2015

SAP BW Testing Episode 2 – System testing


By Former Member , Jan 13, 2014

Using SAP BEx and SAP BO as an alternative to report SAP BPC data for Financial Consolidation
By Fernando Faian , Apr 07, 2017

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 10/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Related Questions

Functiona Upgrade plan for SAP BW 7.4 Oracle DB


By Former Member , Aug 17, 2017

Do we need BW Java stack ?


By Ram Kurapati , Jan 08, 2018

Xcelsius 2008 dashboards - Are they compatible with BW 7.40?


By PAVAN SAPHANA , Jan 16, 2017

19 Comments

You must be Logged on to comment or reply to a post.

Former Member

May 11, 2016 at 10:11 pm


Hello Miguel

It’s a really interesting blog. I have an issue in its implementation:

I have marked OData ag in my query, but I can’t see it in /IWFND/MAINT_SERVICE tx, in order to select the service.

When I press “Get services” button appear many services except mine.

I have checked Gateway Con guration and it looks ne. I am working in embedded deployment and my system is Netweaver
7.4 SP8.

Please do you have any idea about the cause?

Thanks in advance.

Best regards

Cesar Begazo

Like (0)

Former Member

May 12, 2016 at 8:11 am


Hello Cesar,

No idea, sorry. But just in case check note:

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 11/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

2103222 – Generation and Transportation of BExQuery with active OData-Flag

Also make sure that the BEX query designer in your PC is up to date, and pay attention to messages when
saving:

“When saving the query check that there are no error messages, usually those are authorization related. When you save a
query with the OData ag on, the system auto-generates some things related to OData.”

I my case I was lacking some authorization objects, and thus it was not generating the objects when saving, but was showing
some warning in the Bex query designer.

Best regards,

Miguel

Like (0)

Vanessa Martinez

May 20, 2016 at 7:43 am


Hi Miguel Peredo Zurcher thanks for this great tutorial.

Like (0)

Former Member

June 13, 2016 at 4:11 pm


Hello Cesar,

I have the same problem. After create the query with the odata ag. I don’t see the service.

Have you been able to solve it?

Like (0)

Former Member

June 13, 2016 at 9:42 pm


Hello Jordi

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 12/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

I have solved the problem. In my case, my query was not in a transport request, because that OData objects
couldn’t be created.

I used transport connection to assign query to a transport request. It resolve the problem.

Best regards

Like (0)

Eduard Sanz

July 19, 2017 at 12:55 pm


i’have the same problem. My query is in a transport request and I’ve executed  RSEQ_NAT_GENERATION.
The service is not showed in   /IWFND/MAINT_SERVICE

Like (0)

Rachid Kaouass

August 17, 2016 at 7:23 am


Hi,

nice blog, I’ve succeeded to generate my oData service and consume it.

We wanted to get the data from a drilldown as we can do using the BEx Query, however, I don’t see how to
manage the “drilldown” using the oData Service.

I think it is not possible but I prefer to ask to be sure 🙂

Regards,

Rachid

Like (0)

Miguel Peredo Zurcher | Post author

August 19, 2016 at 7:25 pm


Hello Rachid,

Not sure if I understood you correctly. The drilldown happens at the frontend, if you manage to a write a
frontend that detects when the users does a drilldown, and then generates the new query, that’s it.

If you are talking about hierarchies, those are not supported.

Regards,

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 13/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Miguel

PS.: Check also this: Connect to an OData feed (Power Query) – Excel

Like (0)

Rachid Kaouass

August 20, 2016 at 11:24 am


Hi,

I don’t know if it is Hierarchies, but let me explain di erently:

When you execute a Bex Query, you can right-click on the report, on a certain value, and then you can drill
down. So in that case a new column will be displayed and still using the same Query.

Unfortunately, using the generated oData, they are not ways to request this detail with the same Bex Query.

I had to ask to generate a Bex Query that display every column, and then I did in the UI5 application the
aggregation and the drill down.

I don’t know if it is the hierarchies, that you mention.

Best regards,

Rachid

Like (0)

Former Member

September 19, 2016 at 12:27 pm


Hi Miguel,

I am trying to do the exactly same thing .

Created a BEx query ; enabled the By Odata checkbox ; publsihed using the Tcodea and tests ne in the NW
gateway.

In the browser, I was able to generate the metadata but when I try to do /QuerynameResults,

it throws me

ERROR: Access using a ‘ZERO’ object reference is not possible. (termination: RABAX_STATE)

Searching through all available online sources, I understand that my Odata service is absolutely correct and
could generate the Metadata perfectly ne.

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 14/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Can you help me in understanding what the issue can be?

Regards,

Deep

Like (0)

Miguel Peredo Zurcher | Post author

September 21, 2016 at 4:09 pm


Hello Deep,

I think the best way is to open an OSS message.

Br,

Miguel

Like (0)

Miguel Peredo Zurcher | Post author

October 20, 2016 at 6:20 pm


Hello,
In other system I ran in the the same issue that the service was not being generated. I did a trace and I found
that you can generate the service for the query using function module: RSEQ_NAT_GENERATION in SE37. Just
ll the the technical name of the query in the input structure.

Like (0)

Former Member

March 21, 2017 at 7:04 am


Hi Miguel,

Thank you for the Blog!

I am new to BW/BI, i have the same requirement as your example is, But the problem is that “By

oData” option is missing in my Query Designer to expose it as oData service,

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 15/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

My Query Designer Version is:

How to enable “By oData” option? Is this because of lower level Support Package?

Please help me with this,

Regards,

Karthik Sridhar

Like (0)

Arne Witte

March 23, 2017 at 10:25 am


Hi,

you need to update your BI Addon front end tools. Query Designer SP0 is too low. Just take the actual SP,
then the option will be displayed. I have installed SP7 and the option is available.

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 16/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Regards,

Arne

Like (0)

Former Member

March 22, 2017 at 4:58 pm


Very cool! Thanks for the e ort.

Like (0)

Former Member

March 28, 2017 at 6:25 am


HI Guyz,

I am facing the same problem, I have collected the query in transport request, and i have tried generating
the service via the  functional module, i am still not able to generate a service.

Any pointers would be helpful !!!

Like (0)

Former Member

August 3, 2017 at 12:24 pm


Hi Miguel,

Any experience with implementing Odata Version 4 for a BW query?

The automatic generation is only Version 2.

Thanks, Anders

Like (1)

Wolfgang Lindner

September 1, 2017 at 10:04 am


 

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 17/18
27/1/2019 BEx queries and OData in BW 7.4 | SAP Blogs

Hi all,

based on the following documentation


https://help.sap.com/saphelp_nw74/helpdata/en/f3/0c7316de924a98bb173904f7a61b4a/frameset.htm?
frameset=/en/c9/384c774bcc4837b84bee3679520fb4/frameset.htm&current_toc=/en/22/c927d9cd6f4
8d18cf4793ccce1cb71/plain.htm&node_id=110

the oData enabled query does not supported the central hub architecture.

Is that correct?

My goal is to consume the query with a Fiori frontend by using a separate gateway system as recommended
by SAP.

Do I have to use the easy query instead?

Regards

Wolfgang

Like (0)

Sangharsh Aggarwal

November 16, 2018 at 10:36 pm


Thanks Miguel for the wonderful blog. On the t-code /n/IWFND/MAINT_SERVICE, after hitting the “Add
Service” button, the next screen does not bring me any Backend Service. I have tried all the options you
mentioned here. But none worked. Also, for me System Alias eld populates whatever I entered last and
can’t blank it out. Plus there is nothing that works on that eld. Everything pops error: System alias ‘ABC’
does not exist.

Like (0)

Share & Follow

Privacy Terms of Use

Legal Disclosure Copyright

Trademark Preferencias para cookies

Sitemap Newsletter

https://blogs.sap.com/2016/02/08/bex-queries-and-odata-in-bw-74/ 18/18

You might also like