Professional Documents
Culture Documents
ABAP Code - To Fetch SAP BI Query Data
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.
Table of Contents
Scenario ....................................................................................................................................................... 3 Step-by-Step Solution ................................................................................................................................ 3
Query Design ............................................................................................................................................................... 3 ABAP Code (Logic) ...................................................................................................................................................... 4 Execution ..................................................................................................................................................................... 7
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.
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 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.
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.
* Function Module to Fetch the Query Data CALL FUNCTION 'RRW3_GET_QUERY_VIEW_DATA' EXPORTING
i_infoprovider i_query i_t_parameter = w_i_infoprovider = w_i_query = t_i_parameter = t_axis_info = t_cell_data = t_axis_data = 1 = 2 = 3 = 4 = 5 = 6 = 7.
IMPORTING
e_axis_info e_cell_data e_axis_data
EXCEPTIONS
no_applicable_data invalid_variable_values no_authority abort invalid_input invalid_view
OTHERS 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.
Execution Execute the ABAP Code and enter the values for month, material and data packet
ABAP Code Report (Displays the values which are updated in DSO):
Related Content
Help.sap Link For more information, visit the EDW homepage.