Anda di halaman 1dari 19

Process for implementing Virtual Char / Keyfigures:

Business Scenarios:

1. Populate a release date value for a given combination of data selected from two
different data streams.
a. Data stream1 for the given selection has the release date characteristic
b. Data stream2 for the given selection or for any other selection doesn’t
have release date characteristic
2. Populate the value for a keyfigure based on the G/L Account value within the
query output

Phase A (Addresses Business Scenario 1 for virtual char implementation):

Cube A has the release date characteristic and is loaded via a flat file.

Cube B does not have the release date characteristic and would need maximum value of
the data coming through for a given combination of characteristics.

Step 1: Add the characteristic to Cube B and set the transformation or update rules
mapping to initial value with no update happening to the field. The characteristic is added
to the cube only to have it in the structure for reporting purposes (To drag it over in the
query).

Step 2: Create a DSO and load the data from the flat file which actually has the
data to get the combination of Characteristic A and Characteristic B as Key fields of DSO
and the date value to be maximum in the aggregation definition of the keyfigure (date).

By doing so, the DSO will contain the unique combination of Characteristic A
and Characteristic B with the maximum value of release date available for reference.

Step 3: Update MultiProvider with identification of the release date characteristic


from the related cuhes (Cube A and Cube B).

Phase B (Addresses Business Scenario 2 for virtual keyfigure implementation):

Step 1: Add the keyfigure to the Cube in consideration and similar to the step1
above no update needs to happen within the transformation or update rules.

Step 2: Identify the keyfigure in the concerned MultiProvider for reporting


purpose.

Step 3: Need to use this keyfigure in the queries to trigger the code in BadI.

The rest of the steps are going to be common for both the phases.
Step 4: Go to transaction code SE18 and select the option “BAdI Name” and enter
the BAdI name as “RSR_OLAP_BADI” and click on display button.

Step 5: In the next screen go to menu and click on “Implementation” and then
select the option “Create” if a previously implemented option/filter does not exist.

If it does exist, select “Change” option accordingly.

If you click on “Create”, a new screen opens up asking you to enter the name of the
implementation for the original BadI “RSR_OLAP_BADI”.

Name the BadI as “ZVAR_IMPL” (BADI for Virtual Char & KYFG’s implementation)
and in the next screen define the filter as “Z*” as shown in the screenshot below by
clicking on the insert row button in the screen:
Step 6: Now click on the tab “Interface” and you can define the name of the
implementing class as “ZCL_IM_VAR_IMPL” as shown in the screenshot below:

Double click on the implementation class and you can see the default methods available
in the screen for
DEFINE
INITIALIZE
COMPUTE

Each of this default methods have parameters which can be leveraged for filtering and
other data processing.

Before going into parameters / attributes available for methods, we will look into the
actual definition of the class ZCL_IM_VAR_IMPL,
In the above screenshot the attributes are added as per the requirement, in the first
scenario of virtual char implementation the attributes to be added would be:

P_CHA_0ME_MED_ISS
P_CHA_SP_TERRTY
P_CHA_SPRELDATE

In the second scenario of virtual keyfigure implementation the attributes added are:

P_CHA_0CHRT_ACCTS
P_CHA_0GL_ACCOUNT
P_KYF_0QUANTITY
P_KYF_SP_VR_QTY
Now, parameters for the method DEFINE are:
FLT_VAL  Value of the MultiProvider for which the BadI is to be executed. We can
use this as a case scenario and have different coding functionality within the Method
based on the MultiProvider name.

I_S_RKB1D  Has list of components other than MultiProvider for filtering if required.
The possible columns which can be used for filtering are:
I_TH_CHANM_USED is of the type RRKE_TH_CHANM which in turn maps to the
table RSDCHA for looking up the characteristic existence in the system.

I_TH_KYFNM_USED is of the type RRKE_TH_KYFNM which in turn maps to the


table RSDKYF for looking up the keyfigure existence in the system.

C_T_CHANM and C_T_KYFNM are the characteristic and keyfigure tables respectively
which would be updated by the list of characteristics and keyfigures required for the
derivation or calculation of the virtual fields for reporting.

Now parameters for the method INITIALIZE are:

FLT_VAL  Same as the one for Define mentioned above.

I_S_RKB1D  Same as the one for Define mentioned above.

I_TH_SFC  Would be the internal table which will have all the values from the
C_T_CHANM.

I_TH_SFK  Would be the internal table which will have the values from the
C_T_KYFNM table.

I_S_DATA  This would be the table in which the position of the fields to be updated
along with other data is being determined.

Now parameters for the method COMPUTE are:


FLT_VAL  Same as the one for Define mentioned above.

I_PARTCUBE  This would be the partial cube within the MultiProvider if the filtering
has to be cube specific within the MultiProvider.

I_S_RKB1D  This would be similar to the one mentioned in Define and Initialize
sections.

I_NCUM  Is an indicator for Non Cumulative calculation for query design.

C_S_DATA  Is the final data set for the query output.

Other than the basic methods available in the class, additional methods have been
implemented to attain the functionality w.r.to virtual chars/keyfigures.

The following are the custom methods implemented for the class:

1. CONSTRUCTOR - Constructor
2. GET_FIELD_POSITION_D
3. DEF_CHECK_CHA
4. DEF_CHECK_KYF
5. DEF_ADD_CHA
6. DEF_ADD_KYF

The source code for the standard methods and the custom method will be provided in the
later part of this document.

First, we will be looking into the parameters of the custom methods which have been
implemented:

Parameters of CONSTRUCTOR method:

None.

Parameters of GET_FIELD_POSITION_D method:

I_FIELDNM  It uses the P_CHA and the actual characteristic or P_KYF and the
keyfigure to populate the concatenated attribute for later use in the COMPUTE method
and also for position generation.
I_S_DATA  internal table to hold the characteristics and keyfigures defined in the
section.
R_POSITION  Position of the fields w.r.to the usage of the method

Parameters of DEF_CHECK_CHA:
CHATAB  Table to be referenced for looking up the characteristic
CHA_NAME  Name of the characteristic to be looked up
FLAG  Flag value set either to X or blank which is later used in Define method

Parameters of DEF_CHECK_KYF:

KYFTAB  Table to be referenced for looking up the keyfigure


KYF_NAME  Name of the keyfigure to be looked up
FLAG  Flag value set either to X or blank which is later used in Define method

Parameters of DEF_ADD_CHA:

CHA_NAME  Character name to be added to the list


READONLY  Is it read only or is it the one to be updated
CHATAB  Characteristic list of the InfoObjects to be referred

Parameters of DEF_ADD_KYF:

KYF_NAME  Keyfigure name to be added to the list


KYFTAB  Keyfigure list of the InfoObjects to be referred

Source code of each of the methods is:

A. Source code of IF_EX_RSR_OLAP_BADI~DEFINE is:

*----------------------------------------------------------------------*
* Method IF_EX_RSR_OLAP_BADI~DEFINE
* Author : Dharma Teja Atluri *
* Date : Aug 14, 2008 *
* Technical Contact : SAP BI Support *
* Functional Contact : NA *
* RICE ID : NA *
* *
* Purpose :
*----------------------------------------------------------------------*
* Modification Log *
* *
* Changed On Changed By CTS Description *
* ---------------------------------------------------------------------*
* 07/22/2008 DATLURI BDVK915309 Initial implementation *
* TPR 28165
* 07/08/2010 DATLURI BDVK919311 TPR 41836 - Royalty qty *
* calculation based on G/L Account mapping table ZBW_QRY_GL_MAP *
*----------------------------------------------------------------------*

method IF_EX_RSR_OLAP_BADI~DEFINE.

DATA: L_CHAR_EXISTS TYPE CHAR1,


L_KYF_EXISTS TYPE CHAR1.

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.

* This implementation is for IMSM related queries

WHEN 'ZM_IPSPRI'.

IF FLT_VAL = 'ZM_IPSPRI'.

CLEAR: L_CHAR_EXISTS.

L_CHAR_EXISTS = DEF_CHECK_CHA( CHATAB = I_TH_CHANM_USED CHA_NAME =


'SPRELDATE' ).

IF L_CHAR_EXISTS = 'X'.

DEF_ADD_CHA( exporting CHA_NAME = '0ME_MED_ISS' READONLY = 'X' changing


CHATAB = C_T_CHANM ).
DEF_ADD_CHA( exporting CHA_NAME = 'SP_TERRTY' READONLY = 'X' changing CHATAB
= C_T_CHANM ).
DEF_ADD_CHA( exporting CHA_NAME = 'SPRELDATE' READONLY = ' ' changing CHATAB
= C_T_CHANM ).

ELSE.

CLEAR: L_CHAR_EXISTS.

ENDIF.

ENDIF.

* This implementation is for SPL Detail related queries relevant for Royalty qty

WHEN 'ZMSLDTLS'.

IF FLT_VAL = 'ZMSLDTLS'.

CLEAR: L_KYF_EXISTS.

L_KYF_EXISTS = DEF_CHECK_KYF( KYFTAB = I_TH_KYFNM_USED KYF_NAME =


'SP_VR_QTY' ).

IF L_KYF_EXISTS = 'X'.

DEF_ADD_CHA( exporting CHA_NAME = '0CHRT_ACCTS' READONLY = 'X' changing


CHATAB = C_T_CHANM ).
DEF_ADD_CHA( exporting CHA_NAME = '0GL_ACCOUNT' READONLY = 'X' changing
CHATAB = C_T_CHANM ).
DEF_ADD_KYF( exporting KYF_NAME = '0QUANTITY' changing KYFTAB = C_T_KYFNM ).
DEF_ADD_KYF( exporting KYF_NAME = 'SP_VR_QTY' changing KYFTAB = C_T_KYFNM ).

ELSE.

CLEAR: L_KYF_EXISTS.

ENDIF.

ENDIF.
ENDCASE.

endmethod.

B. Source code of IF_EX_RSR_OLAP_BADI~INITIALIZE is:

*----------------------------------------------------------------------*
* Method IF_EX_RSR_OLAP_BADI~INITIALIZE
* Author : Dharma Teja Atluri *
* Date : Aug 14, 2008 *
* Technical Contact : SAP BI Support *
* Functional Contact : NA *
* RICE ID : NA *
* *
* Purpose :
*----------------------------------------------------------------------*
* Modification Log *
* *
* Changed On Changed By CTS Description *
* ---------------------------------------------------------------------*
* 07/22/2008 DATLURI BDVK915309 Initial implementation *
* TPR 28165
* 07/08/2010 DATLURI BDVK919311 TPR 41836 - Royalty qty *
* calculation based on G/L Account mapping table ZBW_QRY_GL_MAP *
*----------------------------------------------------------------------*
method IF_EX_RSR_OLAP_BADI~INITIALIZE.

DATA: l_global_name TYPE string.


FIELD-SYMBOLS:
<l_global> TYPE i,
<l_s_sfc> TYPE rrkg_s_sfc,
<l_s_sfk> TYPE rrkg_s_sfk.

* there's no need to change this method


* Just create attributes for each charactersitic
* with name P_CHA_<characteristic> TYPE i.
* and constants for each key figure with name
* P_KYF_<key figure> TYPE i.

IF FLT_VAL = 'ZM_IPSPRI'.

CLASS cl_exm_im_rsr_olap_badi DEFINITION LOAD.

* get field postions for characteristics in structure


LOOP AT i_th_sfc ASSIGNING <l_s_sfc>
WHERE user_exit NE rrke_c_mode-none.
* field name in structure is keyreturnnm
* name of the global variable
CONCATENATE 'P_CHA' <l_s_sfc>-chanm
INTO l_global_name
SEPARATED BY '_'.
* fill the global variable
UNASSIGN <l_global>.

ASSIGN (l_global_name) TO <l_global>.

CHECK <l_global> IS ASSIGNED.


<l_global> = get_field_position_d( i_fieldnm = <l_s_sfc>-keyreturnnm
i_s_data = i_s_data ).
ENDLOOP.

ENDIF.

* This is for ZMSLDTLS MultiProvider relevant for royalty requirements

IF FLT_VAL = 'ZMSLDTLS'.

CLASS cl_exm_im_rsr_olap_badi DEFINITION LOAD.

* get field positions for characteristics in structure


LOOP AT i_th_sfc ASSIGNING <l_s_sfc>
WHERE user_exit NE rrke_c_mode-none.
* field name in structure is keyreturnnm
* name of the global variable
CONCATENATE 'P_CHA' <l_s_sfc>-chanm
INTO l_global_name
SEPARATED BY '_'.
* fill the global variable
UNASSIGN <l_global>.

ASSIGN (l_global_name) TO <l_global>.

CHECK <l_global> IS ASSIGNED.

<l_global> = CL_EXM_IM_RSR_OLAP_BADI=>get_field_position_d( i_fieldnm = <l_s_sfc>-


keyreturnnm
i_s_data = i_s_data ).
ENDLOOP.

* get field positions for keyfigures in structure


LOOP AT i_th_sfk ASSIGNING <l_s_sfk>
WHERE value_returnnm IS NOT INITIAL.

* name of global variable


CONCATENATE 'P_KYF' <l_s_sfk>-kyfnm
INTO l_global_name
SEPARATED BY '_'.

* fill the global variable


UNASSIGN <l_global>.

ASSIGN (l_global_name) TO <l_global>.

CHECK <l_global> IS ASSIGNED.

<l_global> = CL_EXM_IM_RSR_OLAP_BADI=>get_field_position_d( i_fieldnm = <l_s_sfk>-


value_returnnm
i_s_data = i_s_data ).

ENDLOOP.

ENDIF.

endmethod.

C. Source code of IF_EX_RSR_OLAP_BADI~COMPUTE is:


*----------------------------------------------------------------------*
* Method IF_EX_RSR_OLAP_BADI~COMPUTE
* Author : Dharma Teja Atluri *
* Date : Aug 14, 2008 *
* Technical Contact : SAP BI Support *
* Functional Contact : NA *
* RICE ID : NA *
* *
* Purpose :
*----------------------------------------------------------------------*
* Modification Log *
* *
* Changed On Changed By CTS Description *
* ---------------------------------------------------------------------*
* 07/22/2008 DATLURI BDVK915309 Initial implementation *
* TPR 28165 *
* 07/08/2010 DATLURI BDVK919311 TPR 41836 - Royalty qty *
* calculation based on G/L Account mapping table ZBW_QRY_GL_MAP *
*----------------------------------------------------------------------*

method IF_EX_RSR_OLAP_BADI~COMPUTE.

FIELD-SYMBOLS: <l_ME_MED_ISS> TYPE ANY,


<l_SP_TERRTY> TYPE ANY,
<l_SPRELDATE> TYPE ANY.

FIELD-SYMBOLS: <l_chrt_accts> TYPE ANY,


<l_gl_account> TYPE ANY,
<l_quantityor> TYPE ANY,
<l_quantityvr> TYPE ANY.

DATA: l_med_iss TYPE /BI0/OIME_MED_ISS,


l_terrty TYPE /BIC/OISP_TERRTY,
l_spreldt TYPE /BIC/OISPRELDATE.

DATA: l_spreldat01 TYPE /BIC/OISPRELDATE.

DATA: l_qryid TYPE RSZCOMPID,


l_chrtacct TYPE /BI0/OICHRT_ACCTS,
l_glacct TYPE /BI0/OIGL_ACCOUNT,
l_qtyor TYPE /BI0/OIQUANTITY,
l_qtyvr TYPE /BIC/OISP_VR_QTY.

* Check to prevent destroying C_S_DATA....

IF FLT_VAL = 'ZM_IPSPRI'.

IF I_PARTCUBE = 'ZCSLSMR03' OR I_PARTCUBE = 'ZCSLSMR04'


OR I_PARTCUBE = 'ZCSLSMR05' OR I_PARTCUBE = 'ZCSLSMR06'
OR I_PARTCUBE = 'ZCSLSMR07' OR I_PARTCUBE = 'ZCSLSMR08'
OR I_PARTCUBE = 'ZCSLSMR09' OR I_PARTCUBE = 'ZTPS_C12'.

IF P_CHA_0ME_MED_ISS > 0 AND P_CHA_SP_TERRTY > 0.

ASSIGN COMPONENT P_CHA_0ME_MED_ISS OF STRUCTURE C_S_DATA


TO <l_ME_MED_ISS>.

ASSIGN COMPONENT P_CHA_SP_TERRTY OF STRUCTURE C_S_DATA


TO <l_SP_TERRTY>.
ASSIGN COMPONENT P_CHA_SPRELDATE OF STRUCTURE C_S_DATA
TO <l_SPRELDATE>.

SELECT SINGLE ME_MED_ISS


/BIC/SP_TERRTY
/BIC/SPRELDATE
FROM /BIC/AZDMETPLN00
INTO (l_med_iss, l_terrty, l_spreldt)
WHERE
ME_MED_ISS = <l_ME_MED_ISS>
AND /BIC/SP_TERRTY = <l_SP_TERRTY>.

IF SY-SUBRC EQ 0.

clear: l_spreldat01.

l_spreldat01 = l_spreldt.

<l_SPRELDATE> = l_spreldat01.

ENDIF.

UNASSIGN: <l_ME_MED_ISS>, <l_SP_TERRTY>,


<l_SPRELDATE>.

ENDIF.

ENDIF.

ENDIF.

* The code below is for ZMSLDTLS royalty G/L Account related quantity calculation

IF FLT_VAL = 'ZMSLDTLS'.

IF P_CHA_0CHRT_ACCTS > 0 AND P_CHA_0GL_ACCOUNT > 0.

ASSIGN COMPONENT P_CHA_0CHRT_ACCTS OF


STRUCTURE C_S_DATA
TO <l_chrt_accts>.

ASSIGN COMPONENT P_CHA_0GL_ACCOUNT OF


STRUCTURE C_S_DATA
TO <l_gl_account>.

ASSIGN COMPONENT P_KYF_0QUANTITY OF


STRUCTURE C_S_DATA
TO <l_quantityor>.

ASSIGN COMPONENT P_KYF_SP_VR_QTY OF


STRUCTURE C_S_DATA
TO <l_quantityvr>.

CLEAR: l_qryid, l_chrtacct, l_glacct, l_qtyor, l_qtyvr.

SELECT SINGLE QRY_TECH_NM


CHRT_ACCTS
GL_ACCT
FROM ZBW_QRY_GL_MAP
INTO (l_qryid, l_chrtacct, l_glacct)
WHERE
QRY_TECH_NM = I_S_RKB1D-COMPID
AND CHRT_ACCTS = <l_chrt_accts>
AND GL_ACCT = <l_gl_account>.

IF SY-SUBRC EQ 0.

clear: l_qtyvr.

l_qtyvr = 0.

<l_quantityvr> = l_qtyvr.

ELSE.

clear: l_qtyvr.

l_qtyvr = <l_quantityor>.

<l_quantityvr> = l_qtyvr.

ENDIF.

UNASSIGN: <l_chrt_accts>, <l_gl_account>,


<l_quantityor>, <l_quantityvr>.

ENDIF.

ENDIF.

endmethod.

D. Source code of CONSTRUCTOR is:

method CONSTRUCTOR.
endmethod.

E. Source code of GET_FIELD_POSITION_D is:

method GET_FIELD_POSITION_D.

DATA: l_t_fienm TYPE STANDARD TABLE OF sydes_nameinfo-name,


l_sx_td TYPE sydes_desc,
l_s_types TYPE sydes_typeinfo,
l_s_names TYPE sydes_nameinfo,
l_s TYPE string.

DESCRIBE FIELD i_s_data INTO l_sx_td.


LOOP AT l_sx_td-types INTO l_s_types
WHERE back EQ 1.
READ TABLE l_sx_td-names INTO l_s_names INDEX l_s_types-idx_name.
APPEND l_s_names-name TO l_t_fienm.
IF l_s_names-name EQ i_fieldnm.
r_position = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.

IF r_position IS INITIAL.
CONCATENATE 'I_S_DATA' i_fieldnm INTO l_s SEPARATED BY '-'.
RAISE EXCEPTION TYPE cx_rs_not_found
EXPORTING
object = 'FIELD'
key = l_s.
ENDIF.

endmethod.

F. Source code of DEF_CHECK_CHA is:

method DEF_CHECK_CHA.

field-symbols: <c> type RSCHANM.

read table chatab with key table_line = cha_name assigning <c>.


if sy-subrc = 0.
flag = 'X'.
else.
flag = ' '.
endif.

endmethod.

G. Source code of DEF_CHECK_KYF is:

method DEF_CHECK_KYF.

field-symbols: <k> like line of kyftab.

read table kyftab with key table_line = kyf_name assigning <k>.


if sy-subrc = 0.
flag = 'X'.
else.
flag = ' '.
endif.

endmethod.

H. Source code of DEF_ADD_CHA is:

method DEF_ADD_CHA.

data: l_s_chanm TYPE rrke_s_chanm.


FIELD-SYMBOLS: <l_s_chanm> TYPE rrke_s_chanm.

l_s_chanm-chanm = cha_name.
if readonly = 'X'.
l_s_chanm-mode = rrke_c_mode-read.
else.
l_s_chanm-mode = rrke_c_mode-no_selection.
endif.
READ TABLE chatab ASSIGNING <l_s_chanm>
WITH KEY chanm = l_s_chanm-chanm.
IF sy-subrc <> 0.
APPEND l_s_chanm TO chatab.
ELSEIF readonly <> 'X'.
<l_s_chanm>-mode = rrke_c_mode-no_selection.
ENDIF.
endmethod.

I. Source code of DEF_ADD_KYF is:

method DEF_ADD_KYF.

data: l_kyfnm TYPE rsd_kyfnm.

l_kyfnm = kyf_name.
READ TABLE kyftab
WITH KEY table_line = l_kyfnm
TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
APPEND l_kyfnm TO kyftab.
ENDIF.

endmethod.

Anda mungkin juga menyukai