Professional Documents
Culture Documents
org
Contents
1. Reporting Scenario requiring VKF ................................................................................................... 1
2. Create a Key Figure (VKF) and add it to the infocube, multiprovider ............................................. 2
3. Create Classic BAdi Implementation with appropriate parameters and code in the methods ...... 3
4. Create a query with the VKF and debug it ...................................................................................... 6
5. Identify position(s) of parameters and update the ABAP code ...................................................... 6
6. Create a BO4 Webi /OLAP Analysis report based on the BEx query via BICS ................................. 7
7. Possible impact on other queries and performance....................................................................... 7
First of all I do not advise using Virtual Key Figures (VKF) unless you really have to. The reason for
that is twofold: they are difficult to maintain, and they may impact query performance dramatically.
However, there are certain reporting scenarios where it is impossible to deliver a proper BI reporting
solution without a VKF. For example, we have a Credit Limit set as an attribute of 0Customer and it is
periodically updated. We also want to display Credit Limit in the reports as a Key Figure in order to
apply currency conversions, aggregations by maximum value, etc. Having KF as an attribute of an
infoobject does not give us these capabilities. At the same time if we copy the Credit Limit to the
transactional object (Infocube) we would have to fully refresh it every time as the Credit Limit values
get updated for each customer. Full cube refresh is not a great option in case of big data volumes.
This scenario leads us to a solution where we have to introduce a VKF and populate it at the report
run time based on the current Credit Limit values from the Customer master data.
In this post I will show how the scenario described above has been implemented and tested using
BO4 frontend tools, addressing possible performance risks.
1
www.biportal.org
Add the VKF to the infocube(s) and multiprovider(s) where it is going to be used. In the
transformation to the cube the VKF does not have to be mapped.
2
www.biportal.org
You have to create your own implementation based on it and link it to relevant infoprovider(s).
In the Attributes tab you have to enter Input/ Output parameters as well as internal tables that you
want to use at the run time.
3
www.biportal.org
public section.
interfaces IF_EX_RSR_OLAP_BADI .
types:
begin of ty_cust,
CUSTOMER TYPE /BI0/OICUSTOMER,
/BIC/CDM_LIMI1 TYPE /BIC/OICDM_LIMI1,
/BIC/ZCUR TYPE /BIC/OIZCUR,
end of ty_cust .
data P_KYF_CDM_LIMVK type I .
data P_CHA_0DEBITOR type I .
data P_CHA_ZCUR type I .
data:
T_CUST type HASHED TABLE OF ty_cust WITH UNIQUE KEY customer .
______________________________________________________________________________
method IF_EX_RSR_OLAP_BADI~DEFINE.
DATA: l_s_chanm TYPE rrke_s_chanm,
l_kyfnm TYPE rsd_kyfnm.
FIELD-SYMBOLS:
<l_s_chanm> TYPE rrke_s_chanm.
CASE i_s_rkb1d-infocube.
WHEN 'FIAR_M03' OR 'FIAR_C03'.
l_s_chanm-chanm = '0DEBITOR'.
l_s_chanm-mode = rrke_c_mode-read.
APPEND l_s_chanm to c_t_chanm.
l_s_chanm-chanm = 'ZCUR'.
l_s_chanm-mode = rrke_c_mode-chng_w_sel.
APPEND l_s_chanm to c_t_chanm.
APPEND 'CDM_LIMVK' TO c_t_kyfnm.
ENDCASE.
endmethod.
4
www.biportal.org
______________________________________________________________________________
method IF_EX_RSR_OLAP_BADI~INITIALIZE.
CASE i_s_rkb1d-COMPID. " different offset for each query
WHEN 'FIAR_QUERY1'.
IF t_cust IS INITIAL.
SELECT CUSTOMER /BIC/CDM_LIMI1 /BIC/ZCUR
FROM /BI0/PCUSTOMER INTO TABLE t_cust
WHERE OBJVERS = 'A' AND /BIC/CDM_LIMI1 NE 0.
ENDIF.
p_kyf_CDM_LIMVK = 36.
p_cha_0DEBITOR = 21.
P_CHA_AZCS1100 = 30.
WHEN ' FIAR_QUERY2'.
IF t_cust IS INITIAL.
SELECT CUSTOMER /BIC/CDM_LIMI1 /BIC/ZCUR
FROM /BI0/PCUSTOMER INTO TABLE t_cust
WHERE OBJVERS = 'A' AND /BIC/CDM_LIMI1 NE 0.
ENDIF.
p_kyf_CDM_LIMVK = 38.
p_cha_0DEBITOR = 22.
P_CHA_AZCS1100 = 32.
ENDCASE.
endmethod.
______________________________________________________________________________
method IF_EX_RSR_OLAP_BADI~COMPUTE.
FIELD-SYMBOLS <fs_CDM_LIMVK> TYPE ANY.
FIELD-SYMBOLS <fs_0DEBITOR> TYPE ANY.
FIELD-SYMBOLS <fs_ZCUR> TYPE ANY.
FIELD-SYMBOLS <cust> TYPE ty_cust.
5
www.biportal.org
In the COMPUTE method you should analyze C_S_DATA object for your query:
p_kyf_CDM_LIMVK = 38.
p_cha_0DEBITOR = 22.
P_CHA_AZCS1100 = 32.
6
www.biportal.org
One of the purposes of the VKF in this case is to be able to perform currency conversion on master
data attributes (Credit Limit). When running the report please specify the target currency in the
prompt:
After execution all Key Figures in the report have been converted to the target currency from the
prompt. During report execution Credit Limit VKF is been read from 0Customer master data
attributes:
It has been verified that VKFs work correctly with all BO4 tools (BO Analysis, Webi, OLAP Analysis,
etc.)
IF t_cust IS INITIAL.
SELECT CUSTOMER /BIC/CDM_LIMI1 /BIC/ZCUR
7
www.biportal.org
Please note, we use a HASHED internal table with a Unique key for attribute lookups. The lookup is
done for every line from the cube used in the report calculation, therefore it is critical to have this
code done the most optimal way. We have to READ data using WITH TABLE KEY for best
performance results:
We also have to make sure we read master data tables only in those queries where the VKF is used.
Therefore, we have to do query name checks in the INITIALIZE method:
If we do not check for query names the code will be executed for all queries based on the
infoproviders mentioned in the BAdi parameters. This will badly impact performance of all these
queries and may corrupt results.