[PP] 判斷不同BOM修改, 將BOM核發狀態改為unrelease
BAdI: BOM_UPDATE
Method: CHANGE_AT_SAVE
[CODE]
METHOD IF_EX_BOM_UPDATE~CHANGE_AT_SAVE.
CHECK SY-TCODE EQ 'CS02'.
DATA: WA_STPO TYPE STPO,
L_MATNR TYPE MAST-MATNR,
L_WERKS TYPE MAST-WERKS,
L_STLNR TYPE MAST-STLNR,
L_STLAL TYPE MAST-STLAL,
TB_STPO TYPE STANDARD TABLE OF STPO,
L_RELEASE(1) TYPE C,
WA_STKO TYPE STKO,
WA_MAST TYPE MAST,
WA_STPO2 TYPE STPO.
CLEAR L_RELEASE.
LOOP AT DELTA_MASTB INTO WA_MAST.
MOVE: WA_MAST-MATNR TO L_MATNR.
MOVE: WA_MAST-WERKS TO L_WERKS.
SELECT SINGLE STLNR STLAL FROM MAST INTO (L_STLNR, L_STLAL) WHERE MATNR = L_MATNR AND WERKS = L_WERKS.
CHECK L_MATNR IS NOT INITIAL.
EXIT.
ENDLOOP.
IF L_MATNR+0(2) = 'PA' AND L_WERKS = '****'. " check statement
SELECT * FROM STPO INTO TABLE TB_STPO WHERE STLNR = L_STLNR AND STLTY = 'M'.
LOOP AT DELTA_STPOB INTO WA_STPO.
CLEAR: WA_STPO2.
READ TABLE TB_STPO INTO WA_STPO2 WITH KEY POSNR = WA_STPO-POSNR
IDNRK = WA_STPO-IDNRK
MENGE = WA_STPO-MENGE
MEINS = WA_STPO-MEINS.
IF WA_STPO2 IS NOT INITIAL. " Change qty of BOM component
L_RELEASE = 'X'.
ENDIF.
ENDLOOP.
CHECK L_RELEASE = 'X'.
SELECT SINGLE * INTO WA_STKO FROM STKO WHERE STLTY = 'M'
AND STLNR = L_STLNR
AND STLAL = L_STLAL.
WA_STKO-STLST = '2'. " 2: unrelease
WA_STKO-AEDAT = SY-DATUM.
WA_STKO-AENAM = SY-UNAME.
UPDATE STKO FROM WA_STKO.
ENDIF.
ENDMETHOD.
Method: CHANGE_AT_SAVE
[CODE]
METHOD IF_EX_BOM_UPDATE~CHANGE_AT_SAVE.
CHECK SY-TCODE EQ 'CS02'.
DATA: WA_STPO TYPE STPO,
L_MATNR TYPE MAST-MATNR,
L_WERKS TYPE MAST-WERKS,
L_STLNR TYPE MAST-STLNR,
L_STLAL TYPE MAST-STLAL,
TB_STPO TYPE STANDARD TABLE OF STPO,
L_RELEASE(1) TYPE C,
WA_STKO TYPE STKO,
WA_MAST TYPE MAST,
WA_STPO2 TYPE STPO.
CLEAR L_RELEASE.
LOOP AT DELTA_MASTB INTO WA_MAST.
MOVE: WA_MAST-MATNR TO L_MATNR.
MOVE: WA_MAST-WERKS TO L_WERKS.
SELECT SINGLE STLNR STLAL FROM MAST INTO (L_STLNR, L_STLAL) WHERE MATNR = L_MATNR AND WERKS = L_WERKS.
CHECK L_MATNR IS NOT INITIAL.
EXIT.
ENDLOOP.
IF L_MATNR+0(2) = 'PA' AND L_WERKS = '****'. " check statement
SELECT * FROM STPO INTO TABLE TB_STPO WHERE STLNR = L_STLNR AND STLTY = 'M'.
LOOP AT DELTA_STPOB INTO WA_STPO.
CLEAR: WA_STPO2.
READ TABLE TB_STPO INTO WA_STPO2 WITH KEY POSNR = WA_STPO-POSNR
IDNRK = WA_STPO-IDNRK
MENGE = WA_STPO-MENGE
MEINS = WA_STPO-MEINS.
IF WA_STPO2 IS NOT INITIAL. " Change qty of BOM component
L_RELEASE = 'X'.
ENDIF.
ENDLOOP.
CHECK L_RELEASE = 'X'.
SELECT SINGLE * INTO WA_STKO FROM STKO WHERE STLTY = 'M'
AND STLNR = L_STLNR
AND STLAL = L_STLAL.
WA_STKO-STLST = '2'. " 2: unrelease
WA_STKO-AEDAT = SY-DATUM.
WA_STKO-AENAM = SY-UNAME.
UPDATE STKO FROM WA_STKO.
ENDIF.
ENDMETHOD.
留言
張貼留言