Upload Data from R/3 System using a Function Module in Generic Extraction to a DataStore Object in BI

...Previous

Now go to the source code of the FM & do the below change & then Save & Activate the FM Group and the FM.
FUNCTION ZZRSAX_BIW_GET_DATA_SIMPLE.
*"----------------------------------------------------------------------
*"*"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  ZZVTTPLIKP OPTIONAL
*"  EXCEPTIONS
*"      NO_MORE_DATA
*"      ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------
* Example: DataSource for table SFLIGHT
* Change the structure from sflight to ZZVTTPLIKP********
  TABLES: ZZVTTPLIKP. 
* Auxiliary Selection criteria structure
  DATA: L_S_SELECT TYPE SRSC_S_SELECT.
* Maximum number of lines for DB table
  STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,
* counter
          S_COUNTER_DATAPAKID LIKE SY-TABIX,
* cursor
          S_CURSOR TYPE CURSOR.
* Create a range for Delivery Number
 RANGES: L_R_VBELN FOR LIKP-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 validity
    CASE I_DSOURCE.
* Give the datasource a name which we will create in RSO2
      WHEN 'ZZ_SHIPMENT_DATA '.  
      WHEN OTHERS.
        IF 1 = 2. MESSAGE E009(R3). ENDIF.
* this is a typical log call. Please write every error message like this
        LOG_WRITE 'E'                  "message type
                  'R3'                 "message class
                  '009'                "message number
                  I_DSOURCE   "message variable 1
                  ' '.                 "message variable 2
        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 calls
    S_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 with VBELN & change the name of range table
   LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'VBELN'.
     MOVE-CORRESPONDING L_S_SELECT TO L_R_VBELN.
     APPEND L_R_VBELN.
   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
* Write your Select Query to fetch the data:
       Select LIKP~VBELN
              LIKP~ERNAM
              LIKP~ERDAT
              LIKP~VKORG
              LIKP~LFDAT
              LIKP~KUNNR
              LIKP~KUNAG
              VTTP~TKNUM
              VTTP~TPNUM
         from LIKP INNER JOIN VTTP
           on LIKP~VBELN = VTTP~VBELN
        where LIKP~VBELN IN L_R_VBELN.
    ENDIF.                             "First data package ?
* Fetch records into interface table.
*   named E_T_'Name of extract structure'.
    FETCH NEXT CURSOR S_CURSOR
               APPENDING CORRESPONDING FIELDS
               OF TABLE E_T_DATA
               PACKAGE 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.

STEP 3: Go to t code RSO2 & create a DataSource with the same name that we have used in our FM i.e., ZZ_SHIPMENT_DATA & as we are uploading transactional data so select the radiobutton for Transaction data as shown below:  

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image