销售订单增强

文摘   2024-11-27 18:18   北京  

01

前言

     销售订单增强与交货单/采购订单增强方式不太一样,没有公开的BADI可以使用,对销售订单的增强在程序"MV45AFZZ"中处理。

    在"MV45AFZZ"程序中可以做以下增强:

  1. 对销售订单抬头和明细行进行处理,如设置默认值

  2. 可以对定价过程进行增强,设置tkomk/tkomp中字段值

  3. 销售订单保存前校验


02

设置默认值

 1.USEREXIT_MOVE_FIELD_TO_VBAK子例程用来修改销售订单抬头信息,

需创建隐式增强,示例代码如下

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form USEREXIT_MOVE_FIELD_TO_VBAK, End                                                                                                             A*$*$-Start: (1)---------------------------------------------------------------------------------$*$*ENHANCEMENT 2  ZSD_EI_MV45ATZZ.    "active version  "设置成本中心  IF vbak-auart = 'ZCU2'.    vbak-kostl = vbak-kunnr.  ENDIF.
IF us_vbakkom-kostl IS NOT INITIAL. vbak-kostl = us_vbakkom-kostl. ENDIF.ENDENHANCEMENT.*$*$-End: (1)---------------------------------------------------------------------------------$*$*

 2.USEREXIT_MOVE_FIELD_TO_VBAP子例程用来修改销售订单行信息,

需创建隐式增强,示例代码如下

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form USEREXIT_MOVE_FIELD_TO_VBAP, End                                                                                                             A*$*$-Start: (1)---------------------------------------------------------------------------------$*$*ENHANCEMENT 3  ZSD_EI_MV45ATZZ.    "active version  "根据订单类型按照销售组织替换利润中心
DATA: lt_ztsd_auart_conf TYPE TABLE OF ztsd_auart_conf, ls_ztsd_auart_conf TYPE ztsd_auart_conf.
IF vbak-auart = 'ZEC4' OR vbak-auart = 'ZER4' OR vbak-kunnr = 'Z004'. IF vbak-vkorg IS NOT INITIAL. SELECT SINGLE prctr INTO vbap-prctr FROM ztsd_auart_conf WHERE vkorg = vbak-vkorg. xvbap-prctr = vbap-prctr. ENDIF. ENDIF.ENDENHANCEMENT.*$*$-End: (1)---------------------------------------------------------------------------------$*$*

    

03

定价过程增强

1.USEREXIT_PRICING_PREPARE_TKOMK子例程用来修改定价抬头信息,

通常需要先在KOMK中增加自定义字段

然后创建隐式增强,示例代码如下

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(3) Form USEREXIT_PRICING_PREPARE_TKOMK, Start                                                                                                        A*$*$-Start: (3)---------------------------------------------------------------------------------$*$*ENHANCEMENT 1  ZSD_EI_PRICING_TKOMK.    "active version        SELECT SINGLE znsrlb FROM but000 INTO tkomk-znsrlb WHERE partner = vbak-kunnr.ENDENHANCEMENT.*$*$-End:   (3)---------------------------------------------------------------------------------$*$*

2.USEREXIT_PRICING_PREPARE_TKOMP子例程用来修改定价行信息,

通常需要先在KOMP中增加自定义字段

然后创建隐式增强,示例代码如下

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(2) Form USEREXIT_PRICING_PREPARE_TKOMP, End                                                                                                          A*$*$-Start: (2)---------------------------------------------------------------------------------$*$*ENHANCEMENT 1  ZE_INVOICE_PRICE_TKOMP.    "active version SELECT SINGLE zyear zseason zchannel zmat_cate mtart    INTO (tkomp-zyear,tkomp-zseason,tkomp-zchannel,tkomp-zmat_cate,tkomp-mtart )    FROM mara WHERE matnr = tkomp-matnr.ENDENHANCEMENT.*$*$-End:   (2)---------------------------------------------------------------------------------$*$*

 

04

保存前检查

在USEREXIT_SAVE_DOCUMENT_PREPARE子例程中创建隐式增强,示例代码如下

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(6) Form USEREXIT_SAVE_DOCUMENT_PREPARE, Start                                                                                                        A*$*$-Start: (6)---------------------------------------------------------------------------------$*$*ENHANCEMENT 4  ZSD_EI_MV45ATZZ.    "active version DATA: BEGIN OF lt_vbap OCCURS 0,         werks TYPE t001w-werks,         bukrs TYPE t001k-bukrs,                                               S       END OF lt_vbap . DATA: BEGIN OF lt_mara OCCURS 0,         matnr  TYPE mara-matnr,         zbrand TYPE mara-zbrand,       END OF lt_mara . IF xvbap[] IS NOT INITIAL AND vbak-bukrs_vf IS NOT INITIAL.   SELECT b~werks a~bukrs INTO TABLE lt_vbap FROM t001k AS a JOIN t001w AS b ON a~bwkey = b~bwkey     FOR ALL ENTRIES IN xvbap     WHERE b~werks = xvbap-werks.   SORT lt_vbap BY werks.   SELECT matnr zbrand INTO TABLE lt_mara FROM mara      FOR ALL ENTRIES IN xvbap      WHERE matnr = xvbap-matnr.   SORT lt_mara BY matnr.   LOOP AT xvbap ASSIGNING FIELD-SYMBOL(<fs_xvbap>) WHERE updkz <> 'D'. "删除的项目不判断     "业务范围增强     READ TABLE lt_mara WITH KEY matnr = <fs_xvbap>-matnr BINARY SEARCH.     IF sy-subrc = 0.       <fs_xvbap>-gsber = lt_mara-zbrand.     ENDIF.     READ TABLE lt_vbap WITH KEY werks = <fs_xvbap>-werks BINARY SEARCH.     IF sy-subrc = 0.       IF lt_vbap-bukrs <> vbak-bukrs_vf .         READ TABLE xkomv WITH KEY kposn = <fs_xvbap>-posnr kschl = 'ZDS7'.         IF sy-subrc NE 0 OR xkomv-kwert IS INITIAL.           MESSAGE e020(zsd001) WITH <fs_xvbap>-posnr <fs_xvbap>-matnr.         ENDIF.       ENDIF.     ENDIF.   ENDLOOP. ENDIF.ENDENHANCEMENT.*$*$-End:   (6)---------------------------------------------------------------------------------$*$*



05

总结

    就个人而言,比较喜欢基于BADI的增强方式,这种一代增强方式略显落后和麻烦,不知道SAP在后续的版本中会不会做修改呢?


END

 

温馨提示

如果你喜欢本文,请分享给有需要的朋友,想要获得更多信息,请关注我。





 

 

扫码关注我们

以便获取最新更新内容


 

码农干货铺
永远要保持一种无论何时何地都逼着自己更努力更优秀来享受更好生活的学习状态
 最新文章