extraction using functional module
DESCRIPTION
tyujklTRANSCRIPT
![Page 1: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/1.jpg)
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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/2.jpg)
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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/3.jpg)
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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/4.jpg)
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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/5.jpg)
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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/6.jpg)
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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/7.jpg)
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 8: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/8.jpg)
![Page 9: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/9.jpg)
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 10: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/10.jpg)
![Page 11: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/11.jpg)
![Page 12: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/12.jpg)
![Page 13: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/13.jpg)
Now we have created a copy of Functional Group and Functional Module..
![Page 14: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/14.jpg)
![Page 15: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/15.jpg)
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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/16.jpg)
************************************************************************* 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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/17.jpg)
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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/18.jpg)
Activate Functional Module..
Step 3
Create Datasource
Goto Tcode RSO2
![Page 21: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/21.jpg)
Click on Save button
![Page 23: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/23.jpg)
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](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/25.jpg)
so we have data in datasource... Now replicate to BI...
![Page 26: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/26.jpg)
Our Datasource is replicated to BI system...
![Page 27: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/27.jpg)
![Page 30: Extraction Using Functional Module](https://reader030.vdocuments.site/reader030/viewer/2022020403/577c830a1a28abe054b351c0/html5/thumbnails/30.jpg)
Our data has successfully reached BI system... Now take it to the corresponding targets