Hi experts,
I have a requirement ...which will explode indirect BOM for specific material and plant.
now i need to validate before exploring the BOM with specific materil type and BOM usage.
for BOM explore i am using function module 'CS_BOM_EXPL_MAT_V2'......
this above function module i called in my own function module.....plz check the given code and help me in this..
i will give full reward points.
FUNCTION Z_EXPLORE_BOM_MULTI_LEVEL_2.
*"----
""Local interface:
*" IMPORTING
*" VALUE(I_MATNR) LIKE MAST-MATNR
*" VALUE(I_WERKS) LIKE MAST-WERKS
*" VALUE(I_DATE) LIKE SY-DATUM
*" REFERENCE(I_ABOM) TYPE CHAR1 OPTIONAL
*" TABLES
*" ZBOM_TAB STRUCTURE ZEXBOM2
*" EXCEPTIONS
*" NO_BOM_EXISTS
*" MATERIAL_NOT_EXISTS
*"----
*----
*Modification Log:
*CR# Date Coded Transport Description
*======= ======== ========= ========== =================================
*DR10131 20050916 AHARINA DEVK933246 Show Alternate BOM's
*----
TABLES: MARA, MARC.
DATA: BEGIN OF STB OCCURS 1000.
INCLUDE STRUCTURE STPOX.
DATA: END OF STB.
DATA: BEGIN OF MATCAT OCCURS 1000.
INCLUDE STRUCTURE CSCMAT.
DATA: END OF MATCAT.
DATA: TAB_LINES TYPE I,
PER LIKE STPO-MENGE.
DEVK908208 variables to store the status of the previous item
DATA: L_LAST_LEVEL type i. "last level (integer). count from 1, 2, ...
DATA: L_LAST_LEVEL_NORMAL. "X: last level is normal, blank: blocked/alt
DEVK908208
************************************************************************
Validate on importing parameters
SELECT SINGLE MATNR INTO MARA-MATNR FROM MARA WHERE MATNR = I_MATNR.
IF SY-SUBRC NE 0.
RAISE MATERIAL_NOT_EXISTS.
ENDIF.
SELECT SINGLE MATNR INTO MARC-MATNR FROM MARC WHERE MATNR = I_MATNR
AND WERKS = I_WERKS.
IF SY-SUBRC NE 0.
RAISE MATERIAL_NOT_EXISTS.
ENDIF.
Call function to explore BOM
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP01'
DATUV = I_DATE
MTNRV = I_MATNR
MEHRS = 'X'
RVREL = ' '
*{ INSERT UATK916232 1
Do not filter cost rel items here "DEVK908208
need additional algorithm to handle multi-level bom "DEVK908208
SANKA = 'X' "Must be cost relevancy
*} INSERT
WERKS = I_WERKS
TABLES
STB = STB
MATCAT = MATCAT
EXCEPTIONS
NO_BOM_FOUND = 1
NO_SUITABLE_BOM_FOUND = 2
OTHERS = 3.
IF SY-SUBRC NE 0.
RAISE NO_BOM_EXISTS.
ENDIF.
SELECT SINGLE MTART INTO ZBOM_TAB-MTART FROM MARA
WHERE MATNR = I_MATNR.
ZBOM_TAB-STLNR = STB-STLNR.
ZBOM_TAB-STUFE = '0'.
ZBOM_TAB-POSNR = '0000'.
ZBOM_TAB-STLKN = STB-STLKN. "DVPK907974
ZBOM_TAB-STPOZ = STB-STPOZ. "DVPK907974
ZBOM_TAB-BOM = I_MATNR.
ZBOM_TAB-MATNR = I_MATNR.
ZBOM_TAB-WERKS = I_WERKS.
ZBOM_TAB-MENGE = 1.
ZBOM_TAB-MEINS = STB-MEINS. "DVPK907974
ZBOM_TAB-STPRS = STB-STPRS. "DVPK907974
ZBOM_TAB-WAERS = STB-WAERS. "DVPK907974
ZBOM_TAB-DATUV = STB-DATUV. "DVPK907974
ZBOM_TAB-DATUB = STB-DATUB. "DVPK907974
APPEND ZBOM_TAB.
l_last_level = '0'. "DEVK908208
l_last_level_normal = 'X'. "DEVK908208
LOOP AT STB.
*{ INSERT UATK916232 2
check STB-ALPOS = space "Should not be alt. component
or STB-EWAHR = '100'. "or should be 100% if it is alt. comp.
*} INSERT
ZBOM_TAB-STLNR = STB-STLNR.
ZBOM_TAB-STUFE = STB-STUFE.
ZBOM_TAB-POSNR = STB-POSNR.
ZBOM_TAB-STLKN = STB-STLKN. "DVPK907974
ZBOM_TAB-STPOZ = STB-STPOZ. "DVPK907974
ZBOM_TAB-MATNR = STB-IDNRK.
ZBOM_TAB-MTART = STB-MTART.
ZBOM_TAB-WERKS = I_WERKS.
ZBOM_TAB-MENGE = STB-MNGKO.
READ TABLE MATCAT WITH KEY INDEX = STB-TTIDX.
ZBOM_TAB-BOM = MATCAT-MATNR.
ZBOM_TAB-MEINS = STB-MEINS. "DVPK907974
ZBOM_TAB-STPRS = STB-STPRS. "DVPK907974
ZBOM_TAB-WAERS = STB-WAERS. "DVPK907974
ZBOM_TAB-DATUV = STB-DATUV. "DVPK907974
ZBOM_TAB-DATUB = STB-DATUB. "DVPK907974
ZBOM_TAB-POTX1 = STB-POTX1. "DVPK907974
ZBOM_TAB-POTX2 = STB-POTX2. "DVPK907974
COLLECT ZBOM_TAB. "DEVK908208
BEGIN INSERT "DEVK908208
if STB-STUFE > L_LAST_LEVEL. " lower level
if L_LAST_LEVEL_NORMAL = 'X'.
Ashok
if i_abom = ' '. " DEVK933246
if ( STB-ALPOS = 'X' and STB-EWAHR is initial ) "alt item
or ( STB-SANKA is initial ). "not cost relv
L_LAST_LEVEL_NORMAL = space. " this item should be excluded
endif.
else.
if ( STB-SANKA is initial ). "not cost relv " DEVK933246
L_LAST_LEVEL_NORMAL = space. " this item should be excluded
endif. " DEVK933246
endif. " DEVK933246
L_LAST_LEVEL = STB-STUFE.
endif. " DEVK933246
else. "same / higher level
if i_abom = ' '. " DEVK933246
if ( STB-ALPOS = 'X' and STB-EWAHR is initial ) "alt item
or ( STB-SANKA is initial ). "not cost relv
L_LAST_LEVEL_NORMAL = space. " this item should be excluded
else.
L_LAST_LEVEL_NORMAL = 'X'. " this item should be included
endif.
else. " DEVK933246
if ( STB-SANKA is initial ). "not cost relv
L_LAST_LEVEL_NORMAL = space. " this item should be excluded
else. " DEVK933246
L_LAST_LEVEL_NORMAL = 'X'. " this item should be included
endif. " DEVK933246
endif. " DEVK933246
L_LAST_LEVEL = STB-STUFE. " update the level
endif.
if L_LAST_LEVEL_NORMAL = 'X'. " this item should be included
COLLECT ZBOM_TAB. " add item into internal table
APPEND ZBOM_TAB. "should use APPEND, not COLLECT
endif.
END INSERT "DEVK908208
ENDLOOP.
DESCRIBE TABLE ZBOM_TAB LINES TAB_LINES.
IF TAB_LINES = 0.
RAISE NO_BOM_EXISTS.
ENDIF.
ENDFUNCTION.