Skip to Content
0
Former Member
May 12, 2008 at 04:24 PM

PP BOM Question

145 Views

I have question regarding calculating BOM USAGE QTY, By using MAST-STKO-STPO tables.

I have found for same STLNR and STLTY there can be multiple entries in STKO and STPO tables. Also STPO table does not necessarily have item with same name as Production Order(CO03). I have written code to select last entry out of both STKO and STPO table to do the stpo-menge / STKO-BMENG calculation and in case the name(IDNRK) does not match name from PO then

do the calculation using AFKO table (itab_report-igmng / afko-gamng). This is working in most cases but not all, can anyone give me comprehensive logic which takes care of all cases.

The link below has TWO excel files having data from table STPO and STKO for particular STNLR for example(this particular case does work right with logic i have till now)

http://myaccount.dropsend.com/file/6ed2646493269ab6

Here is the code I have till now.

select bmeng
from STKO
INTO CORRESPONDING FIELDS OF WA_STKO_TEMP
WHERE STLNR = WA_MAST-STLNR
and stlty = 'M'
AND STLST = 1.
CLEAR WA_STKO. “ only take last item
Move-CORRESPONDING WA_STKO_TEMP TO WA_STKO. “ only take last item
ENDSELECT.

select *
from stpo
into corresponding fields of wa_stpo_temp " pk
where idnrk = coep-matnr
and stlnr = wa_mast-stlnr
and stlty = 'M'.
clear wa_stpo. " only take last item
MOVE-CORRESPONDING WA_STPO_TEMP TO WA_STPO. “only take last item
ENDSELECT.

if sy-subrc is initial.” If stpo had item with same name as CO03
* convert the base unit price to BOM unit price
if not mara-meins eq wa_stpo-meins.
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
i_matnr = wa_stpo-idnrk
i_in_me = wa_stpo-meins
i_out_me = wa_stpo-meins
i_menge = 1
IMPORTING
E_MENGE = w_unit1

IF sy-subrc <> 0.

ENDIF.

tdollar = tdollar / w_unit1.
endif.

itab_report-gamng = wa_stpo-menge / WA_STKO-BMENG."
endif.

if sy-subrc is not initial.”If stpo does not have item with same name as CO03

itab_report-gamng = itab_report-igmng / afko-gamng.

endif.

Edited by: Harry parmar on May 12, 2008 6:31 PM

Edited by: Harry parmar on May 12, 2008 6:32 PM

Edited by: Harry parmar on May 12, 2008 6:33 PM