先使用如下程序对已出错订单进行修正,然后再实施Note 1094999 - Goods receipt quantity is updated incorrectly
---------------分割线-----------------------------------------
REPORT Z_PPCON_076 .
TABLES: AFKO, AFPO, MSEG, MKPF.
PARAMETERS: TEST_? TYPE C DEFAULT 'X'.
SELECT-OPTIONS: PAORDER FOR AFPO-AUFNR.
DATA: BEGIN OF UPOS_TAB OCCURS 500.
INCLUDE STRUCTURE AFPO.
DATA: END OF UPOS_TAB.
DATA: BEGIN OF POS_TAB OCCURS 500.
INCLUDE STRUCTURE AFPO.
DATA: END OF POS_TAB.
DATA: BEGIN OF A_TAB OCCURS 500,
AUFNR LIKE AFKO-AUFNR,
END OF A_TAB.
DATA: BEGIN OF M_TAB OCCURS 500.
INCLUDE STRUCTURE MSEG.
DATA: END OF M_TAB.
DATA: NO_WEMNG LIKE AFPO-WEMNG VALUE '0',
NO_LTRMI LIKE AFPO-LTRMI VALUE '00000000',
KUM_WEMNG LIKE AFPO-WEMNG,
KUM_WEWRT LIKE AFPO-WEWRT,
DIF_QUAN LIKE AFPO-IAMNG,
DIF_WERT LIKE AFPO-WEWRT,
U_FLAG TYPE C.
IF NOT TEST_? IS INITIAL.
WRITE: ' !!!!! TEST !!!!!!'.
SKIP 1.
ENDIF.
SELECT * FROM AFPO INTO TABLE POS_TAB
WHERE AUFNR IN PAORDER.
* read material documents per order
LOOP AT POS_TAB.
REFRESH M_TAB.
CLEAR: U_FLAG.
CLEAR: KUM_WEMNG.
CLEAR: KUM_WEWRT.
SELECT * FROM MSEG INTO TABLE M_TAB
WHERE MATNR EQ POS_TAB-MATNR
AND AUFNR EQ POS_TAB-AUFNR
AND AUFPS EQ POS_TAB-POSNR.
LOOP AT M_TAB.
CHECK M_TAB-BWART EQ '101' OR M_TAB-BWART EQ '102'
OR M_TAB-BWART EQ '122'.
*..inward movement
IF M_TAB-SHKZG EQ 'S'.
IF NOT M_TAB-DMBTR IS INITIAL.
KUM_WEWRT = KUM_WEWRT + M_TAB-DMBTR.
ENDIF.
IF NOT M_TAB-BSTMG IS INITIAL.
KUM_WEMNG = KUM_WEMNG + M_TAB-BSTMG.
ELSE.
IF M_TAB-ERFME EQ POS_TAB-AMEIN.
KUM_WEWRT = KUM_WEWRT + M_TAB-DMBTR.
ELSE.
IF M_TAB-MEINS EQ POS_TAB-AMEIN.
KUM_WEMNG = KUM_WEMNG + M_TAB-MENGE.
ELSE.
WRITE: 'ERROR - Order:', POS_TAB-AUFNR.
CLEAR U_FLAG.
EXIT.
ENDIF.
ENDIF.
ENDIF.
ELSE.
*..outward movement
IF NOT M_TAB-DMBTR IS INITIAL.
IF M_TAB-DMBTR NE M_TAB-BUALT AND
NOT M_TAB-BUALT IS INITIAL.
KUM_WEWRT = KUM_WEWRT - M_TAB-BUALT.
ELSE.
KUM_WEWRT = KUM_WEWRT - M_TAB-DMBTR.
ENDIF.
ENDIF.
IF NOT M_TAB-BSTMG IS INITIAL.
KUM_WEMNG = KUM_WEMNG - M_TAB-BSTMG.
ELSE.
IF M_TAB-ERFME EQ POS_TAB-AMEIN.
KUM_WEMNG = KUM_WEMNG - M_TAB-ERFMG.
ELSE.
IF M_TAB-MEINS EQ POS_TAB-AMEIN.
KUM_WEMNG = KUM_WEMNG - M_TAB-MENGE.
ELSE.
WRITE: 'ERROR - Order:', POS_TAB-AUFNR.
CLEAR U_FLAG.
EXIT.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
U_FLAG = 'X'.
ENDLOOP.
*..update necessary ?
IF NOT U_FLAG IS INITIAL AND ( NOT KUM_WEMNG IS INITIAL
AND KUM_WEMNG NE POS_TAB-WEMNG )
OR ( NOT KUM_WEWRT IS INITIAL
AND KUM_WEWRT NE POS_TAB-WEWRT ).
SELECT SINGLE * FROM MKPF WHERE MBLNR EQ M_TAB-MBLNR
AND MJAHR EQ M_TAB-MJAHR.
IF SY-SUBRC IS INITIAL.
MOVE MKPF-BUDAT TO POS_TAB-LTRMI.
ENDIF.
IF KUM_WEMNG = POS_TAB-WEMNG OR
KUM_WEWRT = POS_TAB-WEWRT.
WRITE: / 'No update for the following order - check the order !'.
ELSE.
MOVE-CORRESPONDING POS_TAB TO UPOS_TAB.
MOVE KUM_WEMNG TO UPOS_TAB-WEMNG.
MOVE KUM_WEWRT TO UPOS_TAB-WEWRT.
APPEND UPOS_TAB.
ENDIF.
WRITE: / 'Order:', POS_TAB-AUFNR, 'Material:', POS_TAB-MATNR,
'Delivered Quantity:', POS_TAB-WEMNG, POS_TAB-AMEIN,
'Value:', POS_TAB-WEWRT.
WRITE: / 'Document Item Move-type Stock-Quantity Unit',
'Entry-Quantity Unit Value'.
LOOP AT M_TAB.
WRITE: / M_TAB-MBLNR, M_TAB-ZEILE, 21 M_TAB-BWART, 27 M_TAB-MENGE,
M_TAB-MEINS, M_TAB-BSTMG, M_TAB-BSTME, 71 M_TAB-DMBTR,
M_TAB-WAERS.
ENDLOOP.
ULINE.
DIF_QUAN = KUM_WEMNG - POS_TAB-WEMNG.
DIF_WERT = KUM_WEWRT - POS_TAB-WEWRT.
WRITE: /22 'Sum:', KUM_WEMNG, POS_TAB-AMEIN, 71 KUM_WEWRT,
/ 'Balance Quantity Document - Order:',
'Quantity:', DIF_QUAN, 'Value:', DIF_WERT.
SKIP 1.
ENDIF.
ENDLOOP.
CLEAR SY-DBCNT.
*...change order items.
IF TEST_? IS INITIAL AND NOT UPOS_TAB[] IS INITIAL.
UPDATE AFPO FROM TABLE UPOS_TAB.
ENDIF.
SKIP 1.
WRITE: / 'Changed Orders:', SY-DBCNT.
******** End of Report
No comments:
Post a Comment