2017年8月19日 星期六

ABAP/4 : BAPI:BAPI_GOODSMVT_CANCEL Reversed MM DOC (MBST)

當 MM Document 過帳後,如果須要進行迴轉時,一般透過 MBST 進行迴轉,有時需要透過系統自動迴轉時,則可以使用 BAPI:BAPI_GOODSMVT_CANCEL,進行


IMPORT 參數
MATERIALDOCUMENT : 要迴轉的 MM Doc
MATDOCUMENTYEAR ; 要迴轉傳票的 MM Doc Year
GOODSMVT_PSTNG_DATE : 過帳的日期
GOODSMVT_PR_UNAME : 過帳的 User ID

EXPORT 參數
GOODSMVT_HEADRET : 產生的回轉 MM Doc 相關資訊

TABLES 參數
RETURN : 執行的 Return Message
GOODSMVT_MATDOCITEM : 如果非整張文件迴轉,則可以 By Item 迴轉


一、MM Document Reversed

SAMPLE CODE :

REPORT Z_BAPI_GOODSMVT_CANCEL.

DATA:
  L_MATERIALDOCUMENT    TYPE BAPI2017_GM_HEAD_02-MAT_DOC,
  L_MATDOCUMENTYEAR     TYPE BAPI2017_GM_HEAD_02-DOC_YEAR,
  L_GOODSMVT_PSTNG_DATE TYPE BAPI2017_GM_HEAD_02-PSTNG_DATE,
  L_GOODSMVT_PR_UNAME   TYPE BAPI2017_GM_HEAD_01-PR_UNAME.

DATA:
  L_GOODSMVT_HEADRET    LIKE BAPI2017_GM_HEAD_RET.

DATA:
  L_RETURN LIKE STANDARD TABLE OF BAPIRET2 WITH HEADER LINE.

L_MATERIALDOCUMENT    = '5000001712'.
L_MATDOCUMENTYEAR     = '2017'.
L_GOODSMVT_PSTNG_DATE = '20170819'.
L_GOODSMVT_PR_UNAME   = SY-UNAME.

CALL FUNCTION 'BAPI_GOODSMVT_CANCEL'
  EXPORTING
    MATERIALDOCUMENT          = L_MATERIALDOCUMENT
    MATDOCUMENTYEAR           = L_MATDOCUMENTYEAR
    GOODSMVT_PSTNG_DATE       = L_GOODSMVT_PSTNG_DATE
    GOODSMVT_PR_UNAME         = L_GOODSMVT_PR_UNAME
  IMPORTING
    GOODSMVT_HEADRET          = L_GOODSMVT_HEADRET
  TABLES
    RETURN                    = L_RETURN
*   GOODSMVT_MATDOCITEM       =
          .

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    WAIT          = 'X'
*  IMPORTING
*    RETURN        =
          .

WRITE L_GOODSMVT_HEADRET.

執行後即可產生回轉文件,在 PO History 產生 102 迴轉文件

如果只想迴轉文件中的一個 Item 時,則可使用參數 GOODSMVT_MATDOCITEM

SAMPLE CODE :

REPORT Z_BAPI_GOODSMVT_CANCEL.

DATA:
  L_MATERIALDOCUMENT    TYPE BAPI2017_GM_HEAD_02-MAT_DOC,
  L_MATDOCUMENTYEAR     TYPE BAPI2017_GM_HEAD_02-DOC_YEAR,
  L_GOODSMVT_PSTNG_DATE TYPE BAPI2017_GM_HEAD_02-PSTNG_DATE,
  L_GOODSMVT_PR_UNAME   TYPE BAPI2017_GM_HEAD_01-PR_UNAME.

DATA:
  L_GOODSMVT_HEADRET    LIKE BAPI2017_GM_HEAD_RET.

DATA:
  L_RETURN LIKE STANDARD TABLE OF BAPIRET2 WITH HEADER LINE.

DATA:
  LT_GOODSMVT_MATDOCITEM LIKE STANDARD TABLE OF BAPI2017_GM_ITEM_04 WITH HEADER LINE.

L_MATERIALDOCUMENT    = '5000001736'.
L_MATDOCUMENTYEAR     = '2017'.
L_GOODSMVT_PSTNG_DATE = '20170819'.
L_GOODSMVT_PR_UNAME   = SY-UNAME.

LT_GOODSMVT_MATDOCITEM-MATDOC_ITEM = '0002'.
APPEND LT_GOODSMVT_MATDOCITEM. CLEAR LT_GOODSMVT_MATDOCITEM.

CALL FUNCTION 'BAPI_GOODSMVT_CANCEL'
  EXPORTING
    MATERIALDOCUMENT          = L_MATERIALDOCUMENT
    MATDOCUMENTYEAR           = L_MATDOCUMENTYEAR
    GOODSMVT_PSTNG_DATE       = L_GOODSMVT_PSTNG_DATE
    GOODSMVT_PR_UNAME         = L_GOODSMVT_PR_UNAME
  IMPORTING
    GOODSMVT_HEADRET          = L_GOODSMVT_HEADRET
  TABLES
    RETURN                    = L_RETURN
    GOODSMVT_MATDOCITEM       = LT_GOODSMVT_MATDOCITEM.
          .

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    WAIT          = 'X'
*  IMPORTING
*    RETURN        =
          .

WRITE L_GOODSMVT_HEADRET.

即可看到目前產生的迴轉文件只有其中一個 Item

沒有留言:

張貼留言

How to install & specified python version or distreibtuion package version in google colab

在買了 RTX 3080 要來 挖礦...  嗯~是跑機器學習後,結果發現了 GOOGLE COLAB,其實之前在「GAN 對抗式生成網路」一書就有看到,但資訊人就是什麼都想自己安裝,在本機用 Anaconda + pyCharm 弄了 GPU 環境,結果有天從新竹回家發現家裡沒...