如何使用BADI修改PO (processing to ME21N )

本文介绍如何使用SAP BADI实现采购订单创建时的后处理功能,具体为从销售订单中继承装运点到采购订单上。通过实施特定BADI并调用后台任务中的BAPI来更新采购订单。

Requirement:

Populate EVERS [ Shipping Point ] at the time of purchase order ceration. Shipping point should be derivated from the shipping point on sales order [ if PO created from in reference to a sales order ].


Processing:

This is an example to show - how to achieve post-processing [ follow-on processing ] functionality using BADIs [ Business Add-inn ] or user-exits.

  • Find the relevant BADI using transaction SE18. In this case BADI ME_PURCHDOC_POSTED is used.
  • Further, implement the BADI using transaction SE19.
  • In Attributes section of BADI, define a STATIC attribute as PO_NUMBER. Static means the attribute will keep its value between the calls. This will be checked to ensure that same PO will not be processed twice. Also these kind of user-exits and BADIs might get called recursively and get caught into an infinite loop, if not coded properly. Rememeber that this BADI is at the time of PO save and then you are again trying to change & save the Purchase Order from within the BADI.
  • BAPI to change Purchase Order 'BAPI_PO_CHANGE' will be called IN BACKGROUND TASK to ensure that it will be called when COMMIT WORK is encountered.
  • Don't forget to activate the BADI implementation in SE19.


method IF_EX_ME_PURCHDOC_POSTED~POSTED .

DATA: wa_ekpo like line of IM_EKPO,
      lt_po_item type standard table of BAPIMEPOITEM,
      lt_po_itemx type standard table of BAPIMEPOITEMX,
      wa_po_item type BAPIMEPOITEM,
      wa_po_itemx type BAPIMEPOITEMX,
      lt_return type standard table of BAPIRET2.


*data: ls_ebeln type BAPIMEPOHEADER-PO_NUMBER.

check im_ekko-ebeln ne PO_NUMBER.

PO_NUMBER = im_ekko-ebeln.

LOOP AT IM_EKPO into wa_ekpo.

  wa_po_item-PO_ITEM = wa_ekpo-ebelp.
* EVERS to be derived
  wa_po_item-SHIPPING = 'C'.
  APPEND wa_po_item to lt_po_item .

  wa_po_itemx-PO_ITEM = wa_ekpo-ebelp.
  wa_po_itemx-SHIPPING = 'X'.
  APPEND wa_po_itemx to lt_po_itemx.
ENDLOOP.

 CALL FUNCTION 'BAPI_PO_CHANGE' IN BACKGROUND TASK
   EXPORTING
     purchaseorder                = PO_NUMBER
*    POHEADER                     =
*    POHEADERX                    =
*    POADDRVENDOR                 =
*    TESTRUN                      =
*    MEMORY_UNCOMPLETE            =
*    MEMORY_COMPLETE              =
*    POEXPIMPHEADER               =
*    POEXPIMPHEADERX              =
*    VERSIONS                     =
    NO_MESSAGING                 = 'X'
    NO_MESSAGE_REQ               = 'X'
    NO_AUTHORITY                 = 'X'
    NO_PRICE_FROM_PO             = 'X'
*  IMPORTING
*    EXPHEADER                    =
*    EXPPOEXPIMPHEADER            =
   TABLES
     RETURN                       = lt_return
     POITEM                       = lt_po_item
     POITEMX                      = lt_po_itemx
*    POADDRDELIVERY               =
*    POSCHEDULE                   =
*    POSCHEDULEX                  =
*    POACCOUNT                    =
*    POACCOUNTPROFITSEGMENT       =
*    POACCOUNTX                   =
*    POCONDHEADER                 =
*    POCONDHEADERX                =
*    POCOND                       =
*    POCONDX                      =
*    POLIMITS                     =
*    POCONTRACTLIMITS             =
*    POSERVICES                   =
*    POSRVACCESSVALUES            =
*    POSERVICESTEXT               =
*    EXTENSIONIN                  =
*    EXTENSIONOUT                 =
*    POEXPIMPITEM                 =
*    POEXPIMPITEMX                =
*    POTEXTHEADER                 =
*    POTEXTITEM                   =
*    ALLVERSIONS                  =
*    POPARTNER                    =
           .

endmethod.
来源:http://www.geocities.com/rmtiwari/main.html?http://www.geocities.com/rmtiwari/Resources/MySolutions/Dev/ABAP_nsFAQ.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值