You are on page 1of 2

Generic Extraction via Function Module

How does the extraction api work in case you are extracting data using a self defined function module with generic delta? Sometimes, if your application or requirement makes it necessary, you have to create your own function module to extract the data from whatever sap system to bw. Therefore you normally make a copy of the standard fm 'RSAX_BIW_GET_DATA_SIMPLE'. To make this new function work for you, you have to realize the following. 1.) the fm gets called by the extraction api for at least 2 times. First time is for initialization and from the 2nd time on it is for data extraction. 2.) right after the last data package (somehow you need to make sure that it is the last one) you have to raise the exception no_more_data. Example with lots of comments

FUNCTION RSAX_BIW_GET_DATA_SIMPLE. *"-------------------------------------------------------------------------*"*"Lokale Schnittstelle: *" 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 *" 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 SFLIGHT OPTIONAL *" EXCEPTIONS *" NO_MORE_DATA *" ERROR_PASSED_TO_MESS_HANDLER *"-------------------------------------------------------------------------* 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. * Initialization mode (first call by SAPI) or data transfer mode IF I_INITFLAG = SBIWA_C_FLAG_ON. * the coding here will be processed the first time the fm gets called. * it is used to populate static or global variables and to check wether * it's called by the right datasource or not. ELSE. "Initialization mode or data extraction ? * this part will be executed from the 2nd call on * First data package -> OPEN CURSOR IF S_COUNTER_DATAPAKID = 0. * in case it is for the first data package, range tabs gets filled, a cursor will * be opened or a initial dataset will be read from database into a global internal table * this has to be done here, with the first data package, to avoid getting the same data with

* each call of the fm. * additionally you can check wether you get select-options for your 'generic delta'-field or not, * and, if it is provided, you are able to set a flag in order to do different selections * based on this flag for delta or full load. ENDIF. "First data package ? * from now on records gets fetched from the database or gets read from the internal table * and the return table e_t_data gets populated with the number of rows given by parameter s_s_if-maxsize. * if the last record is populated to table e_t_data you need to raise the exeption no_more_data * and you need to close the cursor, if you opened one. * with each data package you also have to increase s_counter_datapakid. ENDIF. "Initialization mode or data extraction ? ENDFUNCTION.

If you forget to raise no_more_data, the extraction api will call the fm forever. ITs suggested use business content extractors because of : 1)Its standars solution, so you will find the correspongins Cube, ODS ,etc 2)Most of the extractors has the Delta functionality, and if you want to create a generic extractor you have to add manually the delta functionality(for example time stamp) 3)Standard extractors are faster than generic extractor 4)In the upgrade, you will have to take care with generic extractors. These points that i mentioned are some of the advantages of standard extractors. Disagree with point 3. We have copied and improved a handfull of Business Content extractors, e.g. 0INFO_REC_ATTR. The delta load of the BC one proved to be slower than the full load, because in both cases a full table scan is done on table EINA and in delta mode, on top of this, the change docs were being read. So we built a generic DS with an improved copy of FM MEBW_INFORECORD_GET_DATA. Now the delta goes a lot faster like it should.

You might also like