extraction using functional module

31
Extraction using Functional Module A program is something that accepts an input , Do processing and delivers output..

Upload: srinivas

Post on 13-Jul-2016

229 views

Category:

Documents


1 download

DESCRIPTION

tyujkl

TRANSCRIPT

Page 1: Extraction Using Functional Module

Extraction using Functional Module

A program is something that accepts an input , Do processing and delivers output..

Structure of a program will look like this...

Page 2: Extraction Using Functional Module

Now consider a program logic that we do repeatedly in our program... It is not a good method to write code for that logic each time .. so we create a functional module...

Functional module is just another program which is global.. and can be accesses by all other programs...

Page 3: Extraction Using Functional Module

Now each time we don't have to write code for that program... we just need to call that functional module ..

Page 4: Extraction Using Functional Module

Through out the logic of program we are accessing ECC tables ( Transaction table), which will affect the efficiency of transaction system..

To overcome this we use Internal tables..

Page 5: Extraction Using Functional Module

Data from ECC table will be moved to this internal table.. and program access only this internal table not ECC tables...

Page 6: Extraction Using Functional Module

When we click on start button of Infopackage  our functional module is triggered..

E_T_DATA is our internal table which stores data from program logic and will be having the same structure of Extract structure of Datasource...

Page 7: Extraction Using Functional Module

Steps

1. Create a structure with necessary fields.

2. Create Functional Module.       * Extract data to the structure created       * Give the name of Datasource which is going to use this functional module

3. Create Datasource       * Add name of the structure and Functional Module while creating datasource

Step 1

Create structure.

Goto Tcode SE11 ( ABAP Data Dictionary)

Page 9: Extraction Using Functional Module

Add all the necessary fields needed in our structure.

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

Activate the structure..

Step 2

Create Functional Module

Goto Tcode SE80 ( ABAP Workbench)

Page 13: Extraction Using Functional Module

Now we have created a copy of Functional Group and Functional Module..

Page 15: Extraction Using Functional Module

go to source code tab and paste the following 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.                                                                    "Name of Structure"* 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,

RANGES: SDNO FOR znvbak1-VBELN.* Initialization mode (first call by SAPI) or data transfer mode* (following calls) ?IF I_INITFLAG = SBIWA_C_FLAG_ON.

Page 16: Extraction Using Functional Module

************************************************************************* Initialization: check input parameters* buffer input parameters* prepare data selection************************************************************************* Check DataSource validityCASE I_DSOURCE.WHEN 'ZFMEDS4'.                                                   " Name of Datasource"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

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.

* First data package -> OPEN CURSORIF 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.

Page 17: Extraction Using Functional Module

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.

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. ENDFUNCTION.

Page 18: Extraction Using Functional Module

Activate Functional Module..

Step 3

Create Datasource

Goto Tcode RSO2

Page 23: Extraction Using Functional Module

Now our data source is ready...

Now lets check if we have data in our Datasource...

Goto RSA3 (Extraction Checker)

Page 25: Extraction Using Functional Module

so we have data in datasource... Now replicate to BI...

Page 30: Extraction Using Functional Module

Our data has successfully reached BI system... Now take it to the corresponding targets