Enhancing standard data source in BI
To analyze data in BI(Business intelligence)
we are using 'Data source'. Data source is nothing but like Reports in normal
ABAP. So data source is a collection of fields along with data.
Requirement: Now Business wants
some additional logic like calculations or wants to see the field from some
other data sources. In such cases we will do data source enhancement.
Here we are going to enhance
Purchase order item data source.
Steps to Enhance a data source:
1. identify or get the standard data source name from the
RSA6
2. Select data source and click on display button and get the
structure name which is available in field 'Extract structure'.
3. add new fields in structure by using Append structure. In
case of this new fields are currency/quantity then we should have reference
fields also in the same structure.
4. Now to add logic for new fields we should create
implementation for the Badi 'RSU5_SAPI_BADI'
Step by Step in detail:
1. identify or get the standard data source name from the
RSA6
Go to required module and find data source based on name and
description. in our case for Purchase order item data it is '2LIS_02_ITM'.
2. Select data source and click on display button and get the structure name which is available in
field 'Extract structure'.
3. Add new fields in structure by using Append structure in SE11. In case of this new fields are currency/quantity then we should have reference fields also in the same structure.
Here we have appended new structure 'ZBW_PO_ITEM' with required fields. You can observe that currency fields should have reference field also from same structure.
4. Now to add logic for new fields we should create implementation for the Badi 'RSU5_SAPI_BADI.
go to SE19 and create implementation for BADI
There are two methods in interface tab. we need to write our logic in 'DATA_TRANSFORM' method only.
so double click on Data transform method and go to edit screen.This method having multiple parameters as below screen. However, the below parameters are important for us.
I_DATASOURCE --> Having data source name, based on name required logic will trigger C_T_DATA --> Data source complete records, modify this table using our logic
How I implemented in my assignment:
In our scenario, it is MM Module. below image refers the same.
now there are multiple data sources in MM module. So when we want to enhance to any data source we are including new method in ZCL_IM_BW_RSU5_SAPI_MM and calling that method from DATA_TRANSFORM method.
METHOD m_2lis_02_itm.
FIELD-SYMBOLS: <lfs_data> TYPE mc02m_0itm.
TYPES: BEGIN OF ty_po,
zebeln TYPE ebeln,
zbukrs TYPE bukrs,
zstatu TYPE estak,
aedat TYPE erdat,
ernam TYPE ernam,
waers TYPE waers,
inco1 TYPE inco1,
inco2 TYPE inco2,
knumv TYPE knumv,
exnum TYPE exnum,
frgzu TYPE frgzu,
END OF ty_po.
TYPES: BEGIN OF ty_poreq,
zbanfn TYPE banfn,
zbnfpo TYPE bnfpo,
zfrgdt TYPE frgdt,
END OF ty_poreq.
DATA : lt_po TYPE STANDARD TABLE OF ty_po,
lwa_po TYPE ty_po,
lt_data TYPE STANDARD TABLE OF mc02m_0itm,
lwa_data TYPE mc02m_0itm,
lt_poreq TYPE STANDARD TABLE OF ty_poreq,
lwa_poreq TYPE ty_poreq.
* Copy the contents of the data table into a temporary table
lt_data[] = c_t_data[].
IF NOT lt_data IS INITIAL.
SELECT ebeln bukrs statu aedat ernam waers inco1 inco2 knumv exnum frgzu FROM ekko INTO TABLE lt_po
FOR ALL ENTRIES IN lt_data
WHERE ebeln = lt_data-ebeln
AND bukrs = lt_data-bukrs.
FIELD-SYMBOLS: <lfs_data> TYPE mc02m_0itm.
TYPES: BEGIN OF ty_po,
zebeln TYPE ebeln,
zbukrs TYPE bukrs,
zstatu TYPE estak,
aedat TYPE erdat,
ernam TYPE ernam,
waers TYPE waers,
inco1 TYPE inco1,
inco2 TYPE inco2,
knumv TYPE knumv,
exnum TYPE exnum,
frgzu TYPE frgzu,
END OF ty_po.
TYPES: BEGIN OF ty_poreq,
zbanfn TYPE banfn,
zbnfpo TYPE bnfpo,
zfrgdt TYPE frgdt,
END OF ty_poreq.
DATA : lt_po TYPE STANDARD TABLE OF ty_po,
lwa_po TYPE ty_po,
lt_data TYPE STANDARD TABLE OF mc02m_0itm,
lwa_data TYPE mc02m_0itm,
lt_poreq TYPE STANDARD TABLE OF ty_poreq,
lwa_poreq TYPE ty_poreq.
* Copy the contents of the data table into a temporary table
lt_data[] = c_t_data[].
IF NOT lt_data IS INITIAL.
SELECT ebeln bukrs statu aedat ernam waers inco1 inco2 knumv exnum frgzu FROM ekko INTO TABLE lt_po
FOR ALL ENTRIES IN lt_data
WHERE ebeln = lt_data-ebeln
AND bukrs = lt_data-bukrs.
IF sy-subrc IS INITIAL.
SORT lt_po BY zebeln.
ENDIF.
* Append a record for each purchase document
LOOP AT lt_data ASSIGNING <lfs_data>.
LOOP AT lt_po INTO lwa_po WHERE zebeln = <lfs_data>-ebeln AND
zbukrs = <lfs_data>-bukrs.
IF sy-subrc = 0.
<lfs_data>-zzstatu = lwa_po-zstatu.
IF lwa_po-zstatu = 'B'.
<lfs_data>-zzaupoc = 1.
ENDIF.
<lfs_data>-aedat_po = lwa_po-aedat.
<lfs_data>-ernam_po = lwa_po-ernam.
<lfs_data>-frgzu = lwa_po-frgzu.
<lfs_data>-exnum = lwa_po-exnum.
<lfs_data>-knumv = lwa_po-knumv.
<lfs_data>-ekko_inco1 = lwa_po-inco1.
<lfs_data>-ekko_inco2 = lwa_po-inco2.
MOVE <lfs_data>-ebelp TO <lfs_data>-kposn.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
* Transfer back the contents to original table.
FREE:c_t_data[].
c_t_data[] = lt_data[].
SORT lt_po BY zebeln.
ENDIF.
* Append a record for each purchase document
LOOP AT lt_data ASSIGNING <lfs_data>.
LOOP AT lt_po INTO lwa_po WHERE zebeln = <lfs_data>-ebeln AND
zbukrs = <lfs_data>-bukrs.
IF sy-subrc = 0.
<lfs_data>-zzstatu = lwa_po-zstatu.
IF lwa_po-zstatu = 'B'.
<lfs_data>-zzaupoc = 1.
ENDIF.
<lfs_data>-aedat_po = lwa_po-aedat.
<lfs_data>-ernam_po = lwa_po-ernam.
<lfs_data>-frgzu = lwa_po-frgzu.
<lfs_data>-exnum = lwa_po-exnum.
<lfs_data>-knumv = lwa_po-knumv.
<lfs_data>-ekko_inco1 = lwa_po-inco1.
<lfs_data>-ekko_inco2 = lwa_po-inco2.
MOVE <lfs_data>-ebelp TO <lfs_data>-kposn.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
* Transfer back the contents to original table.
FREE:c_t_data[].
c_t_data[] = lt_data[].
METHOD IF_EX_RSU5_SAPI_BADI~DATA_TRANSFORM.
**********************************************************
* To implement an exit for a
* datasource create your own method by copying the
* method _TEMPLATE_DATASOURCE and rename it to the name
* of your datasource. In case you enhance a Business
* Content datasource skip the 0 at the beginning (e.g.
* Datasource 0FI_AR_3 -> Method FI_AR_3
* The method is then called by the Exit Framework
*********************************************************
DATA: ls_oltpsource TYPE rsaot_s_osource,
lv_data TYPE REF TO data,
lv_method TYPE seocmpname.
FIELD-SYMBOLS: <lt_data> TYPE STANDARD TABLE.
* check BW system
*CHECK _check_bw_system( ) = 'X'.
* check if any data is extracted
CHECK c_t_data IS NOT INITIAL.
CALL FUNCTION 'RSA1_SINGLE_OLTPSOURCE_GET'
EXPORTING
i_oltpsource = i_datasource
i_objvers = 'A'
IMPORTING
e_s_oltpsource = ls_oltpsource
EXCEPTIONS
no_authority = 1
not_exist = 2
inconsistent = 3
OTHERS = 4.
IF sy-subrc <> 0.
EXIT.
ENDIF.
* create data for Extract Structure
CREATE DATA lv_data TYPE TABLE OF (ls_oltpsource-exstruct).
ASSIGN lv_data->* TO <lt_data>.
ASSIGN c_t_data TO <lt_data>.
DATA : l_method TYPE seocmpname.
CONCATENATE 'M_' i_datasource INTO l_method.
CHECK c_t_data[] IS NOT INITIAL.
SELECT SINGLE cmpname FROM seocompo INTO l_method WHERE
clsname = 'ZCL_IM_BW_RSU5_SAPI_MM' AND
cmpname = l_method.
CHECK sy-subrc EQ 0.
CALL METHOD (l_method)
EXPORTING
i_updmode = i_updmode
i_t_select = i_t_select
i_t_fields = i_t_fields
CHANGING
c_t_data = c_t_data
c_t_messages = c_t_messages.
ENDMETHOD. "if_ex_rsu5_sapi_badi~data_transfo
No comments:
Post a Comment