SAP BAPI MB01

SAP 中采用BAPI  BAPI_GOODSMVT_CREATE 进行MB01 冲销功能


 GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order
* 02 - MB31 - Goods Receipts for Prod Order
* 03 - MB1A - Goods Issue
* 04 - MB1B - Transfer Posting
* 05 - MB1C - Enter Other Goods Receipt
* 06 - MB11
*
* Domain: KZBEW - Movement Indicator
* Goods movement w/o reference
* B - Goods movement for purchase order
* F - Goods movement for production order
* L - Goods movement for delivery note
* K - Goods movement for kanban requirement (WM - internal only)
* O - Subsequent adjustment of "material-provided" consumption
* W - Subsequent adjustment of proportion/product unit material
*


form frm_chongxiao_process.

 DATAls_header_ret LIKE bapi2017_gm_head_ret,
        ls_header     LIKE bapi2017_gm_head_01,
        ls_item       LIKE bapi2017_gm_item_create,
        lt_item       LIKE TABLE OF bapi2017_gm_item_create,
        lt_return     LIKE TABLE OF bapiret2" BAPI RETURN
        ls_return     like bapiret2,
        ls_retcom     LIKE bapiret2 " COMMIT RETURN
        .

data:begin of itaby occurs 0,
       ebeln like ekpo-ebeln,
       ebelp like ekpo-ebelp,
       matnr like ekpo-matnr,
     end of itaby.

  ls_header-pstng_date p_budat" 过账日期
  ls_header-doc_date   p_bldat" 凭证日期
  ls_header-pr_uname   sy-uname.

  select ebeln ebelp matnr into corresponding fields of table itaby from ekpo where ebeln p_ebeln.

  loop at purch_itab.
    ls_item-material purch_itab-matnr.
    ls_item-plant    purch_itab-werks.
    ls_item-stge_loc purch_itab-lgort.
    ls_item-batch    purch_itab-charg.
    ls_item-entry_qnt purch_itab-erfmg.
    ls_item-po_number p_ebeln.
    ls_item-move_type '102'.
    "ls_item-stck_type = 'X'.
    "ls_item-no_more_gr = 'X'.
    ls_item-mvt_ind 'B'.
    read table itaby with key matnr purch_itab-matnr.
    if sy-subrc 0.
      ls_item-po_item itaby-ebelp.
    endif.

    append ls_item to lt_item.
  endloop.

  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
       EXPORTING
         goodsmvt_header  ls_header
         goodsmvt_code    '01' " MB01
         "testrun          = p_test
       IMPORTING
         goodsmvt_headret ls_header_ret
       TABLES
         goodsmvt_item    lt_item[]
         return           lt_return[].
  if lt_return[] is initial.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait   'X'
          IMPORTING
            return ls_retcom.
    if strlenls_header_ret 10.

      data:msg(100type c.

      concatenate '冲销处理成功完成,物料凭证号' ls_header_ret+0(10into msg.

      refresh it_btns.
      it_btns-fcode 'BTN_PROC'.
      append it_btns.

      message msg type 'S'.
    endif.

  else.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
          IMPORTING
            return ls_retcom.

    data:msge(100type c.
    loop at lt_return into ls_return.
      concatenate msge ls_return-message into msge.
    endloop.
    message msge type 'S'.
  endif.
endform.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值