Reading SAP BEx Queries via REST Service
Reading SAP BEx Queries via REST Service
> Craft > Technology > Approach > Discover Us > Insights
Tanya Vryashkova
Success Stories Planning More
Nov 5, 2021 · 4 min read
For this purpose, we have developed an ABAP program which can dynamically
get data from any BW Query and pass it for transfer via a REST API call.
As a first step, we had to choose the best format for presenting BEx query data.
The most popular lightweight text format for data interchange is JSON
(JavaScript Object Notation). It presents a human-readable collection of data
which can be consumed by web services and APIs.
The second step was to find best way for reading BEx query data and
transforming it in JSON format. As an example, we will use a simple query with
one characteristic "Calendar Year/Month" in columns and Key Figure "Total
Profit" in rows for the sake of walking through the implementation (see Picture
1).
We use cookies on our website to see how you interact with it. By
Settings Accept all
accepting, you agree to our use of such cookies. Privacy Policy
https://www.dahlbeer.com/post/reading-sap-bex-queries-via-rest-service 1/9
4/15/25, 4:45 PM Reading SAP BEx Queries via REST Service
Exploring data from SAP BEx queries can be done using standard functionality
from SAP. No additional changes to existing queries are required, one can fetch
the data and use it. The function module (FM) RRW3_GET_QUERY_VIEW_DATA
returns the structure and content of the query data, which makes it easier to
display it via a web service. This function allows advanced query control via
run-time defined parameters. These parameters represent the defined query
variables using BEx query designer or BW modeling tools.
We use cookies on our website to see how you interact with it. By
accepting, you agree to our use of such cookies. Privacy Policy
https://www.dahlbeer.com/post/reading-sap-bex-queries-via-rest-service 2/9
4/15/25, 4:45 PM Reading SAP BEx Queries via REST Service
We use cookies on our website to see how you interact with it. By
accepting, you agree to our use of such cookies. Privacy Policy
https://www.dahlbeer.com/post/reading-sap-bex-queries-via-rest-service 3/9
4/15/25, 4:45 PM Reading SAP BEx Queries via REST Service
The internal table "e_cell_data" represents cell data. In our example it contains
values for the Key Figure “Total Profit” for each Calendar Year/Month. The first
row keeps value “11,00 EUR” for “01.2019” (see Picture 5). The most important
fields in this table are "VALUE" and “FORMATTED_VALUE”. Both fields keep values
for Key Figures, the field "VALUE" keeps the raw value, while "FORMATTED_VALUE"
keeps the value with its formatting. The formatting contains objects like
currency symbols and numeric conventions. If the query data is displayed in
tables, the field "FORMATTED_VALUE" is preferred, because it contains all the
formatting, which is needed. When it is required to perform further calculations
like summationor display in chars, it is better to use the "Value" field.
Picture 5 "E_CELL_DATA"
In our program, we combine results from these three tables in a single internal
table (see Picture 6). It is done via several steps. The first step makes a list with
all characteristics from the columns ("E_AXIS_DATA" - "SET", AXIS=0). The
second step creates dynamic structure type from the list with all
characteristics and two additional fields "KEYFIGURE" and "VALUE". In doing so,
our result table has a dynamic structure depending on the BEx query. The fields
in result table are based on Characteristics used in the query. The next steps
populate the result table with query data through several loops.
We use cookies on our website to see how you interact with it. By
accepting, you agree to our use of such cookies. Privacy Policy
https://www.dahlbeer.com/post/reading-sap-bex-queries-via-rest-service 4/9
4/15/25, 4:45 PM Reading SAP BEx Queries via REST Service
After the result table is ready, it is straightforward to create a JSON file with
query data. SAP provides a standard functionality for converting internal tables
to xml, see code below.
We use cookies on our website to see how you interact with it. By
accepting, you agree to our use of such cookies. Privacy Policy
https://www.dahlbeer.com/post/reading-sap-bex-queries-via-rest-service 5/9
4/15/25, 4:45 PM Reading SAP BEx Queries via REST Service
We use cookies on our website to see how you interact with it. By
accepting, you agree to our use of such cookies. Privacy Policy
https://www.dahlbeer.com/post/reading-sap-bex-queries-via-rest-service 6/9
4/15/25, 4:45 PM Reading SAP BEx Queries via REST Service
If the receiving Web service requires the query data in a specific JSON format,
it could be done through a loop on the result table. In the loop, we can
manipulate the query data in required format (see Picture 8).
We use cookies on our website to see how you interact with it. By
accepting, you agree to our use of such cookies. Privacy Policy
https://www.dahlbeer.com/post/reading-sap-bex-queries-via-rest-service 7/9
4/15/25, 4:45 PM Reading SAP BEx Queries via REST Service
We use cookies on our website to see how you interact with it. By
accepting, you agree to our use of such cookies. Privacy Policy
https://www.dahlbeer.com/post/reading-sap-bex-queries-via-rest-service 8/9
4/15/25, 4:45 PM Reading SAP BEx Queries via REST Service
Finally, we have our query data in JSON format. Web services and APIs can
consume it in this format. Additional information about REST Service
Integration in SAP BW could be found here.
• SAP HANA
Book a Call
We use cookies on our website to see how you interact with it. By
accepting, you agree to our use of such cookies. Privacy Policy
https://www.dahlbeer.com/post/reading-sap-bex-queries-via-rest-service 9/9