本文主要是介绍MIGO屏幕增强,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
增强步骤
1.为主表添加附加结构
由于S4版本物料凭证表来源于MATDOC,因此也需要在MATDOC里增加附加结构。
(抬头NSDM_S_HEADER,行项目NSDM_S_ITEM)
2.创建DDL视图用于扩展标准CDS视图(S4版本需要)
可参考NOTE:2686694
打开ECLIPSE ADT工具,在开发包中右键创建DDL视图
创建CDS视图并激活
@AbapCatalog.sqlViewAppendName:'ZMMS_MKPF_V'
@EndUserText.label:'APPEND MKPF'
@AccessControl.authorizationCheck:#NOT_REQUIRED
EXTEND VIEW NSDM_E_MKPF with ZMMS_MKPF_E
{ZZWMSUSER,ZZWMSID
}
3.新建函数组
创建抬头数据的传入传出函数
FUNCTION zmmfu_migo_get_data.
*"----------------------------------------------------------------------
*"*"本地接口:
*" EXPORTING
*" REFERENCE(OS_OUTPUT) TYPE ZMMS_MKPF
*"----------------------------------------------------------------------MOVE-CORRESPONDING zmms_mkpf TO os_output.ENDFUNCTION.
FUNCTION zmmfu_migo_set_data.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IS_INPUT) TYPE ZMMS_MKPF
*"----------------------------------------------------------------------MOVE-CORRESPONDING is_input TO zmms_mkpf.ENDFUNCTION.
创建获取操作码的函数
FUNCTION zmmfu_migo_set_goaction.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(I_GOACTION) TYPE GOACTION
*" REFERENCE(I_REFDOC) TYPE REFDOC
*"----------------------------------------------------------------------gv_goaction = i_goaction.gv_refdoc = i_refdoc.ENDFUNCTION.
绘制子屏幕
TOP文件设置全局变量
FUNCTION-POOL zmmfg001. "MESSAGE-ID ..* INCLUDE LZMMFG001D... " Local class definitionTABLES:zmms_mkpf.DATA:gv_goaction TYPE goaction,gv_refdoc TYPE refdoc,gv_action TYPE action.
PBO
*----------------------------------------------------------------------*
***INCLUDE LZMMFG001O01.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_9001 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.LOOP AT SCREEN.IF screen-name+0(12) = 'ZMMS_MKPF-ZZ'.CASE gv_goaction.WHEN 'A04'.screen-input = '0'.WHEN OTHERS.ENDCASE.MODIFY SCREEN.ENDIF.ENDLOOP.ENDMODULE.
行项目需要实现PBO_DETAIL、PAI_DETAIL、LINE_MODIFY、LINE_DELETE方法
4.实施BADI
实施BADI: MB_MIGO_BADI
BADI属性中增加以下变量(保存自定义表使用,标准表可忽略)
实现抬头的PBO方法
METHOD if_ex_mb_migo_badi~pbo_header.CHECK gv_class_id = i_class_id AND i_class_id IS NOT INITIAL.CALL FUNCTION 'ZMMFU_MIGO_SET_DATA'EXPORTINGis_input = is_mkpf_badi.e_cprog = 'SAPLZMMFG001'.e_dynnr = '9001'.e_heading = 'WMS信息'.ENDMETHOD.
实现抬头的PAI方法
METHOD if_ex_mb_migo_badi~pai_header.DATA:ls_mkpf_badi TYPE zmms_mkpf.CALL FUNCTION 'ZMMFU_MIGO_GET_DATA'IMPORTINGos_output = ls_mkpf_badi.MOVE-CORRESPONDING ls_mkpf_badi TO is_mkpf_badi.ENDMETHOD.
实现抬头数据从数据库中读取的方法
METHOD if_ex_mb_migo_badi~status_and_header.IF is_gohead-mblnr IS NOT INITIAL AND is_gohead-mjahr IS NOT INITIAL AND is_mkpf_badi IS INITIAL.SELECT SINGLE *FROM mkpfINTO @DATA(ls_mkpf)WHERE mblnr = @is_gohead-mblnrAND mjahr = @is_gohead-mjahr.MOVE-CORRESPONDING ls_mkpf TO is_mkpf_badi.CLEAR:ls_mkpf.ENDIF.ENDMETHOD.
实现重置方法
METHOD if_ex_mb_migo_badi~reset.CLEAR:is_mkpf_badi.ENDMETHOD.
实现操作模式赋值方法
METHOD if_ex_mb_migo_badi~mode_set.* ACTION and REFDOC will discribe the mode of transaction MIGO.
* ----------------------------------------------------------------------
* 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
*-----------------------------------------------------------------------CALL FUNCTION 'ZMMFU_MIGO_SET_GOACTION'EXPORTINGi_goaction = i_actioni_refdoc = i_refdoc.ENDMETHOD.
保存赋值有两种方式,如果使用的是自定义表保存,则需要通过更新函数实现POST_DOCUMENT方法即可
METHOD if_ex_mb_migo_badi~post_document.CALL FUNCTION 'ZMIGO_BADI_UPDATE_DATA' IN UPDATE TASKEXPORTINGi_zmkpf = is_mkpf_badi.ENDMETHOD.
而如果是在标准表中增加字段,则需要实现另一个保存BADI:MB_DOCUMENT_BADI.
由于BADI中的参数是传入参数,无法修改,因此需要找到BADI的调用点,通过更新内存变量实现
METHOD if_ex_mb_document_badi~mb_document_before_update.DATA:lv_field(40) TYPE c,ls_mkpf TYPE zmms_mkpf.FIELD-SYMBOLS:<lfs_xmkpf> TYPE ANY TABLE,<lfs_mkpf> TYPE mkpf."需要限制前台事务码,否则BAPI传值会被清空IF sy-tcode = 'MIGO'.lv_field = '(SAPMM07M)XMKPF[]'.ASSIGN (lv_field) TO <lfs_xmkpf>.CALL FUNCTION 'ZMMFU_MIGO_GET_DATA'IMPORTINGos_output = ls_mkpf.LOOP AT <lfs_xmkpf> ASSIGNING <lfs_mkpf>.MOVE-CORRESPONDING ls_mkpf TO <lfs_mkpf>.ENDLOOP.ENDIF.ENDMETHOD.
5.BAPI增强
注:使用自定义表的方式不需要此步骤
如果需要在BAPI中传值增强字段,也就是在EXTENSIONIN结构中赋值,需要实施对象增强点:MB_GOODSMOVEMENT中的BADI:MB_BAPI_GOODSMVT_CREATE
SE19中新建实施
由于是复制的示例类,可以看到方法中已经实现的代码,可根据实际情况进行调整
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.
在BAPI增强结构中添加附加结构
BAPI调用即可
LOOP AT it_input ASSIGNING <lfs_input>."抬头ls_goodsmvt_header-pstng_date = sy-datum.ls_goodsmvt_header-doc_date = sy-datum.ls_goodsmvt_header-pr_uname = sy-uname.lv_goodsmvt_code = '02'."行项目ls_goodsmvt_item-stge_loc = <lfs_input>-lgort. "存储地点ls_goodsmvt_item-batch = <lfs_input>-charg. "批次ls_goodsmvt_item-move_type = <lfs_input>-bwart. "移动类型ls_goodsmvt_item-orderid = <lfs_input>-aufnr. "生产订单ls_goodsmvt_item-quantity = <lfs_input>-psmng. "数量APPEND ls_goodsmvt_item TO lt_goodsmvt_item.CLEAR:ls_goodsmvt_item.AT LAST."增强ls_extensionin-structure = 'BAPI_TE_XMKPF'.ls_bapi_te_xmkpf-zzwmsuser = <lfs_input>-zzwmsuser.ls_bapi_te_xmkpf-zzwmsid = <lfs_input>-zzwmsid.CALL METHOD cl_abap_container_utilities=>fill_container_cEXPORTINGim_value = ls_bapi_te_xmkpfIMPORTINGex_container = ls_extensionin-valuepart1. "增强结构数据APPEND ls_extensionin TO lt_extensionin.CLEAR:ls_extensionin,ls_bapi_te_xmkpf."创建物料凭证CALL FUNCTION 'BAPI_GOODSMVT_CREATE'EXPORTINGgoodsmvt_header = ls_goodsmvt_headergoodsmvt_code = lv_goodsmvt_code
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
* GOODSMVT_PRINT_CTRL =IMPORTING
* GOODSMVT_HEADRET =materialdocument = lv_materialdocumentmatdocumentyear = lv_matdocumentyearTABLESgoodsmvt_item = lt_goodsmvt_item
* GOODSMVT_SERIALNUMBER =return = lt_return
* GOODSMVT_SERV_PART_DATA =extensionin = lt_extensionin
* GOODSMVT_ITEM_CWM =.IF line_exists( lt_return[ type = 'E'] ) OR line_exists( lt_return[ type = 'A'] ).CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.LOOP AT lt_return INTO ls_return WHERE type CA 'EA'.IF lv_message IS INITIAL.lv_message = ls_return-message.ELSE.lv_message = lv_message && '/' && ls_return-message.ENDIF.CLEAR:ls_return.ENDLOOP.es_ret-code = 'E'.es_ret-msg = lv_message.ELSE.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.es_ret-code = 'S'.es_ret-msg = '创建成功'.es_ret-key1 = lv_materialdocument.es_ret-key2 = lv_matdocumentyear.ENDIF.CLEAR:lv_materialdocument,lv_matdocumentyear,lv_message,ls_goodsmvt_header,lv_goodsmvt_code.REFRESH:lt_goodsmvt_item,lt_return,lt_extensionin.ENDAT.ENDLOOP.
增强效果
这篇关于MIGO屏幕增强的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!