Technical Articles
How to consume an analytical query / BEx Query in ABAP
How can I consume an analytical query in ABAP ?
Normally analytical queries are used with reporting tools like SAC, Analysis Office, WebDynpro Grid, or RSRT in backend.
This post show how to directly access and use the query within your own ABAP application by the use of Lightweight BICS API ( LBA ) .
It’s really easy and needs only 2 ABAP calls . Development was driven by the need for testing the query with unit test. But for sure this approach also fits to others usecase where you want to use the query in your ABAP application.
This example show the most simple case. Calling a query without variables.
DATA(lr_std_query) = NEW cl_lba_std_query( i_query_name = 'MyQueryName' ). lr_std_query->get_resultset( "EXPORTING i_t_requested_columns = lt_requested_columns "dimensions&keyfigures for resultset " i_t_variable_values = lt_variable "mandatory and optional variables " i_t_filter_values = lt_filter "additional filters IMPORTING e_r_resultset = DATA(lr_resultset) "resultset table e_t_column_catalog = DATA(lt_column_catalog) ). "resultset description
LBA comes also with a 2nd flavours to call the CDS based query.
DATA(lr_std_query) = NEW cl_lba_cds_query( i_view_name = 'MyCDSview' ). lr_cds_query->get_resultset( ...
Query in this context means BW modelled queries:
- CDS based analytical queries ,
- Query modelled using BW modelling tools ( BWMT )
- Query modelled using BEx Query Designer
Note 3269710 contain further details like available releases and has 2 attachments
with several sample cases for CDS based queries and classical analytical queries.
dear Martin,
nice feature, thanks for sharing; Thanks also to Frank Riesner who shared this blog!!!
an idea for improvement; could be possible to call this API remotely from another Netweaver system?
Thanks,
Manos
Hi Manos,
sure you can call this remotely.
Just put the method call inside an remote enabled function module.
regards, Martin
Hi Martin,
is this working in S4 I guess, correct ?
I am trying the examples provided in Note 3269710 on CDS based query but I am getting an empty resultset.
Thank you
AR
Hi Antonio,
compare the resultset call with RSRT and make sure to have same resultset definition (same variables setting, same filter setting, dimension in resultset.
In contrast to RSRT where query designtime is considered LBA uses all dimensions for resultset if method GET_RESULTSET has empty I_T_REQUESTED_COLUMNS.
regards, Martin
Hi Martin,
is it possible to get totals within the result set?
Hi Stefan,
yes, result is considered with regards to query designtime definition.
At the moment not possbile with CDS based queries.
regards, Martin