‎2009 Mar 13 5:01 AM
Hi Experts,
I am doing a report for stock with subcontractors and I am facing a problem in getting the accurate
Norms (STPO~MENGE) against the BOM (STPO~STLNR) for each EBELN.
My requirement is :
1. Finished Goods - ( MSEG~MATNR) or (EKPO~MATNR) but mseg-matnr is more prefered as my output is based on the mkpf-budat , WHERE BWART IN ('101','102') then
MSEG~EBELN.
IF EKPO-PSTYP ne ' 3 ' delete Finished goods.
Then I take raw materials for finished goods and BOM for each rawmaterials.
2. Raw materials - select (RESBMATNR, RESBSTLNR, RESBSTLKN, RESBSTPOZ) where resb-baugr = mseg-matnr and ebeln = mseg-ebeln.
Now I am facing problem in getting NORMS against each BOM.
3. Norms - * select STPOMENGE where STLNR = RESBSTLNR , IDNRK = RESB~MATNR,
STPOZ = RESB~STPOZ.
But I am not getting the correct Norms for each EBELN, please advice if my logic is wrong or if my
tables are wrong.
Thanks
Karthik.
Edited by: Karthik R on Mar 13, 2009 10:32 AM
Edited by: Karthik R on Mar 13, 2009 10:32 AM
Edited by: Karthik R on Mar 13, 2009 10:33 AM
‎2009 Mar 13 6:35 AM
Hi Karthik,
You try this one, which I already tried and working fine for me when i developed a custom's enquiry report,
here is a peice of code,
****************************************************************
SELECT ABUDAT AXBLNR BMBLNR BZEILE
BBWART BEBELN BMENGE BDMBTR B~KUNNR
INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
FROM MKPF AS A INNER JOIN MSEG AS B ON AMBLNR = BMBLNR AND
AMJAHR = BMJAHR
WHERE A~BUDAT IN S_BUDAT AND
B~MATNR = WA_IMAT-MATNR AND
B~WERKS IN S_WERKS .
IF NOT IT_FINAL IS INITIAL.
SELECT MATNR WERKS STLAN STLNR STLAL
FROM MAST INTO TABLE IT_MAST
WHERE MATNR = WA_IMAT-MATNR AND
WERKS IN S_WERKS AND
STLAN = '1'.
ENDIF.
IF NOT IT_MAST IS INITIAL.
SELECT STLTY STLNR STLAL DATUV BMEIN BMENG
FROM STKO INTO TABLE IT_STKO
FOR ALL ENTRIES IN IT_MAST
WHERE STLNR = IT_MAST-STLNR AND
STLAL = IT_MAST-STLAL AND ( STLTY = 'D' OR STLTY = 'E' OR STLTY = 'K' OR
STLTY = 'M' OR STLTY = 'S' OR STLTY = 'T' OR STLTY = 'P' ).
ENDIF.
IF NOT IT_STKO IS INITIAL.
SELECT STLNR DATUV IDNRK POSNR MEINS MENGE
FROM STPO INTO TABLE IT_STPO
FOR ALL ENTRIES IN IT_STKO
WHERE STLNR = IT_STKO-STLNR AND STLTY = IT_STKO-STLTY.
ENDIF.
IF NOT IT_STPO IS INITIAL.
SELECT MATNR MAKTX
FROM MAKT INTO TABLE IT_MAKT
FOR ALL ENTRIES IN IT_STPO
WHERE MATNR = IT_STPO-IDNRK AND
SPRAS = 'EN'.
ENDIF.
LOOP AT IT_STKO INTO WA_STKO.
" Own Custom Logic, If Item Quantity is 500 KG, how to calculate per KG, Simple divide by the same Qty.
IF WA_STKO-BMEIN = 'KG'.
LOOP AT IT_STPO INTO WA_STPO.
WA_STPO-RATIO = WA_STPO-MENGE / WA_STKO-BMENG.
MODIFY IT_STPO FROM WA_STPO.
CLEAR : WA_STPO.
ENDLOOP.
ENDIF.
CLEAR : WA_STKO.
ENDLOOP.
LOOP AT IT_STPO INTO WA_STPO.
LOOP AT IT_MAKT INTO WA_MAKT.
MOVE-CORRESPONDING WA_MAKT TO WA_STPO.
DELETE TABLE IT_MAKT FROM WA_MAKT.
CLEAR : WA_MAKT.
EXIT.
ENDLOOP.
MODIFY IT_STPO FROM WA_STPO.
CLEAR : WA_STPO.
ENDLOOP.
LOOP AT IT_FINAL1 INTO WA_FINAL1 WHERE BWART = '101' OR BWART = '102'.
MOVE WA_FINAL1-BUDAT TO WA_FINAL2-BUDAT.
MOVE WA_FINAL1-EBELN TO WA_FINAL2-EBELN.
MOVE WA_FINAL1-MENGE TO WA_FINAL2-MENGE.
MOVE WA_FINAL1-DMBTR TO WA_FINAL2-DMBTR.
APPEND WA_FINAL2 TO IT_FINAL2.
CLEAR : WA_FINAL1.
ENDLOOP.
****************************************************************
Thanks & Regards,
Dileep .C
‎2009 Mar 13 6:35 AM
Hi Karthik,
You try this one, which I already tried and working fine for me when i developed a custom's enquiry report,
here is a peice of code,
****************************************************************
SELECT ABUDAT AXBLNR BMBLNR BZEILE
BBWART BEBELN BMENGE BDMBTR B~KUNNR
INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
FROM MKPF AS A INNER JOIN MSEG AS B ON AMBLNR = BMBLNR AND
AMJAHR = BMJAHR
WHERE A~BUDAT IN S_BUDAT AND
B~MATNR = WA_IMAT-MATNR AND
B~WERKS IN S_WERKS .
IF NOT IT_FINAL IS INITIAL.
SELECT MATNR WERKS STLAN STLNR STLAL
FROM MAST INTO TABLE IT_MAST
WHERE MATNR = WA_IMAT-MATNR AND
WERKS IN S_WERKS AND
STLAN = '1'.
ENDIF.
IF NOT IT_MAST IS INITIAL.
SELECT STLTY STLNR STLAL DATUV BMEIN BMENG
FROM STKO INTO TABLE IT_STKO
FOR ALL ENTRIES IN IT_MAST
WHERE STLNR = IT_MAST-STLNR AND
STLAL = IT_MAST-STLAL AND ( STLTY = 'D' OR STLTY = 'E' OR STLTY = 'K' OR
STLTY = 'M' OR STLTY = 'S' OR STLTY = 'T' OR STLTY = 'P' ).
ENDIF.
IF NOT IT_STKO IS INITIAL.
SELECT STLNR DATUV IDNRK POSNR MEINS MENGE
FROM STPO INTO TABLE IT_STPO
FOR ALL ENTRIES IN IT_STKO
WHERE STLNR = IT_STKO-STLNR AND STLTY = IT_STKO-STLTY.
ENDIF.
IF NOT IT_STPO IS INITIAL.
SELECT MATNR MAKTX
FROM MAKT INTO TABLE IT_MAKT
FOR ALL ENTRIES IN IT_STPO
WHERE MATNR = IT_STPO-IDNRK AND
SPRAS = 'EN'.
ENDIF.
LOOP AT IT_STKO INTO WA_STKO.
" Own Custom Logic, If Item Quantity is 500 KG, how to calculate per KG, Simple divide by the same Qty.
IF WA_STKO-BMEIN = 'KG'.
LOOP AT IT_STPO INTO WA_STPO.
WA_STPO-RATIO = WA_STPO-MENGE / WA_STKO-BMENG.
MODIFY IT_STPO FROM WA_STPO.
CLEAR : WA_STPO.
ENDLOOP.
ENDIF.
CLEAR : WA_STKO.
ENDLOOP.
LOOP AT IT_STPO INTO WA_STPO.
LOOP AT IT_MAKT INTO WA_MAKT.
MOVE-CORRESPONDING WA_MAKT TO WA_STPO.
DELETE TABLE IT_MAKT FROM WA_MAKT.
CLEAR : WA_MAKT.
EXIT.
ENDLOOP.
MODIFY IT_STPO FROM WA_STPO.
CLEAR : WA_STPO.
ENDLOOP.
LOOP AT IT_FINAL1 INTO WA_FINAL1 WHERE BWART = '101' OR BWART = '102'.
MOVE WA_FINAL1-BUDAT TO WA_FINAL2-BUDAT.
MOVE WA_FINAL1-EBELN TO WA_FINAL2-EBELN.
MOVE WA_FINAL1-MENGE TO WA_FINAL2-MENGE.
MOVE WA_FINAL1-DMBTR TO WA_FINAL2-DMBTR.
APPEND WA_FINAL2 TO IT_FINAL2.
CLEAR : WA_FINAL1.
ENDLOOP.
****************************************************************
Thanks & Regards,
Dileep .C
‎2009 Mar 17 9:52 AM
Hi Dileep,
Thank you !! But it does'nt meet my requirement as I need the BOM for each ebeln of a particular
matnr. But I got the corresponding STLNR from resb table.
But now I want the menge from STKO for the corresponding BOM of particular ebeln
please advice how do I get it, is there any other corresponding table for it?
Thanks
Karthik
‎2009 Mar 17 4:42 PM
Hi Karthik,
You try to goto MAST table with matnr and stlnr, from RESB.. and try to modify my code little,,,,
I hope it works,
If not you try to find some pre written code for BOM in SAP wiki, Will be helpful for you..
thanks & regards,
Dileep .C
‎2009 Mar 18 1:27 AM
Hi Karthik,
For your requirement, when there is a EBELN (P.O) there will be s (GR) BWART = 101, 102
and this will be stored from MSEG & MKPF,
Now just pick the MATNR as I already given i the Above code, and Dont go to RESB Table.
I see no necessary to go for RESB Table, All you need is to given in the above code, As now i can see your requirement is same as mine/... only the difference is to who you show the report, I show to Customs & you showing to someone else, Thats it. But same requirement.
Just try once my code again in a new editor and see whether it works or not...!
Thanks & Regards,
Dileep .C
‎2009 Mar 18 2:11 AM
Hi,
Just like what they said you can go to MAST, MARA and STPO.
MARA - to check the type of your material (FG,SEMi-FG, raw, etc)
MAST- to check the BOM link for your material
STPO - to check the components of of your material.
it goes like MATNR(FG) pass to MAST-MATNR to get MAST-STLNR then MAST-STLNR pass to STPO-STLNR to get STPO-IDNRK . then pass to MAST-MATNR to get MAST-STLNR then MAST-STLNR pass to STPO-STLNR to get STPO-IDNRK ....so on and so forth. do this searching until you cannot retreive a record.it only means that you got all raw materials(most raw materials dont have components)
Hope this helps you.
Regards,
Leonard Chomi.