效果:
BADI:MB_MIGO_BADI
1、类的属性里添加了可以存储行项目的变量
2、IF_EX_MB_MIGO_BADI~LINE_MODIFY的方法被触发时将行项目数据传入GT_GOITEM中
代码:
IF cs_goitem-pps_aufnr IS NOT INITIAL AND cs_goitem-bwart = '101'. DELETE gt_goitem WHERE zeile = i_line_id. APPEND cs_goitem TO gt_goitem. ENDIF.
3、IF_EX_MB_MIGO_BADI~CHECK_ITEM的方法中循环读取GT_GOITEM中的行项目数据做处理即可
代码:
TYPES: BEGIN OF ty_objnr, objnr TYPE j_objnr, END OF ty_objnr, BEGIN OF ty_lgort, lgort TYPE lgort_d, END OF ty_lgort. DATA: lr_objnr TYPE RANGE OF jest-objnr, lr_lgort TYPE RANGE OF mard-lgort, lrs_objnr LIKE LINE OF lr_objnr, lrs_lgort LIKE LINE OF lr_lgort. DATA: lt_mseg TYPE TABLE OF mseg, lt_objnr TYPE TABLE OF ty_objnr, lt_lgort TYPE TABLE OF ty_lgort, lt_goitem TYPE TABLE OF goitem, ls_goitem TYPE goitem, ls_objnr TYPE ty_objnr, ls_lgort TYPE ty_lgort, ls_mseg TYPE mseg, ls_bapiret TYPE bapiret2. DATA : l_aufpl TYPE co_aufpl, l_wemng_in TYPE co_wemng, l_wemng_out TYPE co_wemng, l_vornr TYPE vornr, l_lmnga TYPE co_wemng, l_rmnga TYPE co_wemng, l_sumga TYPE i, l_sumga_c TYPE string, l_menge TYPE co_wemng. IF sy-tcode = 'MIGO' AND gt_goitem IS NOT INITIAL. "不跑MRP仓库 SELECT lgort INTO TABLE lt_lgort FROM mdlg WHERE berid = '2000_ND'. LOOP AT lt_lgort INTO ls_lgort. lrs_lgort-sign = 'I'. lrs_lgort-option = 'EQ'. lrs_lgort-low = ls_lgort-lgort. APPEND lrs_lgort TO lr_lgort. CLEAR lrs_lgort. ENDLOOP. lt_goitem = gt_goitem. SORT lt_goitem BY pps_aufnr lgort. READ TABLE gt_goitem INTO gs_goitem WITH KEY zeile = i_line_id. IF sy-subrc = 0. SELECT SINGLE aufpl INTO l_aufpl FROM afko WHERE aufnr = gs_goitem-pps_aufnr. SELECT afvc~objnr INTO TABLE lt_objnr FROM afvc INNER JOIN jest ON jest~objnr = afvc~objnr WHERE aufpl = l_aufpl AND stat = 'I0013' AND inact = space. LOOP AT lt_objnr INTO ls_objnr. lrs_objnr-sign = 'I'. lrs_objnr-option = 'EQ'. lrs_objnr-low = ls_objnr-objnr. APPEND lrs_objnr TO lr_objnr. CLEAR lrs_objnr. ENDLOOP. "最后大站 IF lr_objnr[] IS NOT INITIAL. SELECT SINGLE MAX( vornr ) INTO l_vornr FROM afvc WHERE aufpl = l_aufpl AND objnr NOT IN lr_objnr AND steus <> 'ZP10'. ELSE. SELECT SINGLE MAX( vornr ) INTO l_vornr FROM afvc WHERE aufpl = l_aufpl AND steus <> 'ZP10'. ENDIF. IF gs_goitem-lgort IN lr_lgort AND lr_lgort IS NOT INITIAL. "不良品报工 SELECT SUM( rmnga ) INTO l_rmnga FROM afru WHERE aufnr = gs_goitem-pps_aufnr AND rmnga > 0 AND stokz = '' AND stzhl = '00000000' AND meilr = 'X'. "不良品收货 SELECT SUM( menge ) INTO l_wemng_in FROM mseg WHERE bwart = '101' AND aufnr = gs_goitem-pps_aufnr AND lgort IN lr_lgort. SELECT SUM( menge ) INTO l_wemng_out FROM mseg WHERE bwart = '102' AND aufnr = gs_goitem-pps_aufnr AND lgort IN lr_lgort. "可收不良品数量 l_sumga = l_rmnga - l_wemng_in + l_wemng_out. ELSE. "良品报工 SELECT SUM( lmnga ) INTO l_lmnga FROM afru WHERE aufnr = gs_goitem-pps_aufnr AND vornr = l_vornr AND lmnga > 0 AND stokz = '' AND stzhl = '00000000' AND meilr = 'X'. SELECT SUM( menge ) INTO l_wemng_in FROM mseg WHERE bwart = '101' AND aufnr = gs_goitem-pps_aufnr AND lgort NOT IN lr_lgort. SELECT SUM( menge ) INTO l_wemng_out FROM mseg WHERE bwart = '102' AND aufnr = gs_goitem-pps_aufnr AND lgort NOT IN lr_lgort. "可收良品数量 l_sumga = l_lmnga - l_wemng_in + l_wemng_out. ENDIF. l_sumga_c = l_sumga. READ TABLE lt_goitem WITH KEY pps_aufnr = gs_goitem-pps_aufnr lgort = gs_goitem-lgort BINARY SEARCH TRANSPORTING NO FIELDS. IF sy-subrc = 0. LOOP AT lt_goitem INTO ls_goitem FROM sy-tabix. IF ls_goitem-pps_aufnr NE gs_goitem-pps_aufnr OR ls_goitem-lgort NE gs_goitem-lgort. EXIT. ENDIF. l_menge = l_menge + ls_goitem-erfmg. ENDLOOP. ENDIF. IF l_menge > l_sumga. ls_bapiret-type = 'E'. ls_bapiret-id = '00'. ls_bapiret-number = '001'. IF gs_goitem-lgort IN lr_lgort AND lr_lgort IS NOT INITIAL. CONCATENATE '工单' gs_goitem-pps_aufnr '入库数量大于报工数,只能再收' l_sumga_c '个不良品' INTO ls_bapiret-message_v1. ELSE. CONCATENATE '工单' gs_goitem-pps_aufnr '入库数量大于报工数,只能再收' l_sumga_c '个良品' INTO ls_bapiret-message_v1. ENDIF. APPEND ls_bapiret TO et_bapiret2. ENDIF. ENDIF. ENDIF.
4、最后在IF_EX_MB_MIGO_BADI~POST_DOCUMENT中将属性GT_GOITEM清空
代码:
CLEAR gt_goitem.