Sei sulla pagina 1di 5

Generic Extraction with Function Module:

----------------------------------------
We can do the Generic Extraction based on
Table/View
Domain
Infoset
Function Module

Generic extraction based on Table/View,Domain,Infoset, system will create extract


structure automatically.
Generic extraction based on Function Module, we need to create Extract structure
explicitly and provide to the Datasource.

1.Create Extract Structure


2.Create Function Module
3.Create Datasource by using Extract Structure & Function Module

Scenario:
VBAK: VBELN
ERDAT
NETWR
WAERK
KUNNR
-----------------------------------------------------------------------------------
---------------------------------------
Step1: Create Extract Structure -> SE11

Data Type: ZBW_ES_VBAK


Data Element
Stucture
Table Type

".INCLUDE" -> It includes all the fields to the extract structure from the table

-----------------------------------------------------------------------------------
--------------------------------------

Step2: Create Function Module -> SE37(For ex. ZFM_G001)


- Create Function Group
- 2 Programs(Include Programs)
- Top Include(Global Declaration)
- Second Include(Connection between Function Module and
Function Group)

When creting the Function Group, it will create 2 Include programs by default
1.Top Include: INCLUDE LZFM_G001TOP
2.Second Include: INCLUDE LZFM_G001Uxx

Create Function Module -> SE37


RSAX_BIW_GET_DATA - Standard Function Module
Copy the above Standard function module to our function module(ZFM_001)

Here we can see the below 5 tabs in the Function Module:

Attributes
Import
Export
Changing
Tables
Exception
Source Code

Need to define the Internal Table "E_T_DATA" by assigning the Extract Structure
"ZBW_ES_VBAK" in the Tables tab.

Tables:
---------------------------------------------
Parameter Name Type Spec. Associated Type
---------------------------------------------
E_T_DATA LIKE ZBW_ES_VBAK
---------------------------------------------

E_T_DATA: This Internal Table data is output for BW and need to fill this Internal
Table.
Structure of this internal table should fill with the fields of Extract Structure.

IMPORT:
I_REQUNR: Request No.
I_ISOURCE: Datasource Name
I_MAXSIZE: Data Packet Size
I_INITFLAG: Initialization Call
If it is 'X' -> Initialization Call
If it is '' -> Data Extraction Call
I_UPDMODE: Update Mode of Infopackage(Init,Full,Delta)
I_DATAPAKID: Datapacket No.
For first time Extraction(I_INITFLAG),I_DATAPACKID is ZERO
i.e. If I_INITFLAG = 'X', I_DATAPACKID = '0'.
I_PRIVATE_MODE:
I_CALLMODE:
I_REMOTE_CALL:

TABLES:
I_T_SELECT: This Internal Table have all the selection fields
For eg. VBELN = 1111; KUNNR = 0111
I_T_FIELDS: This Internal table will have all the fields which are in the extract
structure fields
E_T_DATA: Internal Table where the data is storedwhich will be passed to BW.
E_T_SOURCE_STRUCTURE_:

SOURCE CODE:

SELECT VBELN ERDAT NETWR WAERS KUNNR FROM VBAK INTO TABLE E_T_DATA.

-----------------------------------------------------------------------------------
--------
Step3: After creating the Extract Structure & Function Module, we need to create
Datasource

Create Datasource - RSO2

Datasource: ZBW_FM1
Application Componenet: SD

Short Description: FM Extraction


Medium Description: FM Extraction
Long Description: FM Extraction
Select "Extraction By FM" push button

Function Module: ZFM_001


Extract Structure: ZBW_ES_VBAK

Save the datasource

Select the Selection fields from the datasource:


For Ex. VBELN, KUNNR
Again Save the datasource
-----------------------------------------------------------------------------------
----------
Limitations:

1.Unable to read/control the data packet size


We cannot use the select statement to fetch the data from Database
2.Unable to control the Selection field's of a datasource(Selections:VBAK =
1111;KUNNR = 0111)

Inorder to overcome above two issues, we need to use Cursor statements.


Hence we need to use Cursor statements to control the datapacket size in the Source
Code.
-----------------------------------------------------------------------------------
--------
The New Source Code as below: For CURSOR Statement Logic

TABLES: VBAK.
RANGES: l_r_VBELN FOR VBAK-VBELN,
l_r_KUNNR FOR VBAK-KUNNR.

Ranges for Multiple Intervals

APPEND LINES OF i_t_select TO g_t_select.(i_t_select -> Local temporary


table;g_t_select -> Global temporary table)

g_s_interface-requnr = i_requnr.
g_s_interface-isource = isource.
g_s_interface-maxsize = i_maxsize.
g_s_interface-initflag = i_initflag.
g_s_interface-updmode = i_updmode.
g_s_interface-datapakid = i_datapakid.
g_flag_interface-initialized = sbiwa_c_flag_on.

APPEND LINES OF i_t_fields TO g_t_fields.

CURSOR Statement: Read data from Database based on packet size by using CURSOR
Statement Logic.

OPEN CURSOR + FETCH + CLOSE CURSOR

OPEN CURSOR: Open CURSOR will keep ready the data for extraction
One time operation
FETCH: Extraction of data
Multiple times: Packet by Packet
DataPacket 1
2
3
4
.
.
.
.
Last DataPacket
CLOSE CURSOR: After completion of extraction of all the data by uing datapackets.
One time operation

IF g_counter_datapakid = 0.

LOOP AT g_t_select INTO l_s_select WHERE fieldnm = 'VBELN'.


MOVE-CORRESPONDING l_s_select TO l_r_VBELN.
APPEND l_r_VBELN.
ENDLOOP.

LOOP AT g_t_select INTO l_s_select WHERE fieldnm = 'KUNNR'.


MOVE-CORRESPONDING l_s_select TO l_r_KUNNR.
APPEND l_r_KUNNR.
ENDLOOP.

OPEN CURSOR WITH HOLD g_cursor FOR


SELECT (g_t_fields) FROM VBAK
WHERE VBELN IN l_r_VBELN AND
KUNNR IN l_r_KUNNR.
ENDIF.

FETCH NEXT CURSOR g_cursor


APPENDING CORRESPONDING FIELDS
OF TABLE E_T_DATA
PACKAGE SIZE l_maxsize.

IF sy_subrc <> 0.
CLOSE CURSOR g_cursor.
RAISE no_more_data.
ENDIF.

g_counter_datapakid = g_counter_datapakid + 1.

ENDIF.

ENDFUNCTION.