Hi KD, Although its a long time since your post could u pls help me with the same information as i m also facing a issue while extracting data in BW from ECC via generic extractor based on FM using FM cs_bom_expl_mat_v2 in ECC. Only Few records are appearing no data related to cs_bom_expl_mat_v2 is coming as of now.
my code is
FUNCTION ZRSAX_BIW_GET_DATA_SIMPLE_BOM.
*"----------------------------------------------------------------------
*"*"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 ZSBOMDTL OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------
TABLES: MAST , ZSBOMDTL , marc, mbewh.
* Auxiliary Selection criteria structure
DATA: L_S_SELECT TYPE SRSC_S_SELECT.
DATA: it_marc type standard table of marc,
it_mbewh type standard table of mbewh,
wa_mbewh type mbewh,
wa_marc type marc.
DATA: i_lfgja type c length 4,
i_lfmon type c length 2.
* 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
* (following calls) ?
IF I_INITFLAG = SBIWA_C_FLAG_ON.
************************************************************************
* Initialization: check input parameters
* buffer input parameters
* prepare data selection
************************************************************************
* Check DataSource validity
CASE I_DSOURCE.
WHEN 'ZDS_BOMDTL'.
WHEN OTHERS.
IF 1 = 2. MESSAGE E009(R3). ENDIF.
* this is a typical log call. Please write every error message like this
LOG_WRITE 'E' "message type
'R3' "message class
'009' "message number
I_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 calls
S_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. "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 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 = 'MATNR'.
MOVE-CORRESPONDING L_S_SELECT TO R_MATNR.
APPEND R_MATNR.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'WERKS'.
MOVE-CORRESPONDING L_S_SELECT TO R_WERKS.
APPEND R_WERKS.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'STLNR'.
MOVE-CORRESPONDING L_S_SELECT TO R_STLNR.
APPEND R_STLNR.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'STLAN'.
MOVE-CORRESPONDING L_S_SELECT TO R_STLAN.
APPEND R_STLAN.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'STLAL'.
MOVE-CORRESPONDING L_S_SELECT TO R_STLAL.
APPEND R_STLAL.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'ERDAT'.
MOVE-CORRESPONDING L_S_SELECT TO R_ERDAT.
APPEND R_ERDAT.
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 * FROM MAST
WHERE MATNR IN R_MATNR
AND WERKS IN R_WERKS
AND STLNR IN R_STLNR
AND STLAN IN R_STLAN
AND STLAL IN R_STLAL.
else.
RAISE no_more_data.
ENDIF. "First data package ?
refresh : i_mast,e_t_data,t_data.
* Fetch records into interface table.
* named E_T_'Name of extract structure'.
FETCH NEXT CURSOR S_CURSOR
APPENDING CORRESPONDING FIELDS
OF TABLE I_MAST
PACKAGE SIZE S_S_IF-MAXSIZE.
IF SY-SUBRC <> 0.
CLOSE CURSOR S_CURSOR.
RAISE NO_MORE_DATA.
ENDIF.
sort i_mast by werks matnr stlnr.
delete i_mast where werks = ''.
break-point.
loop at i_mast.
call function 'CS_BOM_EXPL_MAT_V2'
exporting
capid = 'PP01'
datuv = r_erdat-low
emeng = '1'
mbwls = 'X'
mehrs = 'X'
mtnrv = i_mast-matnr
stlal = i_mast-stlal
stlan = i_mast-stlan
werks = i_mast-werks
importing
topmat = i_cstmat
tables
stb = i_stb
matcat = i_cscmat
exceptions
alt_not_found = 1
call_invalid = 2
material_not_found = 3
missing_authorization = 4
no_bom_found = 5
no_plant_data = 6
no_suitable_bom_found = 7
conversion_error = 8
others = 9
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
if r_erdat-low+4(2) LE '03'.
i_lfgja = r_erdat-low+0(4) - 1.
i_lfmon = r_erdat-low+4(2) + 9.
else.
i_lfgja = r_erdat-low+0(4).
i_lfmon = r_erdat-low+4(2) - 3.
endif.
select single * from mbewh into wa_mbewh
where matnr = i_mast-matnr
and bwkey = i_mast-werks
and lfgja = i_lfgja
and lfmon = i_lfmon.
if sy-subrc = 0.
t_data-stprs = wa_mbewh-stprs.
t_data-verpr = wa_mbewh-verpr.
else.
select * from mbewh into table it_mbewh
where matnr = i_mast-matnr
and bwkey = i_mast-werks
and lfgja le i_lfgja
and lfmon le i_lfmon.
sort it_mbewh by lfgja lfmon ascending.
read table it_mbewh into wa_mbewh index 1.
if sy-subrc = 0.
t_data-stprs = wa_mbewh-stprs.
t_data-verpr = wa_mbewh-verpr.
endif.
endif.
BREAK-POINT.
read table i_cscmat
with key matnr = i_mast-matnr.
if sy-subrc = 0.
t_data-base_matnr = i_cscmat-matnr.
endif.
t_data-mandt = i_mast-mandt.
t_data-erdat = r_erdat-low.
t_data-matnr = i_mast-matnr.
t_data-werks = i_mast-werks.
t_data-stlan = i_mast-stlan.
t_data-stlnr = i_mast-stlnr.
t_data-stlal = i_mast-stlal.
t_data-stlty = i_cstmat-stlty.
t_data-datuv = i_cstmat-datuv.
t_data-datub = i_cstmat-datub.
t_data-menge = i_cstmat-emeng.
t_data-meins = i_cstmat-emgme.
t_data-waers = 'INR'.
t_data-stufe = '1'.
t_data-ttidx = ' '.
t_data-component = ' '.
t_data-comp_qty = ' '.
t_data-comp_unit = ' '.
t_data-comp_datuv = ' '.
t_data-comp_datub = ' '.
t_data-preih = ' '.
t_data-schgt = ' '.
append t_data.
loop at i_stb.
read table i_cscmat
with key index = i_stb-ttidx.
if sy-subrc = 0.
t_data-base_matnr = i_cscmat-matnr.
endif.
t_data-mandt = i_mast-mandt.
t_data-erdat = r_erdat-low.
t_data-matnr = i_mast-matnr.
t_data-werks = i_mast-werks.
t_data-stlan = i_mast-stlan.
t_data-stlnr = i_mast-stlnr.
t_data-stlal = i_mast-stlal.
t_data-stlty = i_cstmat-stlty.
t_data-datuv = i_cstmat-datuv.
t_data-datub = i_cstmat-datub.
t_data-menge = i_cstmat-emeng.
t_data-meins = i_cstmat-emgme.
t_data-stufe = i_stb-stufe.
t_data-ttidx = i_stb-ttidx.
t_data-component = i_stb-idnrk.
t_data-comp_qty = i_stb-menge.
t_data-comp_unit = i_stb-meins.
t_data-comp_datuv = i_stb-datuv.
t_data-comp_datub = i_stb-datub.
select single * from marc into wa_marc
where matnr = i_stb-idnrk
and werks = i_mast-werks.
if sy-subrc = 0.
t_data-schgt = wa_marc-schgt.
endif.
select single * from mbewh into wa_mbewh
where matnr = i_stb-idnrk
and bwkey = i_mast-werks
and lfgja = i_lfgja
and lfmon = i_lfmon.
if sy-subrc = 0.
t_data-stprs = wa_mbewh-stprs.
t_data-verpr = wa_mbewh-verpr.
else.
select * from mbewh into table it_mbewh
where matnr = i_stb-idnrk
and bwkey = i_mast-werks
and lfgja LE i_lfgja
and lfmon LE i_lfmon.
sort it_mbewh by lfgja lfmon ascending.
read table it_mbewh into wa_mbewh index 1.
if sy-subrc = 0.
t_data-stprs = wa_mbewh-stprs.
t_data-verpr = wa_mbewh-verpr.
endif.
endif.
t_data-preih = i_stb-preih.
t_data-waers = 'INR'.
append t_data.
endloop.
endloop.
e_t_data[] = t_data[].
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
ENDIF. "Initialization mode or data extraction ?
ENDFUNCTION.