BAPI中的货物移动事务代码

1.Backgroud

When you use migo for it . It is ok. But you don’t use bapi for it . The error is
following.

在这里插入图片描述
In the BAPI_GOODSMVT_CREATE . We must give goodsmvt_code for it.

2. Code

The value is following:

01 MB01
02 MB31
03 MB1A
04 MB1B
05 MB1C
06 MB11
07 MB04

 if itype = 'Z51'.
      l_goodsmvt_code = '06'.

    endif.

3 Demo

if itype = 'Z51'.
    if ijason is not initial.
      replace all occurrences of regex '"(\w+)"(\s*:\s*)'
                 in ijason  with '$1$2'.
      create object ztrexjsonret.
      ztrexjsonret->deserialize(
            exporting json = ijason
            importing abap = gt_data_z51[] ).
    endif.

    if gt_data_z51[] is initial.
      esign = 'E'.
      emessage = '传输数据为空,或JSON数据解析出错,请检查!'.
      exit.
    endif.

**Check Data
    check esign is initial.

    clear:gw_data_z51.
    loop at gt_data_z51  into gw_data_z51 .

      move-corresponding gw_data_z51 to  gw_ztmm124.
      append   gw_ztmm124 to gt_ztmm124 .
      clear: gw_data_z51,gw_ztmm124.
    endloop.

    read table gt_data_z51 into gw_data_z51 index 1.
    "Dealing with posting data .
    call function 'ZWMSWS_FUN_PERIOD'
      exporting
        budat     = sy-datum
        werks     = gw_data_z51-werks
      importing
        budat_out = p_budat." posting data


    " Judge  BAPI's code value  as  business movetype

    if itype = 'Z51'.
      l_goodsmvt_code = '06'.

    endif.


    "head data
    l_goodsmvt_header-pstng_date = p_budat.
    l_goodsmvt_header-doc_date   = sy-datum.
    l_goodsmvt_header-pr_uname   = sy-uname.
*    l_goodsmvt_header-ref_doc_no = gw_data_Z51-rsnum.



    "line data
    clear :gw_data_z51,gw_mard.
    loop at gt_data_z51 into gw_data_z51.
      ref_add_zero:gw_data_z51-matnr.

      it_goodsmvt_item-material = gw_data_z51-matnr .
      it_goodsmvt_item-plant     = gw_data_z51-werks.
      it_goodsmvt_item-stge_loc  = gw_data_z51-lgort.
      it_goodsmvt_item-move_type = itype .
      it_goodsmvt_item-entry_qnt = gw_data_z51-menge .
      it_goodsmvt_item-item_text = gw_data_z51-sgtxt .
      it_goodsmvt_item-mvt_ind = ' '.
*      it_goodsmvt_item-reserv_no   = gw_data_Z51-rsnum.
      select single * from mard
      into gw_mard
      where  werks = gw_data_z51-werks and lgort = gw_data_z51-lgort and matnr = gw_data_z51-matnr .
      if gw_data_z51-menge > gw_mard-labst.
        esign  = 'E'.
        concatenate   gw_data_z51-matnr '过账数大于库存数' into emessage.
        exit.
      endif.

      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = it_goodsmvt_item-customer
        importing
          output = it_goodsmvt_item-customer.

      append it_goodsmvt_item.
      clear:it_goodsmvt_item.

    endloop.
** Call BAPI  for delivery.
    call function 'BAPI_GOODSMVT_CREATE'
      exporting
        goodsmvt_header  = l_goodsmvt_header
        goodsmvt_code    = l_goodsmvt_code
      importing
        goodsmvt_headret = l_goodsmvt_headret
      tables
        goodsmvt_item    = it_goodsmvt_item
        return           = it_return.

    if it_return[] is initial.
      call function 'BAPI_TRANSACTION_COMMIT'
        exporting
          wait = 'X'.
      mblnr = l_goodsmvt_headret(10).
      esign = 'S'.
      emessage = '执行成功'.

      loop at gt_ztmm124 into gw_ztmm124.
        gw_ztmm124-status  = 'S'.
        gw_ztmm124-resultdata = '调拨单过账成功' .
        modify gt_ztmm124 from gw_ztmm124.
        clear:gw_ztmm124.
      endloop.
      modify ztmm124 from table gt_ztmm124.
      commit work and wait.
    else.
      "Error
      call function 'BAPI_TRANSACTION_ROLLBACK'.
      esign = 'E'.
      concatenate  gw_data_z51-matnr '调拨单过账失败!'  into emessage.
      loop at gt_ztmm124 into gw_ztmm124.
        gw_ztmm124-status  = 'E'.
        gw_ztmm124-resultdata = '调拨单过账失败' .
        modify gt_ztmm124 from gw_ztmm124.
        clear:gw_ztmm124.
      endloop.
      modify ztmm124 from table gt_ztmm124.
      commit work and wait.
    endif.

4 Summary

1.When you use key word ''bapi 货物移动" for search in the baidu.
2.T158G , you can read it in the table.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值