昨天一个需求,需要使用BAPI_GOODSMVT_CREATE 做采购订单收货时,按必要条件写入指定的收货人,开始里直接在BAPI时,
1 |
bapi header ls_header-pr_uname = "指定用户" |
但生成的物料凭证,创建人还是操作用户,不是代码中指定的,
1.解决方法
1.事务码SE18,选择Enhancement Spot,打开MB_GOODSMOVEMENT,
2.选择MB_BAPI_GOODSMVT_CREATE->实施,右键,点击”创建BADI实施”,结果如图。
3.双击新生成的实施“ZMB_BAPI_GOODSMVT_CREATE”,打开实施方法IF_EX_MB_BAPI_GOODSMVT_CREATE~EXTENSIONIN_TO_MATDOC,编辑代码如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
method IF_EX_MB_BAPI_GOODSMVT_CREATE~EXTENSIONIN_TO_MATDOC. DATA: LT_EXTENSION type standard table of BAPIPAREX, LS_EXTENSION type BAPIPAREX, LS_ZEXTEN TYPE ZBAPI_TE_XMKPF. LOOP AT EXTENSION_IN INTO LS_EXTENSION WHERE STRUCTURE = 'ZBAPI_TE_XMKPF'. LS_ZEXTEN = LS_EXTENSION-VALUEPART1. IF LS_ZEXTEN-USNAM IS NOT INITIAL. CS_IMKPF-USNAM = LS_ZEXTEN-USNAM. ENDIF. EXIT. ENDLOOP. endmethod. |
4,在上面的代码中使用了结构,ZBAPI_TE_XMKPF,此结构是从标准结构BAPI_TE_XMKPF复制来的,并增加字段USNAM,结构如下
5.现在,只要在BAPI_GOODSMVT_CREATE中把物料凭证创建人写到增强结构中,就可以了,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
DATA: LT_EXTENSION type standard table of BAPIPAREX, LS_EXTENSION type BAPIPAREX. DATA: WA_ZEXTEN LIKE ZBAPI_TE_XMKPF. WA_ZEXTEN-USNAM = LS_ZSDT0226_CONF2-ZCREN. "收货人 LS_EXTENSION-VALUEPART1 = WA_ZEXTEN. LS_EXTENSION-STRUCTURE = 'ZBAPI_TE_XMKPF'. "CONDENSE lt_extension-valuepart1 . APPEND LS_EXTENSION TO LT_EXTENSION. ....... CALL FUNCTION 'BAPI_GOODSMVT_CREATE' EXPORTING GOODSMVT_HEADER = L_HEADER GOODSMVT_CODE = L_CODE IMPORTING GOODSMVT_HEADRET = LS_GOODSMVT TABLES GOODSMVT_ITEM = LT_ITEM * GOODSMVT_SERIALNUMBER = RETURN = LT_RETURN * GOODSMVT_SERV_PART_DATA = EXTENSIONIN = LT_EXTENSION . |