1.MIGO前台增强:
1.SE18找到增强点:MB_GOODSMOVEMENT
2.找到相应的BADI:右键创建实施
3.找到重写的方法
METHOD if_ex_mb_document_badi~mb_document_before_update.DATA:lv_stat TYPE c,lv_type TYPE bapi_mtype,lv_msg TYPE bapi_msg.DATA:lv_message TYPE string.IF sy-tcode = 'MIGO'.LOOP AT xmseg ASSIGNING FIELD-SYMBOL(<lfs_mseg>).CALL FUNCTION 'ZMM_STATEMENT_SRM'EXPORTINGmblnr = <lfs_mseg>-mblnrgjahr = <lfs_mseg>-gjahrzeile = <lfs_mseg>-zeileIMPORTINGev_stat = lv_statev_type = lv_typeev_msg = lv_msg.IF lv_stat = 1.lv_message = '物料凭证' && <lfs_mseg>-mblnr && '行项目' && <lfs_mseg>-zeile && '已对账不允许原单退货,请通过采购退货订单退货!' .MESSAGE lv_message TYPE 'E'.ELSE.CONTINUE.ENDIF.ENDLOOP.ENDIF.
ENDMETHOD.
2.MIGO 三代增强(BAPI会走这里,上面的那个增强BAPI不会走):
1.SE19:创建BADI实施:
METHOD if_ex_mb_migo_badi~post_document.DATA:lv_message TYPE string.FIELD-SYMBOLS: <lfs_objnr_all> TYPE ANY TABLE.DATA lt_ripw0_t TYPE STANDARD TABLE OF ripw0 WITH NON-UNIQUE SORTED KEY uii COMPONENTS uii.ASSIGN ('(SAPLIPW1)XOBJK_ALL[]') TO <lfs_objnr_all>.IF <lfs_objnr_all> IS ASSIGNED.lt_ripw0_t[] = <lfs_objnr_all>.ENDIF.IF lt_ripw0_t[] IS NOT INITIAL.SELECTe~equnr,e~matnr,e~lbbsaFROM v_equi_eqbs_sml AS eFOR ALL ENTRIES IN @lt_ripw0_tWHERE e~equnr = @lt_ripw0_t-equnrINTO TABLE @DATA(lt_ser).LOOP AT it_mseg INTO DATA(is_mseg) WHERE bwart = '344'.READ TABLE lt_ser INTO DATA(ls_ser) WITH KEY matnr = is_mseg-matnr lbbsa = '07'.IF sy-subrc = 0.lv_message = '行项目' && is_mseg-zeile&& '物料' && ls_ser-matnr&& '序列号' && ls_ser-equnr && '不能重复冻结库存' .MESSAGE lv_message TYPE 'E'.ENDIF.ENDLOOP.ENDIF.DATA: wa_zzsmseg TYPE ztmseg,lt_zzsmseg TYPE TABLE OF ztmseg,wa_item TYPE zzsmseg_s,wa_mseg TYPE mseg.IF it_item[] IS NOT INITIAL.LOOP AT it_item INTO wa_item.READ TABLE it_mseg INTO wa_msegWITH KEY line_id = wa_item-line_id.IF sy-subrc EQ 0.wa_zzsmseg-mblnr = wa_mseg-mblnr.wa_zzsmseg-mjahr = wa_mseg-mjahr.wa_zzsmseg-zeile = wa_mseg-zeile.wa_zzsmseg-zshdh = wa_item-zshdh.wa_zzsmseg-zshdh_item = wa_item-zshdh_item.APPEND wa_zzsmseg TO lt_zzsmseg.ENDIF.ENDLOOP.CALL FUNCTION 'ZFMMM_UPDATE_DATA' IN UPDATE TASKTABLESit_item = lt_zzsmseg.ENDIF.ENDMETHOD.
3.ITEM检查增强:这里增强没有前台页面行项目数据 需要在自定义类中手动添加,初始化,行更新删除时都需要更新此全局表
METHOD if_ex_mb_migo_badi~init.APPEND gf_class_id TO ct_init.ENDMETHOD.
METHOD if_ex_mb_migo_badi~line_modify.DATA: wa_item_new TYPE zzsmseg_s,wa_item_old TYPE zzsmseg_s,wa_zzsmseg TYPE ztmseg,l_subrc TYPE sy-subrc.READ TABLE it_item INTO wa_item_old WITH KEY line_id = i_line_id.l_subrc = sy-subrc.IF sy-subrc <> 0.IF cs_goitem-mblnr IS NOT INITIALAND cs_goitem-mjahr IS NOT INITIALAND cs_goitem-zeile IS NOT INITIAL.SELECT SINGLE * FROM ztmsegINTO wa_zzsmsegWHERE mblnr = cs_goitem-mblnrAND mjahr = cs_goitem-mjahrAND zeile = cs_goitem-zeile.IF wa_zzsmseg IS NOT INITIAL.MOVE-CORRESPONDING wa_zzsmseg TO wa_item_new.ENDIF.ENDIF.wa_item_new-line_id = i_line_id.INSERT wa_item_new INTO TABLE it_item.ELSE.CHECK g_line_id = i_line_id.CALL FUNCTION 'ZFMMM_GET_ITEM_DATA'IMPORTINGe_output = wa_item_new.MODIFY it_item FROM wa_item_new TRANSPORTING zshdh zshdh_item WHERE line_id = i_line_id.ENDIF.DELETE gt_item WHERE ebeln = cs_goitem-ebeln AND ebelp = cs_goitem-ebelp .APPEND cs_goitem TO gt_item .ENDMETHOD.
METHOD if_ex_mb_migo_badi~line_delete.DELETE it_item WHERE line_id = i_line_id.ENDMETHOD.
METHOD if_ex_mb_migo_badi~pbo_detail.IF gf_class_id = i_class_id.DATA: wa_item TYPE zzsmseg_s.CHECK i_line_id IS NOT INITIAL.e_cprog = 'SAPLZFGMM_08'(001). "'SAPL + 'FG Name'e_dynnr = '9010'.e_heading = 'SRM客制化页签'.g_line_id = i_line_id.READ TABLE it_item INTO wa_item WITH KEY line_id = i_line_id.CALL FUNCTION 'ZFMMM_SET_ITEM_DATA'EXPORTINGi_input = wa_item.ENDIF.ENDMETHOD.
METHOD if_ex_mb_migo_badi~pai_detail.DATA: wa_item_new TYPE zzsmseg_s,wa_item_old TYPE zzsmseg_s.CHECK i_line_id <> 0.CALL FUNCTION 'ZFMMM_GET_ITEM_DATA'IMPORTINGe_output = wa_item_new.READ TABLE it_item INTO wa_item_old WITH KEY line_id = i_line_id.IF wa_item_new <> wa_item_old.e_force_change = 'X'.ENDIF.ENDMETHOD.
METHOD if_ex_mb_migo_badi~reset.CLEAR:it_item,g_no_input,g_cancel,g_line_id.CLEAR gt_item .CLEAR gs_gohead .ENDMETHOD.
METHOD if_ex_mb_migo_badi~post_document.DATA:lv_message TYPE string.FIELD-SYMBOLS: <lfs_objnr_all> TYPE ANY TABLE.DATA lt_ripw0_t TYPE STANDARD TABLE OF ripw0 WITH NON-UNIQUE SORTED KEY uii COMPONENTS uii.ASSIGN ('(SAPLIPW1)XOBJK_ALL[]') TO <lfs_objnr_all>.IF <lfs_objnr_all> IS ASSIGNED.lt_ripw0_t[] = <lfs_objnr_all>.ENDIF.IF lt_ripw0_t[] IS NOT INITIAL.SELECTe~equnr,e~matnr,e~lbbsaFROM v_equi_eqbs_sml AS eFOR ALL ENTRIES IN @lt_ripw0_tWHERE e~equnr = @lt_ripw0_t-equnrINTO TABLE @DATA(lt_ser).LOOP AT it_mseg INTO DATA(is_mseg) WHERE bwart = '344'.READ TABLE lt_ser INTO DATA(ls_ser) WITH KEY matnr = is_mseg-matnr lbbsa = '07'.IF sy-subrc = 0.lv_message = '行项目' && is_mseg-zeile&& '物料' && ls_ser-matnr&& '序列号' && ls_ser-equnr && '不能重复冻结库存' .MESSAGE lv_message TYPE 'E'.ENDIF.ENDLOOP.ENDIF.DATA: wa_zzsmseg TYPE ztmseg,lt_zzsmseg TYPE TABLE OF ztmseg,wa_item TYPE zzsmseg_s,wa_mseg TYPE mseg.IF it_item[] IS NOT INITIAL.LOOP AT it_item INTO wa_item.READ TABLE it_mseg INTO wa_msegWITH KEY line_id = wa_item-line_id.IF sy-subrc EQ 0.wa_zzsmseg-mblnr = wa_mseg-mblnr.wa_zzsmseg-mjahr = wa_mseg-mjahr.wa_zzsmseg-zeile = wa_mseg-zeile.wa_zzsmseg-zshdh = wa_item-zshdh.wa_zzsmseg-zshdh_item = wa_item-zshdh_item.APPEND wa_zzsmseg TO lt_zzsmseg.ENDIF.ENDLOOP.CALL FUNCTION 'ZFMMM_UPDATE_DATA' IN UPDATE TASKTABLESit_item = lt_zzsmseg.ENDIF.ENDMETHOD.
METHOD if_ex_mb_migo_badi~check_item.DATA: gs_item_old TYPE goitem,wa_item_old TYPE zzsmseg_s.FIELD-SYMBOLS: <fs_kernel_class> TYPE any.DATA: lv_ref_kernel TYPE REF TO object.FIELD-SYMBOLS:<l_action> TYPE goaction,<l_refdoc> TYPE refdoc.ASSIGN:('(SAPLMIGO)GODYNPRO-REFDOC') TO <l_refdoc>,
('(SAPLMIGO)GODYNPRO-ACTION') TO <l_action>.ASSIGN ('(SAPLMIGO)LCL_MIGO_GLOBALS=>KERNEL') TO <fs_kernel_class>.lv_ref_kernel ?= <fs_kernel_class>.IF <l_action> IS ASSIGNED AND <l_refdoc> IS ASSIGNED.IF <l_action> EQ 'A01' AND <l_refdoc> EQ 'R01'.LOOP AT gt_item INTO gs_item_old WHERE take_it = 'X' AND zeile = i_line_id.SELECT COUNT(*) FROM ekpo WHERE ebeln = gs_item_old-ebeln AND zyxt = 'SRM'.IF sy-subrc = 0.READ TABLE it_item INTO wa_item_old WITH KEY line_id = gs_item_old-zeile.IF wa_item_old-zshdh IS INITIAL OR wa_item_old-zshdh_item IS INITIAL.MESSAGE i_line_id && 'SRM送货单号,SRM送货单号和行项目不能为空' TYPE 'E'.ENDIF.ENDIF.ENDLOOP.ENDIF .ENDIF .ENDMETHOD.
METHOD if_ex_mb_migo_badi~mode_set.
*------------------------------------------------*" i_action:" A01 = Goods receipt" A02 = Return delivery" A03 = Cancellation" A04 = Display" A05 = Release GR bl.st." A06 = Subsequent deliv." A07 = Goods issue"" i_refdoc:" R01 = Purchase order" R02 = Material document" R03 = Delivery note" R04 = Inbound delivery" R05 = Outbound delivery" R06 = Transport" R07 = Transport ID code" R08 = Order" R09 = Reservation" R10 = Other GR
*------------------------------------------------*IF i_action = 'A03' OR i_action = 'A04' .g_no_input = abap_true.ENDIF.IF i_action = 'A03'.g_cancel = abap_true.ENDIF.CALL FUNCTION 'ZFMMM_SET_GOACTION'EXPORTINGi_goaction = i_action.ENDMETHOD.
METHOD if_ex_mb_migo_badi~pai_header.gs_gohead = is_gohead.ENDMETHOD.
METHOD if_ex_mb_migo_badi~check_header.DATA : lv_answer TYPE c.DATA :lv_name(50) TYPE c.DATA :lv_mblnr TYPE mblnr.FIELD-SYMBOLS: <fs_kernel_class> TYPE any.DATA: lv_ref_kernel TYPE REF TO object.FIELD-SYMBOLS:<l_action> TYPE goaction,<l_refdoc> TYPE refdoc.DATA:lv_count TYPE i.DATA:ls_bapiret TYPE bapiret2.DATA: gs_item_old TYPE goitem.ASSIGN:('(SAPLMIGO)GODYNPRO-REFDOC') TO <l_refdoc>,('(SAPLMIGO)GODYNPRO-ACTION') TO <l_action>.ASSIGN ('(SAPLMIGO)LCL_MIGO_GLOBALS=>KERNEL') TO <fs_kernel_class>.lv_ref_kernel ?= <fs_kernel_class>.IF <l_action> IS ASSIGNED AND <l_refdoc> IS ASSIGNED.IF <l_action> EQ 'A01' AND <l_refdoc> EQ 'R01'.LOOP AT gt_item INTO gs_item_old WHERE take_it = 'X'.SELECT COUNT(*) FROM ekpo WHERE ebeln = gs_item_old-ebeln AND zyxt = 'SRM'.IF sy-subrc = 0.IF gs_gohead-bktxt IS INITIAL.MESSAGE '抬头文本不能为空' TYPE 'E'.ELSE.SELECT SINGLE mblnr INTO lv_mblnr FROM mkpf WHERE bktxt = gs_gohead-bktxt .IF lv_mblnr IS NOT INITIAL.lv_name = '抬头文本重复凭证号:' && lv_mblnr && '可能存在收货,请确认是否过账!'.CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'EXPORTING
* DEFAULTOPTION = 'Y'textline1 = lv_name
* TEXTLINE2 = '否'titel = '是否继续'
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'IMPORTINGanswer = lv_answer.IF sy-subrc = 0.IF lv_answer = 'N'.MESSAGE '操作被终止' TYPE 'E'.ELSEIF lv_answer = 'A'..MESSAGE '操作取消' TYPE 'E'.ENDIF.ENDIF.ENDIF.ENDIF.ENDIF.ENDLOOP.ENDIF.ENDIF.ENDMETHOD.
********函数组:
FUNCTION zfmmm_get_item_data.
*"----------------------------------------------------------------------
*"*"本地接口:
*" EXPORTING
*" REFERENCE(E_OUTPUT) TYPE ZZSMSEG_S
*"----------------------------------------------------------------------MOVE-CORRESPONDING gs_zzsmseg TO e_output.ENDFUNCTION.FUNCTION zfmmm_set_goaction.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(I_GOACTION) TYPE GOACTION
*"----------------------------------------------------------------------g_goaction = i_goaction.ENDFUNCTION.FUNCTION zfmmm_set_item_data.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(I_INPUT) TYPE ZZSMSEG_S
*"----------------------------------------------------------------------MOVE-CORRESPONDING i_input TO gs_zzsmseg.ENDFUNCTION.FUNCTION zfmmm_update_data.
*"----------------------------------------------------------------------
*"*"更新函数模块:
*"
*"*"本地接口:
*" TABLES
*" IT_ITEM STRUCTURE ZTMSEG
*"----------------------------------------------------------------------IF it_item[] IS NOT INITIAL.MODIFY ztmseg FROM TABLE it_item[].ENDIF.ENDFUNCTION.
LZFGMM_08TOP
* INCLUDE LZFGMM_08D... " Local class definitionDATA:gs_zzsmseg TYPE zzsmseg_s.
DATA:g_goaction TYPE goaction.
LINE_ID 类型 MIGO_GLOBAL_COUNTER NUMC 6 0 0 一行的唯一编号
.INCLUDE 类型 ZTMSEG 0 0 0 MIGO行项目增强字段
MANDT 类型 MANDT CLNT 3 0 0 客户端
MBLNR 类型 MBLNR CHAR 10 0 0 物料凭证编号
MJAHR 类型 MJAHR NUMC 4 0 0 物料凭证的年份
ZEILE 类型 MBLPO NUMC 4 0 0 物料凭证中的项目
.INCLUDE 类型 ZSMSEG 0 0 0 MIGO增强字段
ZSHDH 类型 ZDEZSHDH CHAR 50 0 0 SRM送货单号
ZSHDH_ITEM 类型 ZDEZSHDH_ITEM NUMC 10 0 0 SRM送货单号行项目
EBELN 类型 EBELN CHAR 10 0 0 采购凭证编号
*----------------------------------------------------------------------*
***INCLUDE LZFGMM_08O01.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9010 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_9010 OUTPUT.LOOP AT SCREEN.IF screen-group1 = 'G1' AND g_goaction = 'A04'.screen-input = 0.MODIFY SCREEN.ENDIF.ENDLOOP.
ENDMODULE.
拓展预留字段:
se18->MB_GOODSMOVEMENT
METHOD if_ex_mb_bapi_goodsmvt_create~extensionin_to_matdoc.DATA:c_lenstruc TYPE i VALUE 30,wa_bapi_mb_header TYPE bapi_te_xmkpf,wa_bapi_mb_item TYPE bapi_te_xmseg,wa_extension_in TYPE bapiparex.FIELD-SYMBOLS:<fs_imseg> TYPE imseg.CHECK NOT extension_in[] IS INITIAL.* Analyze IMSEG for document structure and assign LINE_IDs if necessaryCALL METHOD cl_mmim_line_id_manager=>analyze_mb_createCHANGINGct_imseg = ct_imseg[]EXCEPTIONSduplicate_line_id = 1OTHERS = 2.LOOP AT extension_in INTO wa_extension_in.CASE wa_extension_in-structure.
* extension of MKPFWHEN 'BAPI_TE_XMKPF'.MOVE wa_extension_in+c_lenstruc TO wa_bapi_mb_header.MOVE-CORRESPONDING wa_bapi_mb_header TO cs_imkpf.
* extension of MSEGWHEN 'BAPI_TE_XMSEG'.MOVE wa_extension_in+c_lenstruc TO wa_bapi_mb_item.READ TABLE ct_imsegWITH KEY line_id = wa_bapi_mb_item-matdoc_itmASSIGNING <fs_imseg>.IF sy-subrc EQ 0.MOVE-CORRESPONDING wa_bapi_mb_item TO <fs_imseg>.ENDIF.ENDCASE.ENDLOOP.ENDMETHOD.