SAP BI Generic Extraction Using a Function Module

download SAP BI Generic Extraction Using a Function Module

of 17

Transcript of SAP BI Generic Extraction Using a Function Module

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    1/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 1

    SAP BI Generic Extraction Using a Function Module

    Appl ies to :

    SAP BI

    Summary

    This article demonstrates a step-by-step process for doing generic extraction from R3 into BI usinga Function Module.

    Author(s): P Renjith Kumar.

    Company: Pricol Technologies

    Created on: 14 February 2007

    Author Bio

    P. Renjith Kumar is SAP BI Consultant with PRICOL Technologies. He has extensive cross-functional experience and has been with end-to-end SAP implementations as an ABAP Consultant.

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    2/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 2

    Table of Contents

    R3 Side...............................................................................................................................3 Code.............................................................................................................................8 Data Source Creation..............................................................................................10 Checking Extraction.................................................................................................11 BW Side.....................................................................................................................12

    Disclaimer and Liability Notice......................................................................................17

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    3/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 3

    R3 Side

    1. Create a structure with the necessary fields. The Currency and quantity fields musthave reference fields also.

    NETWRis a currency field so it must have reference field that is in the base table. Click Currency/ Quan and give that field name.

    2. In transaction SE80, Select Function group, name RSAX. Right click and Copy:

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    4/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 4

    Select only the needed function module:

    2

    Give new

    name offunction Group

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    5/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 5

    The Function Module in SE37 will be like this, we have to do light modification

    Give the newfunctionmodule name

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    6/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 6

    No change in Import Tab.

    Export, Changing No values.

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    7/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 7

    In TABLES tab, give the structure name.

    In Exceptions No data. In Source code Tab. Write this Code

    The Code that we need to write is Placed Inside

    Give your structure name

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    8/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 8

    Code

    FUNCTION ZRSAX_BIW_GET_DATA_SIMPLE4_2.*"----------------------------------------------------------------------*"*"Local interface:* IMPORTING*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR*" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL

    *" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL*" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL*" VALUE(I_REMOTE_CALL) TYPE SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF*" TABLES*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL*" E_T_DATA STRUCTURE ZNVBAK1 OPTIONAL*" EXCEPTIONS*" NO_MORE_DATA*" ERROR_PASSED_TO_MESS_HANDLER*"----------------------------------------------------------------------* Example: DataSource for table SFLIGHTTABLES: ZNVBAK1.

    * Auxiliary Selection criteria structureDATA: L_S_SELECT TYPE SRSC_S_SELECT.

    * Maximum number of lines for DB tableSTATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,

    * counterS_COUNTER_DATAPAKID LIKE SY-TABIX,

    * cursorS_CURSOR TYPE CURSOR.

    * Select ranges* RANGES: L_R_CARRID FOR SFLIGHT-CARRID,

    L_R_CONNID FOR SFLIGHT-CONNID.

    RANGES: SDNO FOR znvbak1-VBELN.

    * Initialization mode (first call by SAPI) or data transfer mode* (following calls) ?IF I_INITFLAG = SBIWA_C_FLAG_ON.

    ************************************************************************* Initialization: check input parameters* buffer input parameters* prepare data selection************************************************************************

    * Check DataSource validityCASE I_DSOURCE.

    WHEN 'ZFMEDS4'.

    WHEN OTHERS.IF 1 = 2. MESSAGE E009(R3). ENDIF.

    * this is a typical log call. Please write every error message like thisLOG_WRITE 'E' "message type

    'R3' "message class'009' "message numberI_DSOURCE "message variable 1' '. "message variable 2

    Name of Data sourcegiven in RS02

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    9/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 9

    RAISE ERROR_PASSED_TO_MESS_HANDLER.ENDCASE.

    APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.

    * Fill parameter buffer for data extraction callsS_S_IF-REQUNR = I_REQUNR.S_S_IF-DSOURCE = I_DSOURCE.S_S_IF-MAXSIZE = I_MAXSIZE.

    * Fill field list table for an optimized select statement* (in case that there is no 1:1 relation between InfoSource fields* and database table fields this may be far from beeing trivial)

    APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.

    ELSE. "Initialization mode or data extraction ?

    ************************************************************************* Data transfer: First Call OPEN CURSOR + FETCH* Following Calls FETCH only************************************************************************* First data package -> OPEN CURSOR

    IF S_COUNTER_DATAPAKID = 0.

    * Fill range tables BW will only pass down simple selection criteria* of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.* LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CARRID'.* MOVE-CORRESPONDING L_S_SELECT TO L_R_CARRID.* APPEND L_R_CARRID.* ENDLOOP.** LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CONNID'.* MOVE-CORRESPONDING L_S_SELECT TO L_R_CONNID.* APPEND L_R_CONNID.* ENDLOOP.

    LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'VBELN'.

    MOVE-CORRESPONDING L_S_SELECT TO SDNO.

    APPEND SDNO.

    ENDLOOP.

    * Determine number of database records to be read per FETCH statement* from input parameter I_MAXSIZE. If there is a one to one relation* between DataSource table lines and database entries, this is trivial.* In other cases, it may be impossible and some estimated value has to* be determined.

    OPEN CURSOR WITH HOLD S_CURSOR FOR* SELECT (S_S_IF-T_FIELDS) FROM SFLIGHT* WHERE CARRID IN L_R_CARRID AND* CONNID IN L_R_CONNID.

    SELECT VBAK~VBELN VBAK~ERDAT VBAK~NETWR VBAP~MATNRVBAP~POSNRFROM VBAKINNER JOIN VBAP on VBAK~VBELN = VBAP~VBELNWHERE VBAK~VBELN IN SDNO.

    ENDIF. "First data package ?

    * Fetch records into interface table.* named E_T_'Name of extract structure'.

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    10/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 10

    FETCH NEXT CURSOR S_CURSORAPPENDING CORRESPONDING FIELDSOF TABLE E_T_DATAPACKAGE SIZE S_S_IF-MAXSIZE.

    IF SY-SUBRC 0.CLOSE CURSOR S_CURSOR.RAISE NO_MORE_DATA.

    ENDIF.

    S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.

    ENDIF. "Initialization mode or data extraction ?

    ENDFUNCTION.

    Now Save, Activatethe function module.

    Goto SE80 -> Select Function Group, Activate the Function Group.

    Note:

    If you do not activate function Group, You will not be able to create data source in RS02

    Data Source Creation

    Then you have to create the data source, the data source name must be the name given in the sourcecode of the Function module.

    RSO2 -> Create

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    11/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 11

    Select Extr By Fun Module, Give name of Appl comp, Function Module, Extract Structure, save

    Checking Extraction

    Now give the selection Conditions and save.

    RSA3 ->Give data source name and check extraction

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    12/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 12

    BW Side.

    1. RSA1 ->Source system , Src sys -> Rt Click, Data source Over view, Appl Comp, Rt click,Replicate.

    2. RSA1 - > Info source - > Create Appl comp -> Rt clk , Assign Data source - > Src Sys

    Some Blank Value will come in Info object; just press F4 and select, same field option

    Give max value to getthe correct valueextracted

    2

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    13/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 13

    Then Press

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    14/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 14

    If you double click that info source, every char. Key fig from that info source will comeautomatically into cube, just assign Dimension to Cube and save and activate.

    Create Update Rule for the Cube based on the info source

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    15/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 15

    Now Schedule the Extraction

    The final data will be like this in Monitor

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    16/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 16

  • 7/27/2019 SAP BI Generic Extraction Using a Function Module

    17/17

    SAP BI Generic Extraction Using a Function Module

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    Disclaimer and Liability Notice

    This document may discuss sample coding or other information that does not include SAP officialinterfaces and therefore is not supported by SAP. Changes made based on this information are notsupported and can be overwritten during an upgrade.

    SAP will not be held liable for any damages caused by using or misusing the information, code or

    methods suggested in this document, and anyone using these methods does so at his/her ownrisk.

    SAP offers no guarantees and assumes no responsibility or liability of any type with respect to thecontent of this technical article or code sample, including any liability resulting from incompatibilitybetween the content within this document and the materials and services offered by SAP. Youagree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content ofthis document.