on 06-07-2005 5:47 AM
Hi Gurus,
my requirement is that i have to write a function module that can collect data from 5 tables in R/3 . i know there is function module (RSAX_BIW_GET_DATA_SIMPLE) which i can use as template but the problem is i am not good at ABAP so i dont know where to start so pls could u me some function mudule code written so i can take that as a template.
it is very urgent to me.
thanks in advance.
Regards,
ravindra.
I have a problem - I am trying to create a generic extract function module. The problem is that the template RSAX_BIW_GET_DATA_SIMPLE uses one database select. However for my purpose I need to select from various tables in order to build up my internal table.
It is for PO Service orders so I have to read headers then detailed lines then other tables to get account assignments etc. How do I transfer this to E_T_Data using the required logic for the fetch and open curser etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hallo
See below an example from SDN:
FUNCTION Z_BIW_GET_DATA_GLPCT.
*"----
""Local interface:
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR
*" VALUE(I_ISOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE DEFAULT 1000
*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" VALUE(I_UPDMODE) TYPE SBIWA_S_INTERFACE-UPDMODE OPTIONAL
*" VALUE(I_DATAPAKID) TYPE SBIWA_S_INTERFACE-DATAPAKID OPTIONAL
*" VALUE(I_CALLMODE) LIKE ROARCHD200-CALLMODE 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 ZBW_GLPCT OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"----
DataSource for table GLPCT
TABLES: GLPCT.
*
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.
Select ranges
RANGES: L_R_RBUKRS FOR GLPCT-RBUKRS,
L_R_RYEAR FOR GLPCT-RYEAR,
L_R_RPMAX FOR GLPCT-RPMAX,
L_R_RACCT FOR GLPCT-RACCT.
Parameter I_PRIVATE_MODE:
Some applications might want to use this function module for other
purposes as well (e.g. data supply for OLTP reporting tools). If the
processing logic has to be different in this case, use the optional
parameter I_PRIVATE_MODE (not supplied by BIW !) to distinguish
between BIW calls (I_PRIVATE_MODE = SPACE) and other calls
(I_PRIVATE_MODE = X).
If the message handling has to be different as well, define Your own
messaging macro which interprets parameter I_PRIVATE_MODE. When
called by BIW, it should use the LOG_WRITE macro, otherwise do what
You want.
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
************************************************************************
The input parameter I_DATAPAKID is not supported yet !
Invalid second initialization call -> error exit
IF NOT G_FLAG_INTERFACE_INITIALIZED IS INITIAL.
IF 1 = 2. MESSAGE E008(R3). ENDIF.
LOG_WRITE 'E' "message type
'R3' "message class
'008' "message number
' ' "message variable 1
' '. "message variable 2
RAISE ERROR_PASSED_TO_MESS_HANDLER.
ENDIF.
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_ISOURCE.
S_S_IF-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.
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 tables for fixed InfoSources. In the case of generated
InfoSources, the usage of a dynamical SELECT statement might be
more reasonable. BIW 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 = 'RBUKRS'.
MOVE-CORRESPONDING L_S_SELECT TO L_R_RBUKRS.
APPEND L_R_RBUKRS.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'RYEAR'.
MOVE-CORRESPONDING L_S_SELECT TO L_R_RYEAR.
APPEND L_R_RYEAR.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'RPMAX'.
MOVE-CORRESPONDING L_S_SELECT TO L_R_RPMAX.
APPEND L_R_RPMAX.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'RACCT'.
MOVE-CORRESPONDING L_S_SELECT TO L_R_RACCT.
APPEND L_R_RACCT.
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.
If the extarct not a delta, then extarct data only by
the selection criteria
OPEN CURSOR WITH HOLD S_CURSOR FOR
SELECT (S_S_IF-T_FIELDS) FROM GLPCT
WHERE RBUKRS IN L_R_RBUKRS AND
RYEAR IN L_R_RYEAR AND
RPMAX IN L_R_RPMAX AND
RACCT IN L_R_RACCT.
ENDIF. "First data package ?
Fetch records into interface table.
- fixed interface table structure for fixed InfoSources have to be
named E_T_'Name of assigned source structure in table ROIS'.
FETCH NEXT CURSOR S_CURSOR
APPENDING CORRESPONDING FIELDS
OF TABLE E_T_DATA
PACKAGE SIZE S_S_IF-MAXSIZE.
If there are no more records, then close cursor exit
IF SY-SUBRC <> 0.
CLOSE CURSOR S_CURSOR.
RAISE NO_MORE_DATA.
ENDIF.
Create anotoer data packet if you have extratced
S_S_IF-MAXSIZE number of records
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
ENDIF. "Initialization mode or data extraction ?
jugal behera
Posts: 6
Registered: 5/30/05
Re: generic datasource using function module
Posted: Jun 6, 2005 1:45 PM Reply E-mail this post
Hi,
There are sample data function module "RSAX_BIW_GET_DATA_SIMPLE" to suppaly data to a generica data source.
This function module is used to get data for a DataSource that was created using generic data extraction (transaction RSO2). During an extraction process, this function module is called up several times in succession:
1. Initialization call up:
Only the request parameters are transferred to the module here (see below). The module cannot transfer any data as yet.
1. First read call up:
The request parameters are not transferred again. The extractor returns data typified by the extract stucture in an interface table. The request parameter (I_MAXSIZE) specifies the number of expected rows.
1. Second read call up:
The extractor returns data connected to the first data package, again in a package with I_MAXSIZE rows.
1. The function module is called up again and again until it calls up the exception 'NO_MORE_DATA'. No more data is allowed to be transferred in the call up in which this exception arose.
The function module must have the following interfaces:
Importing parameters:
I_DSOURCE type SRSC_S_IF_SIMPLE-DSOURCE DataSource
I_INITFLAG type SRSC_S_IF_SIMPLE-INITFLAG Initialization call up
I_MAXSIZE type SRSC_S_IF_SIMPLE-MAXSIZE Package size
I_REQUNR type SRSC_S_IF_SIMPLE-REQUNR Request number
Tables:
I_T_SELECT type SRSC_S_IF_SIMPLE-T_SELECT
I_T_FIELDS type SRSC_S_IF_SIMPLE-T_SELECT
E_T_DATA
Exceptions:
NO_MORE_DATA
ERROR_PASSED_TO_MESS_HANDLER
Notes to the individual parameters:
I_INITFLAG
When the function module is called up for the first time, this parameter is set to 'X', afterwards it is set to ' '.
I_MAXSIZE
This parameter contains the number of rows expected for a read call up.
Also
http://help.sap.com/saphelp_nw04/helpdata/en/86/1c8c3e94243446e10000000a114084/content.htm
you can other example in the forum.
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.