Creating Virtual Cube Based On Function Module in SAP BI
Creating Virtual Cube Based On Function Module in SAP BI
Applies to:
SAP BIW 3.5, SAP NetWeaver 7.0. For more information, visit the EDW homepage.
Summary
Present white paper is a guide for creating virtual cube based on function module. Actually it contains the
sample code of function module that can help a lot in writing your own code for virtual cube.
Author Bio
Dheeraj Gupta is currently working in L&T Infotech. He has worked extensively in SAP BW 3.5 and
SAP BI 7.0. Currently he is responsible for various BI developments.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 1
Creating Virtual Cube based on Function Module in SAP BI
Table of Contents
Creating Virtual Cube ......................................................................................................................................... 3
Writing Function Module ZIFRS_VC2_FM...................................................................................................... 4
Related Content ................................................................................................................................................ 14
Disclaimer and Liability Notice .......................................................................................................................... 15
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 2
Creating Virtual Cube based on Function Module in SAP BI
For our example we will take ZIFRS_VC2 virtual cube which structure is as follows.
st nd
When you click Details button in 1 screen then 2 screen comes where you provide name of Function
Module and other details. As the main objective of this document is to tell how to write FM for VC so we will
not go in any other detail and will directly move to FM.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 3
Creating Virtual Cube based on Function Module in SAP BI
This is main program for function module. When you create some function module in a group let us say
ZF_IPAD then this function module will be created as an include in program (shown above in rectangle) – In
include LZF_IPADUXX. You can include other includes in this main program that can have global functions.
Like below we have included LZF_IPADF01 that contains various functions explained later in this
document.
SAPLZF_IPAD
INCLUDE LZF_IPADTOP. " Global Data
INCLUDE LZF_IPADUXX. " Function Modules
*******************************************************************
* User-defined Include-files (if necessary). *
*******************************************************************
* INCLUDE LZF_IPADF... " Subprograms
* INCLUDE LZF_IPADO... " PBO-Modules
* INCLUDE LZF_IPADI... " PAI-Modules
INCLUDE LZF_IPADF01.
INCLUDE LZF_IPADTOP.
Include LZF_IPADTOP contains global data declaration, type pools definitions, various field-symbols,
structure definitions etc. Below all declarations will always be included for (name can change but will have to
change everywhere accordingly). The structure ls_cd_cube_struc is the structure (fields) of virtual cube
(shown earlier). Here standard infoobject should be named with removing ‘0’ (like 0BUS_AREA as
BUS_AREA) and customized object should be given name as /BIC/ZF_NCURR for ZF_NCURR info object
(prefixed with /BIC/).
FUNCTION-POOL ZF_IPAD. "MESSAGE-ID ..
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 4
Creating Virtual Cube based on Function Module in SAP BI
Types :
*structure for CD report.
Begin of ls_cd_cube_struc,
BUS_AREA(4),
CHRT_ACCTS(4),
COMP_CODE(4),
COSTCENTER(10),
CO_AREA(4),
CURTYPE(2),
DUEDATE type d,
FISCPER3_E type n length 3,
GL_ACCOUNT(10),
BAL_FLAG(1),C4(4),
PROFIT_CTR(10),
SEGMENT(10),
/BIC/ZF_NCURR(1),
/BIC/ZNATUR_JV(4),
/BIC/ZTRANS_DT type d,
FISCPER(7) type N,
FISCVARNT(2),
FISCYEAR(4) type N,
CURRENCY(5),
CREDIT type p length 9 decimals 2,
DEBIT type p length 9 decimals 2,
End of ls_cd_cube_struc,
LZF_IPADF01
Following 2 function module will always be there for Virtual Cube function module. So these can be copied
as it is in new include LZF_IPADF01.
*&---------------------------------------------------------------------*
*& Form move_itab_to_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_AP_TAB text
* -->P_I_TH_SFC text
* -->P_I_TH_SFK text
* -->P_L_T_COMPONENT text
* <--P_<L_S_DATA> text
*----------------------------------------------------------------------*
FORM move_itab_to_data USING P_LS_AP_TAB type any
P_I_TH_SFC TYPE RSDRI_TH_SFC
P_I_TH_SFK TYPE RSDRI_TH_SFK
P_L_T_COMPONENT TYPE abap_compdescr_tab
CHANGING P_L_S_DATA type any.
* define FIELD-SYMBOLS
FIELD-SYMBOLS: <l_s_component> TYPE abap_compdescr,
<l_comp_data> , <fieldvalue> TYPE ANY,
<l_s_sfc> TYPE RSDRI_S_SFC,
<l_s_sfk> TYPE RSDRI_S_SFK.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 5
Creating Virtual Cube based on Function Module in SAP BI
* Datadeclaration
DATA: l_compno TYPE i,
l_t_component TYPE abap_compdescr_tab.
clear p_l_s_data.
endloop.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 6
Creating Virtual Cube based on Function Module in SAP BI
clear ls_data_elem.
CALL FUNCTION 'RSD_FIELDNM_GET_FROM_IOBJNM'
EXPORTING
I_NAME = <l_s_sfk>-KYFNM
IMPORTING
E_DDNAME = ls_data_elem.
IF SY-SUBRC = 0.
ZIFRS_VC2_FM
This is main function module. It’s importing and exporting parameters will remain like this only. When any
query is executed based on VC or we directly see the data of VC then this gets executed and all importing
parameter are automatically passed. Now whatever we fill in E_T_DATA, that will pass to VC output data
that can be used in query or anywhere. Explanation of code is given below with code.
FUNCTION ZIFRS_VC1_FM.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_INFOPROV) TYPE RSINFOPROV
*" REFERENCE(I_TH_SFC) TYPE RSDRI_TH_SFC
*" REFERENCE(I_TH_SFK) TYPE RSDRI_TH_SFK
*" REFERENCE(I_T_RANGE) TYPE RSDRI_T_RANGE
*" REFERENCE(I_TX_RANGETAB) TYPE RSDRI_TX_RANGETAB
*" REFERENCE(I_FIRST_CALL) TYPE RS_BOOL
*" REFERENCE(I_PACKAGESIZE) TYPE I
*" EXPORTING
*" REFERENCE(E_T_DATA) TYPE STANDARD TABLE
*" REFERENCE(E_END_OF_DATA) TYPE RS_BOOL
*" REFERENCE(E_T_MSG) TYPE RS_T_MSG
*"----------------------------------------------------------------------
"-----------------------------------------------------------------------
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 7
Creating Virtual Cube based on Function Module in SAP BI
In above code I-INFOPROV attribute is passed at run time with the name of VC.
I_TH_SFC contains entries like
0BUS_AREA K____1031 0
0CHRT_ACCTS K____198 0
0COMP_CODE K____197 0
0COSTCENTER K____894 0
First column is Characteristic name and 2nd column is BW-DM field alias name and similarly ITH_SFK
contains entries for key figures.
I_T_RANGE table contains if you give some restriction in query or while data displaying.
DATA : C_FIRST_CALL TYPE RS_BOOL.
DATA : ITAB_FINAL_CD TYPE TABLE OF LS_CD_CUBE_STRUC.
DATA : WA_FINAL_CD TYPE LS_CD_CUBE_STRUC.
Above statements are data declarations required in FM. Assign statement creates a structure of E_T_DATA
type and assigns it to <L_S_DATA_CD>.
* Now let us build a dynamic structure so that we can read the infoset
* Build field catelog.
CLEAR: IT_FIELDCAT , IT_FCAT.
REFRESH: IT_FIELDCAT , IT_FCAT.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = '/BIC/VZISFS_M022'
CHANGING
CT_FIELDCAT = IT_FCAT[].
Above statement is written because we want to read data from a multiprovider ZISFS_M02. We will use that
data to fill E_T_DATA table. So for reading data from multiprovider/ cube we have to use
'RSDRI_INFOPROV_READ' FM. This FM requires 1 parameter in import and to provide that parameter we
are going through above FM. We will find 1 structure with name /BIC/VCUBENAME2 or /BI0/VCUBENAME2
that we have to use here and output of this FM IT_FCAT will have following data. That is Column position,
field name, data types, reference table etc.
4 0COSTCENTER X Cost CHAR C 000010 /BIC/VZISFS_M022 Cost 000010
Center Center
5 0BUS_AREA X Business CHAR C 000004 /BIC/VZISFS_M022 Business 000004
area area
6 0CO_AREA X Controlling CHAR C 000004 /BIC/VZISFS_M022 Controlling 000004
Area Area
7 0PROFIT_CTR X Profit CHAR C 000010 /BIC/VZISFS_M022 Profit 000010
Center Center
So above statement will always come if you want to read data from Infoset/ Multiprovider.
LOOP AT IT_FCAT INTO IS_FCAT.
MOVE-CORRESPONDING IS_FCAT TO IS_FIELDCAT.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 8
Creating Virtual Cube based on Function Module in SAP BI
EXPORTING
I_IOBJNM = IS_FCAT-FIELDNAME
IMPORTING
E_KEYRETURNNM = L_SELALIAS.
* exceptions
* x_message = 1
* others = 2.
IF SY-SUBRC <> 0.
E_END_OF_DATA = 'X'.
EXIT.
ENDIF.
IS_FIELDCAT-FIELDNAME = L_SELALIAS.
IS_FIELDCAT-REF_FIELD = IS_FCAT-FIELDNAME.
IS_FIELDCAT-REF_TABLE = IS_FCAT-REF_TABNAME.
APPEND IS_FIELDCAT TO IT_FIELDCAT.
ENDLOOP.
Above code creates another inter mediate table that is for the filling requirement of
'RSDRI_INFOPROV_READ' FM’s import parameter. Mainly this gets BW-DM field alias name for fields of
Multi provider b/c that is required for to communicate from RSDRI_INFOPROV_READ FM.
* Create a new Table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT
IMPORTING
EP_TABLE = E_T_TABLE.
* Create a new Line with the same structure of the table.
ASSIGN E_T_TABLE->* TO <L_TABLE>.
CREATE DATA E_T_LINE LIKE LINE OF <L_TABLE>.
ASSIGN E_T_LINE->* TO <L_LINE>.
Above code creates dynamic table that is it creates E_T_TABLE that will have all columns mentioned in
IT_FIELDCAT. Columns name will be BW-DM field alias name. After that assign statement assigns
E_T_TABLE (pointer to table) to a field symbol. And similarly creates work area of E_T_TABLE and assign
that to <L_LINE>.
CALL FUNCTION 'RSDRI_INFOPROV_READ'
EXPORTING
I_INFOPROV = 'ZISFS_M02'
I_TH_SFC = I_TH_SFC
I_TH_SFK = I_TH_SFK
I_T_RANGE = I_T_RANGE
I_PACKAGESIZE = I_PACKAGESIZE
IMPORTING
E_T_DATA = <L_TABLE>
CHANGING
C_FIRST_CALL = C_FIRST_CALL
EXCEPTIONS
RUNTIME_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 9
Creating Virtual Cube based on Function Module in SAP BI
Finally above statement reads data of multi provider. For reading data from Infoset use 'RSQ_READ_DATA'
FM that is quite similar to above. For reading data from DSO/ Infoobject, you can use simple select
statement on Active table/ ‘M’ table of Infoobject respectively.
**** Read the data from the ODSes.
In above statements starting from LOOP AT <L_TABLE>, <L_TABLE> contains data read from
MultiProvider. The column names in this table are BW-DM field alias names (like K___066 etc.) and work
area for VC has column names as BUS_AREA etc. So we have to reach from K___* names to field name in
VC. So IT_FCAT contains info objects description as ‘Business area’ etc. and IT_FIELDCAT contains K___*
names and joining b/w these 2 tables is IT_FIELDCAT-REF_FIELD = IT_FCAT-FIELDNAME. So reaching to
REPTEXT_DDIC = ‘Business area’ and assigning corresponding K___* component of structure <L_LINE>,
we can use corresponding info object BA through <L_FIELD>.
WHEN ''.
ASSIGN COMPONENT IS_FIELDCAT-FIELDNAME OF
STRUCTURE <L_LINE> TO <L_FIELD>.
WA_FINAL_CD-CURRENCY = <L_FIELD>.
UNASSIGN <L_FIELD>.
*****************************************
WHEN 'Cost Center'.
ASSIGN COMPONENT IS_FIELDCAT-FIELDNAME OF
STRUCTURE <L_LINE> TO <L_FIELD>.
WA_FINAL_CD-COSTCENTER = <L_FIELD>.
UNASSIGN <L_FIELD>.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 10
Creating Virtual Cube based on Function Module in SAP BI
WA_FINAL_CD-CO_AREA = <L_FIELD>.
UNASSIGN <L_FIELD>.
WHEN 'Segment'.
ASSIGN COMPONENT IS_FIELDCAT-FIELDNAME OF
STRUCTURE <L_LINE> TO <L_FIELD>.
WA_FINAL_CD-SEGMENT = <L_FIELD>.
UNASSIGN <L_FIELD>.
WHEN 'Nature'.
ASSIGN COMPONENT IS_FIELDCAT-FIELDNAME OF
STRUCTURE <L_LINE> TO <L_FIELD>.
WA_FINAL_CD-/BIC/ZNATUR_JV = <L_FIELD>.
UNASSIGN <L_FIELD>.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 11
Creating Virtual Cube based on Function Module in SAP BI
ENDCASE.
APPEND WA_FINAL_CD TO ITAB_FINAL_CD.
ENDLOOP.
ENDLOOP.
*
* wa_final_cd-calday = p_date_cd.
Till here we have our data for VC in ITAB_FINAL _CD table. Now we have to push same in E_T_DATA.
* get description of components of <L_S_DATA_cd>
PERFORM GET_TYPE_COMPONENTS(SAPLRSDRC_SERVICES)
USING <L_S_DATA_CD>
CHANGING L_T_COMPONENT_CD.
Perform statement gives Length and types for E_T_DATA table (<L_S_DATA_CD>
The output in L_T_COMPONENT_CD will be and this will be used in following code.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 12
Creating Virtual Cube based on Function Module in SAP BI
PERFORM MOVE_ITAB_TO_DATA
USING CD_CUBE_STRUC
I_TH_SFC
I_TH_SFK
L_T_COMPONENT_CD
CHANGING <L_S_DATA_CD>.
ENDLOOP.
E_END_OF_DATA = 'X'.
ENDFUNCTION.
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 13
Creating Virtual Cube based on Function Module in SAP BI
Related Content
Virtual InfoCubes with Services
How to implement a virtual infoprovider with services
Virtual InfoCubes
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
© 2011 SAP AG 14
Creating Virtual Cube based on Function Module in SAP BI
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2011 SAP AG 15