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

ABAP Code – To fetch SAP BI

Query Data

Applies to:
This article is applicable to all the SAP BI 7.0 consultants who are novice with SAP ABAP skills. For more
information, visit the EDW homepage.

Summary
This document specifies the detailed understanding of using the standard SAP BI function modules
(RRW3_GET_QUERY_VIEW_DATA) to fetch the Query data.

Author: Suraj Tigga


Company: Capgemini Consulting India Pvt. Ltd.
Created on: 08 July 2010

Author Bio

Suraj Tigga is a Senior SAP BI / ABAP consultant at Capgemini Consulting, India. Suraj joined
Capgemini Consulting in 2008 and has worked on multiple SAP BI implementation and
support Projects.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 1
ABAP Code – To fetch SAP BI Query Data

Table of Contents
Scenario ....................................................................................................................................................... 3
Step-by-Step Solution ................................................................................................................................ 3
Query Design ............................................................................................................................................................... 3
ABAP Code (Logic) ...................................................................................................................................................... 4
Execution ..................................................................................................................................................................... 7
Related Content ............................................................................................................................................ 9
Copyright ....................................................................................................... Error! Bookmark not defined.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 2
ABAP Code – To fetch SAP BI Query Data

Scenario
 To fetch the query output values and fed the data to a direct DSO.To handle huge amount of data
we have to design the ABAP code to support specific data package entered in the selection screen.

Step-by-Step Solution
ABAP Solution is explained in two sections:
Query Design: Shows the query elements whose values would be fed into Direct DSO
ABAP Code (Logic): Briefly explains the flow logic of the code.

Query Design
Technical Name: ZPHMMINM19_DJ28_INVENTORY

Query is built on a multiprovider PHMMINM19 which contain the material movements corresponding to
different regions. Now the key figure 0TOTALSTCK (Quantity Total Stock) is non-cumulative (which is based
on 0RECTOTSTCK (Receipt Quantity Total Stock) and 0ISSTOTSTCK (Issue Quantity Total Stock)).

Our aim was to fetch the values of 0TOTALSTCK specific to every month in a year. Since this is a non
cumulative key figure so the mapping of this key figure to any next level data target is not possible .So to get
the values we have to use BI query, which is further fed into direct DSO. To suffice this particular
requirement we have created a ABAP code which would pick the query output data for a particular month
and update the values in direct DSO.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 3
ABAP Code – To fetch SAP BI Query Data

ABAP Code (Logic)


Step1: Built a selection screen which gets the values for Calendar Month, Materials, Data Packets and a
checkbox for Update DSO (If checked then the query data is fed to Direct DSO)

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.


* Selection screen input fields for Input
PARAMETERS:
* Month
p_month TYPE /bi0/oicalmonth OBLIGATORY.
* Material
SELECT-OPTIONS:
s_mat FOR /BI0/MMATERIAL-material.
* Package Size
PARAMETERS: p_pack(7) TYPE n ,
* Update DSO
p_upd AS CHECKBOX DEFAULT ' ’.
SELECTION-SCREEN END OF BLOCK b1.

When the ABAP code is executed in background then by default the last month values would be fetched
(Which would be executed for all the materials ranging from 00000001 to 10000000)
While executing the code in background a default variant has to be saved with values mentioned:
Month: 02/2010
Material: Range (00000001 to 10000000)
No of Data Packets: 1000
Update Data (DSO): Checked
Step2: Define the packet size with reference to the values entered in selection screen. This further defines
the low and high values for the materials
As mentioned above about the package size which has to be maintained so that the code works for the huge
data set records.
Since the data packet size is 1000 and total material range is (00000001 to 10000000).So for each iteration
(Of materials depending on the packet size) equal to [ (Material High Value) / (Packet Size) ] the function
module RRW3_GET_QUERY_VIEW_DATA is called.
Material High Value / Packet Size = (10000000 / 1000) = 10000.
Iteration 1: 00000001 – 00010000
Iteration 2: 00010001 – 00020000
Iteration 3: 00020001 – 00030000
Iteration count values would be stored in variable l_count .Simultaneously the low and high values would be
stored in wl_range-low and wl_range-high.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 4
ABAP Code – To fetch SAP BI Query Data

Step3: Populate the parameters to be filled before the function module RRW3_GET_QUERY_VIEW_DATA is
called
Brief details about the Function Module
Import Parameters:
I_INFOPROVIDER: Infoprovider name
I_QUERY: Query name
I_T_PARAMETER: Contains the selection conditions based on which the query data is returned
Export Parameters:
E_CELL_DATA: Contains Key Figure values
E_AXIS_DATA: Contains Characteristic Values
ABAP Code

* Infoprovider
w_i_infoprovider = 'PHMMINM19'.
* Query Name
w_i_query = 'ZPHMMINM19_DJ28_INVENTORY' .
* Calmonth
wa_i_parameter-name = 'VAR_NAME_1'.
wa_i_parameter-value = '0I_CALMO'.
APPEND wa_i_parameter TO t_i_parameter.
CLEAR wa_i_parameter.
wa_i_parameter-name = 'VAR_SIGN_1'.
wa_i_parameter-value = 'I'.
APPEND wa_i_parameter TO t_i_parameter.
CLEAR wa_i_parameter.
wa_i_parameter-name = 'VAR_OPERATOR_1' .
wa_i_parameter-value = 'BT'.
APPEND wa_i_parameter TO t_i_parameter.
CLEAR wa_i_parameter.

* Calmonth
wa_i_parameter-name = 'VAR_VALUE_LOW_EXT_1' .
wa_i_parameter-value = p_month.
APPEND wa_i_parameter TO t_i_parameter.
CLEAR wa_i_parameter.
wa_i_parameter-name = 'VAR_VALUE_HIGH_EXT_1'.
wa_i_parameter-value = p_month.
APPEND wa_i_parameter TO t_i_parameter.
CLEAR : wa_i_parameter.

* Material
CONCATENATE 'VAR_NAME_' l_count INTO l_name.
wa_i_parameter-name = l_name.
wa_i_parameter-value = '0S_MAT'.
APPEND wa_i_parameter TO t_i_parameter.

CONCATENATE 'VAR_SIGN_' l_count INTO l_sign.


wa_i_parameter-name = l_sign.
wa_i_parameter-value = 'I'.
APPEND wa_i_parameter TO t_i_parameter.

CONCATENATE 'VAR_OPERATOR_' l_count INTO l_operator.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 5
ABAP Code – To fetch SAP BI Query Data

wa_i_parameter-name = l_operator.
wa_i_parameter-value = 'BT'.
APPEND wa_i_parameter TO t_i_parameter.

CONCATENATE 'VAR_VALUE_LOW_EXT_' l_count INTO l_value.


wa_i_parameter-name = l_value.
wa_i_parameter-value = wl_range-low.
APPEND wa_i_parameter TO t_i_parameter.

CONCATENATE 'VAR_VALUE_HIGH_EXT_' l_count INTO l_value.


wa_i_parameter-name = l_value.
wa_i_parameter-value = wl_range-high.
APPEND wa_i_parameter TO t_i_parameter.

Call the Function Module :


* Function Module to Fetch the Query Data
CALL FUNCTION 'RRW3_GET_QUERY_VIEW_DATA'
EXPORTING
i_infoprovider = w_i_infoprovider
i_query = w_i_query
i_t_parameter = t_i_parameter
IMPORTING
e_axis_info = t_axis_info
e_cell_data = t_cell_data
e_axis_data = t_axis_data
EXCEPTIONS
no_applicable_data = 1
invalid_variable_values = 2
no_authority = 3
abort = 4
invalid_input = 5
invalid_view = 6
OTHERS = 7.
IF sy-subrc EQ 0.

 Internal table t_axis_data contains the characteristic value


 Internal table t_cell_data contains the key figures values
 Combine the data fetched in both the above internal tables and store those to internal table
t_final(Which would further update the Direct DSO)

ENDIF.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 6
ABAP Code – To fetch SAP BI Query Data

Execution
Execute the ABAP Code and enter the values for month, material and data packet

Values are fetched from the Function Module

Check the values in the input parameter:

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 7
ABAP Code – To fetch SAP BI Query Data

Values for Characteristics and Key Figures are fetched:

T_cell_data; Contains the Key Figure values

T_axis_data: Contains the Characteristic values

ABAP Code Report (Displays the values which are updated in DSO):

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 8
ABAP Code – To fetch SAP BI Query Data

Related Content
Help.sap Link
For more information, visit the EDW homepage.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 9
ABAP Code – To fetch SAP BI Query Data

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not
supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the i nformation, code or methods suggested in this document,
and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or
code sample, including any liability resulting from incompatibility between the content within this document and the materials a nd
services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this
document.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 10

Вам также может понравиться