MM--物料重新过账的代码摘抄

*&---------------------------------------------------------------------*
*& Report  ZZWASTOR                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT ZZWASTOR .

*********************************************************************
* If you do not know the material document of the goods issue any   *
* more you can use transaction SE16.                                *
* - Type in table name MKPF                                         *
* - Type in the delivery note number in field XBLNR (always with    *
*   leading zeroes)                                                 *
* - Execute                                                         *
* - The Material document number of the goods issue for the deleted *
*   delivery will be shown.                                         *
*                                                                   *
*                                                                   *
*                                                                   *
* LF_BUDAT  =>  Posting date for the reversal                       *
* LF_MJAHR  =>  Posting year of the material document to reverse    *
* LF_MBLNR  =>  Goods issue document (with leading zeroes)          *
* LF_VBELN  =>  Delivery note number (with leading zeroes)          *
* LF_TEST   =>  When 'X' it is test mode only, otherwise GI will be *
*               cancelled                                           *
*********************************************************************

TABLES: MKPF, IMKPF, EMKPF, LIKP.

DATA:   BEGIN OF IMSEG OCCURS 0.
        INCLUDE STRUCTURE IMSEG.
DATA:   END OF IMSEG.

DATA:   BEGIN OF EMSEG OCCURS 0.
        INCLUDE STRUCTURE EMSEG.
DATA:   END OF EMSEG.


PARAMETERS: LF_BUDAT  LIKE SY-DATLO DEFAULT SY-DATLO OBLIGATORY,
            LF_MJAHR  LIKE MKPF-MJAHR DEFAULT SY-DATLO(4) OBLIGATORY,
            LF_MBLNR  LIKE MKPF-MBLNR OBLIGATORY,
            LF_VBELN  LIKE LIKP-VBELN OBLIGATORY,
            LF_TEST   TYPE C DEFAULT 'X'.

DATA:   MBLPO LIKE MSEG-ZEILE.

SELECT SINGLE * FROM MKPF WHERE MBLNR = LF_MBLNR
                          AND   MJAHR = LF_MJAHR
                          AND   XBLNR = LF_VBELN.

IF SY-SUBRC IS INITIAL.
  CALL FUNCTION 'MB_CANCEL_GOODS_MOVEMENT'
    EXPORTING
      BUDAT     = LF_BUDAT
      MBLNR     = LF_MBLNR
      MBLPO     = MBLPO
      MJAHR     = LF_MJAHR
      TCODE     = 'VL09'
      CALLED_BY = 'VL09'
    IMPORTING
      EMKPF     = EMKPF
    TABLES
      EMSEG     = EMSEG
      IMSEG     = IMSEG
    EXCEPTIONS
      OTHERS    = 1.

*... No error found, then it will be posted
  IF EMKPF-SUBRC EQ 1.
    IF LF_TEST IS INITIAL.
      CALL FUNCTION 'MB_POST_GOODS_MOVEMENT'
        EXPORTING
          XBLNR_SD = LF_VBELN
        IMPORTING
          EMKPF    = EMKPF
        EXCEPTIONS
          OTHERS   = 0.

      COMMIT WORK.
    WRITE: / 'Goods movement was cancelled successfully with document:',
            EMKPF-MBLNR.
    ELSE.
      WRITE: / 'Testmode: Goods movement could be cancelled !'.
    ENDIF.
  ELSE.
*... otherwise write an error-log
    LOOP AT EMSEG.
      WRITE: /
                EMSEG-MSGID,
                EMSEG-MSGNO,
                EMSEG-MSGTY,
                EMSEG-MSGV1,
               EMSEG-MSGV2,
               EMSEG-MSGV3,
               EMSEG-MSGV4.
    ENDLOOP.
    WRITE: / EMKPF-MSGID,
             EMKPF-MSGNO,
             EMKPF-MSGTY,
             EMKPF-MSGV1,
             EMKPF-MSGV2,
             EMKPF-MSGV3,
             EMKPF-MSGV4.

  ENDIF.
ELSE.
  WRITE: / 'Material document to reverse does not exsist'.
ENDIF.
                                              .
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是 SAP 采购订单过账的 ABAP 代码实现: 1. 首先需要定义一些变量,并且获取采购订单的相关信息。 ``` DATA: ls_header TYPE bapi_po_header, lt_poitem TYPE TABLE OF bapi_po_item, ls_poitem TYPE bapi_po_item, lt_account TYPE TABLE OF bapi_po_account, ls_account TYPE bapi_po_account. ls_header-po_number = '采购订单号'. ls_header-doc_date = sy-datum. ls_header-posting_date = sy-datum. ls_header-username = sy-uname. CALL FUNCTION 'BAPI_PO_GETDETAIL' EXPORTING purchaseorder = ls_header-po_number IMPORTING po_header = ls_header po_items = lt_poitem. LOOP AT lt_poitem INTO ls_poitem. ls_poitem-po_number = ls_header-po_number. ls_poitem-doc_date = sy-datum. ls_poitem-posting_date = sy-datum. CALL FUNCTION 'BAPI_PO_GETACCOUNT' EXPORTING purchaseorder = ls_header-po_number po_item = ls_poitem-po_item TABLES po_account = lt_account. LOOP AT lt_account INTO ls_account. ls_account-po_number = ls_header-po_number. ls_account-po_item = ls_poitem-po_item. ls_account-doc_date = sy-datum. ls_account-posting_date = sy-datum. ENDLOOP. ENDLOOP. ``` 2. 之后需要调用 `BAPI_PO_CHANGE` 函数进行采购订单的过账。 ``` CALL FUNCTION 'BAPI_PO_CHANGE' EXPORTING purchaseorder = ls_header-po_number headerdata = ls_header TABLES return = lt_return poitem = lt_poitem poaccount = lt_account. ``` 3. 最后需要判断过账是否成功。 ``` IF lt_return[] IS INITIAL. COMMIT WORK. WRITE: / '采购订单 ', ls_header-po_number, ' 过账成功。'. ELSE. ROLLBACK WORK. WRITE: / '采购订单 ', ls_header-po_number, ' 过账失败。'. ENDIF. ``` 以上就是 SAP 采购订单过账的 ABAP 代码实现。需要注意的是,实现过程中需要根据实际情况进行相应的修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值