注
MIGO前台和BAPI过账增强位置是分开的
MB_MIGO_BADI
注
- 只在MIGO前台触发,BAPI_GOODSMVT_CREATE不触发(BAPI处使用MB_DOCUMENT_BADI )
- MB_MIGO_BADI LINE_MODIFY,在回车和保存时会进来,所以可以修改PAI的项目值。要取抬头数据用指针指过去
批次
demo
MB_DOCUMENT_BADI
注
1.MB_DOCUMENT_BADI MB_DOCUMENT_UPDATE在update task里(MIGO前台和BAPI都会进去)
demo
method if_ex_mb_migo_badi~post_document.
data: wa_mseg type mseg,
wa_lips type lips.
data: lv_bsart type esart.
data: lt_lips type table of lips,
wa_likp type likp.
data: lv_mng101 type wemng,
lv_mnggi type wemng.
loop at it_mseg into wa_mseg.
select single bsart into lv_bsart from ekko where ebeln = wa_mseg-ebeln.
if lv_bsart = 'ZSTO'.
clear: lv_mng101,lv_mnggi.
select single wemng into lv_mng101 from eket where ebeln = wa_mseg-ebeln and ebelp = wa_mseg-ebelp.
select * into table lt_lips from lips where vgbel = wa_mseg-ebeln and vgpos = wa_mseg-ebelp.
if sy-subrc = 0.
loop at lt_lips into wa_lips.
clear wa_likp.
select single * into wa_likp from likp where vbeln = wa_lips-vbeln.
if wa_likp-gbstk = 'B' or wa_likp-gbstk = 'C'.
lv_mnggi = lv_mnggi + wa_lips-lfimg.
endif.
endloop.
lv_mng101 = lv_mng101 + wa_mseg-menge.
if lv_mng101 > lv_mnggi.
message '收货数量大于发货数量,请检查!' type 'E'.
exit.
endif.
else.
message '未创建交货单,不允许收货!' type 'E'.
exit.
endif.
endif.
*有交货已完成标记的采购订单不允许收货 cyl 20170406
select single *
into @data(ls_ekpo)
from ekpo
where ebeln = @wa_mseg-ebeln and ebelp = @wa_mseg-ebelp
and elikz = 'X'.
if sy-subrc = 0.
message '有交货已完成标记的采购订单不允许收货!' type 'E'.
endif.
endloop.
endmethod.
2.MBCF0002,函数EXIT_SAPMM07M_001(下面代码)
*标准成本发布物料移动增强
data ls_mbew like mbew.
if i_mseg-matnr is not initial and i_mseg-werks is not initial.
select single *
from mbew
into ls_mbew
where matnr = i_mseg-matnr
and bwkey = i_mseg-werks
and vprsv = 'S'.
if ls_mbew is not initial and ls_mbew-stprs is initial.
message e001(00) with '物料没有成本估算,不能进行物料移动,请联系成本会计首先更新!'.
endif.
endif.
*生产订单入库数量检查增强
DATA:BEGIN OF LT_AFRU OCCURS 0,
AUFNR LIKE AFRU-AUFNR,
VORNR LIKE AFRU-VORNR, "工序
LMNGA LIKE AFRU-LMNGA, "良品数量
XMNGA LIKE AFRU-XMNGA, "不良品数量
STOKZ LIKE AFRU-STOKZ, "冲销标记
END OF LT_AFRU.
DATA L_SUM LIKE I_MSEG-MENGE. "总报工数量
DATA L_AUART LIKE AUFK-AUART. "生产订单类型
DATA L_WEMNG LIKE AFPO-WEMNG. "已入库数量
DATA L_MENGE LIKE I_MSEG-MENGE. "本次可入库数量
IF I_MSEG-BWART = '101' AND I_MSEG-AUFNR IS NOT INITIAL AND SY-TCODE NE 'MBST'. "生产订单入库
*通常检查
SELECT SINGLE AUART
INTO L_AUART
FROM AUFK
WHERE AUFNR = I_MSEG-AUFNR.
FIND L_AUART IN 'TN01,TN02'. "TN01、TN02的类型才检查
IF SY-SUBRC = 0.
IF I_MSEG-WERKS NE '1310'
AND I_MSEG-WERKS NE '1320'
AND I_MSEG-WERKS NE '1390'
AND I_MSEG-WERKS NE '1510'
AND I_MSEG-WERKS NE '1590'
AND I_MSEG-WERKS NE '1990'
AND I_MSEG-WERKS NE '2210'
AND I_MSEG-WERKS NE '2290'
AND I_MSEG-WERKS NE '2390'
AND I_MSEG-WERKS NE '2590'
AND I_MSEG-WERKS NE '2690'
AND I_MSEG-WERKS NE '2790'
AND I_MSEG-WERKS NE '6010'.
IF L_AUART = 'TN02'. "检查总入库数量不能大于总报工数量
IF I_MSEG-AUFNR IS NOT INITIAL AND I_MSEG-BWART = '101'.
SELECT AUFNR VORNR LMNGA XMNGA STOKZ
INTO TABLE LT_AFRU
FROM AFRU
WHERE AUFNR = I_MSEG-AUFNR
AND VORNR = ( SELECT MAX( VORNR ) FROM AFRU WHERE AUFNR = I_MSEG-AUFNR ).
LOOP AT LT_AFRU.
IF LT_AFRU-STOKZ = 'X'.
LT_AFRU-LMNGA = - LT_AFRU-LMNGA.
LT_AFRU-XMNGA = - LT_AFRU-XMNGA.
ENDIF.
L_SUM = L_SUM + LT_AFRU-LMNGA + LT_AFRU-XMNGA.
ENDLOOP.
SELECT SINGLE WEMNG
INTO L_WEMNG
FROM AFPO
WHERE AUFNR = I_MSEG-AUFNR AND POSNR = 1.
IF L_WEMNG + I_MSEG-MENGE > L_SUM.
MESSAGE '订单' && I_MSEG-AUFNR && '入库实际数 大于 该订单的报工数量,请检查报工数量' TYPE 'E'.
ENDIF.
ENDIF.
ELSEIF L_AUART = 'TN01'. "检查总入库数量不大于总发料数
DATA:BEGIN OF LT_RESB OCCURS 0,
AUFNR LIKE RESB-AUFNR,
MATNR LIKE RESB-MATNR,
BDMNG LIKE RESB-BDMNG, "需求数量
XLOEK LIKE RESB-XLOEK, "删除
ENMNG LIKE RESB-ENMNG, "总发料数量
FLBL TYPE P DECIMALS 8, "发料比例
END OF LT_RESB.
* DATA L_ENMNG LIKE RESB-ENMNG. "总发料量
DATA L_PSMNG LIKE AFPO-PSMNG.
SELECT AUFNR RESB~MATNR BDMNG XLOEK
INTO TABLE LT_RESB
FROM RESB
INNER JOIN MARC ON RESB~MATNR = MARC~MATNR AND RESB~WERKS = MARC~WERKS
WHERE MARC~FEVOR = 'P02'
AND RESB~AUFNR = I_MSEG-AUFNR AND RESB~RGEKZ = SPACE AND RESB~KZEAR = SPACE. "排除反冲
IF SY-SUBRC = 0. "找不到非反冲件非P02就不检查
READ TABLE LT_RESB WITH KEY XLOEK = ''.
IF SY-SUBRC = 0. "在非反冲组件中至少有一个物料没有打删除标记才检查
SELECT SINGLE PSMNG
INTO L_PSMNG
FROM AFPO
WHERE AUFNR = I_MSEG-AUFNR.
LOOP AT LT_RESB.
* CLEAR L_ENMNG. "组件总发料数量
SELECT SUM( MENGE )
INTO LT_RESB-ENMNG
FROM ZPP_002
WHERE AUFNR = I_MSEG-AUFNR AND MATNR = LT_RESB-MATNR AND STOKZ = SPACE.
LT_RESB-FLBL = LT_RESB-ENMNG / LT_RESB-BDMNG.
MODIFY LT_RESB.
ENDLOOP.
SORT LT_RESB BY FLBL DESCENDING.
READ TABLE LT_RESB INDEX 1.
SELECT SINGLE WEMNG
INTO L_WEMNG
FROM AFPO
WHERE AUFNR = I_MSEG-AUFNR AND POSNR = 1.
IF ( L_WEMNG + I_MSEG-MENGE ) / L_PSMNG > LT_RESB-FLBL.
L_MENGE = LT_RESB-FLBL * L_PSMNG - L_WEMNG.
MESSAGE '订单' && I_MSEG-AUFNR && '的充电电池发料数为' && LT_RESB-ENMNG && '本次入库只能为' && L_MENGE TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.