首页 > 其他分享 >ABAP:MIGO收货BAPI

ABAP:MIGO收货BAPI

时间:2022-12-19 10:47:37浏览次数:48  
标签:BAPI zsdt013 zsdt012 MIGO lt item ABAP ls goodsmvt

MIGO收货BAPI:

  DATA:lt_zsdt008   TYPE TABLE OF zsdt008,
       ls_zsdt008   LIKE LINE OF lt_zsdt008,
       ls_zsdt008_2 LIKE LINE OF lt_zsdt008,
       ls_zsdt014   TYPE zsdt014,
       lt_zsdt014   TYPE TABLE OF zsdt014,
       lt_zsdt013   TYPE TABLE OF zsdt013,
       ls_zsdt013   LIKE LINE OF lt_zsdt013,
       lt_zsdt013_2 TYPE TABLE OF zsdt013,
       ls_zsdt013_2 LIKE LINE OF lt_zsdt013,
       lt_zsdt012   TYPE TABLE OF zsdt012,
       ls_zsdt012   LIKE LINE OF lt_zsdt012,
       ls_ekpo      TYPE ekpo,
       lt_ekpo      TYPE TABLE OF ekpo.
  DATA:lv_ebeln TYPE ekko-ebeln,
       lv_vbeln TYPE vbap-vbeln,
       lv_tabix TYPE sy-tabix.
  DATA:goodsmvt_header LIKE  bapi2017_gm_head_01,
       goodsmvt_item   LIKE TABLE OF bapi2017_gm_item_create WITH HEADER LINE.
  DATA:lv_zrfcid TYPE zsdt008-zrfcid.
  DATA:lv_mjahr TYPE mjahr.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_zsdt012
     FROM zsdt012
     WHERE zrfc_logid = i_id.
  IF lt_zsdt012 IS INITIAL.
    e_code = 'E'.
    e_msg  = '无可执行数据'.
    RETURN.
  ENDIF.
  READ TABLE lt_zsdt012 INTO ls_zsdt012 INDEX 1.
  SELECT SINGLE zrfcid INTO lv_zrfcid FROM zsdt008 WHERE objkey = ls_zsdt012-ebeln AND objtype = 'PO' AND canum = '0010'.
  SELECT SINGLE *
    FROM zsdt014
    INTO ls_zsdt014
    WHERE zrfcid = ls_zsdt012-zrfcid
    AND canum = i_canum
    AND zzrfcid = lv_zrfcid.

  SORT lt_zsdt012 BY mblnr zeile.
  LOOP AT lt_zsdt012 INTO ls_zsdt012.
    CLEAR:ls_zsdt008,ls_zsdt008_2.
    SELECT SINGLE *
      FROM zsdt008
      INTO ls_zsdt008"源头采购订单
      WHERE objkey = ls_zsdt012-ebeln
        AND zrfcid = ls_zsdt014-zzrfcid.
    CHECK ls_zsdt008 IS NOT INITIAL.
    SELECT SINGLE *
      FROM zsdt008
      INTO ls_zsdt008_2"当前采购订单
      WHERE zrfc_logid = ls_zsdt008-zrfc_logid
        AND canum = ls_zsdt014-zcanum.
    SELECT SINGLE *
      FROM ekpo
      INTO ls_ekpo
      WHERE ebeln = ls_zsdt008_2-objkey
        AND ebelp = ls_zsdt012-ebelp.
    goodsmvt_header-pstng_date = ls_zsdt012-budat."过帐日期.
    goodsmvt_header-doc_date = ls_zsdt012-bldat."凭证日期.
    goodsmvt_header-pr_uname = sy-uname."用户名
    goodsmvt_header-ref_doc_no = ls_zsdt012-xblnr.
    goodsmvt_item-material = ls_ekpo-matnr."物料
    goodsmvt_item-plant = ls_ekpo-werks." 工厂
    IF ls_ekpo-werks = '3189'.
      goodsmvt_item-stge_loc = 'US01'.
    ELSE.
      goodsmvt_item-stge_loc = 'NX00'.
    ENDIF.
*    goodsmvt_item-entry_qnt = ls_zsdt012-zocdqty."数量
*    goodsmvt_item-entry_qnt = ls_ekpo-menge."数量
    SELECT SINGLE bstmg
      INTO goodsmvt_item-entry_qnt
      FROM mseg
     WHERE mblnr = ls_zsdt012-mblnr
       AND mjahr = ls_zsdt012-mjahr
       AND zeile = ls_zsdt012-zeile.
    SELECT COUNT(*)"启用批次
      FROM marc
      WHERE matnr = ls_ekpo-matnr
        AND werks = ls_ekpo-werks
        AND xchpf = 'X'.
    SELECT SINGLE bsart INTO @DATA(lv_bsart) FROM ekko WHERE ebeln = @ls_zsdt008_2-objkey.
    IF sy-subrc = 0.
      goodsmvt_item-batch     = ls_zsdt012-charg."批次
      SELECT COUNT(*) FROM mcha
        WHERE matnr = ls_ekpo-matnr
          AND werks = ls_ekpo-werks
          AND charg = ls_zsdt012-charg.
      IF sy-subrc <> 0.
        IF lv_bsart NE 'ZFAI' OR (
           lv_bsart = 'ZFAI' AND
           ls_zsdt012-charg NE '' ).
          CALL FUNCTION 'Z_BATCH_A'
            EXPORTING
              zmatnr     = ls_ekpo-matnr
              zwerks     = ls_ekpo-werks
              zbatch     = ls_zsdt012-charg
              ztype      = 'Y'
              isrefbatch = 'Y'.
        ENDIF.

      ENDIF.
    ENDIF.
    goodsmvt_item-entry_uom = ls_ekpo-meins."单位
*    goodsmvt_item-move_type = '101'. " 移动类型
    SELECT SINGLE bwart INTO goodsmvt_item-move_type
      FROM mseg
      WHERE mblnr = ls_zsdt012-mblnr AND mjahr = ls_zsdt012-mjahr AND zeile = ls_zsdt012-zeile.
*    GOODSMVT_ITEM-MOVE_REAS = LS_ZSDT012-GRUND."移动原因
    goodsmvt_item-mvt_ind = 'B'."移动标识:B 按照PO进行的货物移动
    goodsmvt_item-po_number = ls_zsdt008_2-objkey.   "采购订单
    goodsmvt_item-po_item = ls_zsdt012-ebelp.          "行项目
    SELECT SINGLE insmk
      INTO goodsmvt_item-stck_type
      FROM ekpo
      WHERE ebeln = goodsmvt_item-po_number
        AND ebelp = goodsmvt_item-po_item.
    APPEND goodsmvt_item.
    CLEAR goodsmvt_item.
    lv_mjahr = ls_zsdt012-mjahr.
    AT END OF mblnr.
      ls_zsdt013_2-canum      = i_canum.
      ls_zsdt013_2-zzrfc_logid = ls_zsdt008_2-zrfc_logid.
      ls_zsdt013_2-zcanum = ls_zsdt008_2-canum.
      ls_zsdt013_2-objkey    = ls_zsdt008_2-objkey.
      ls_zsdt013_2-zrfcid    = ls_zsdt014-zrfcid.
      ls_zsdt013_2-zrfc_logid    = i_id.
      ls_zsdt013_2-mblnr      = ls_zsdt012-mblnr.
      ls_zsdt013_2-mjahr      = lv_mjahr.
      ls_zsdt013_2-zobjkey    = ls_zsdt008-objkey.
      ls_zsdt013_2-zobjtype    = ls_zsdt008-objtype.
      APPEND ls_zsdt013_2 TO lt_zsdt013_2.
    ENDAT.
  ENDLOOP.
  PERFORM create_gr TABLES et_return goodsmvt_item lt_zsdt013_2 USING i_id i_canum goodsmvt_header ls_zsdt014 CHANGING e_code e_msg e_flow_end.
  REFRESH:goodsmvt_item,lt_zsdt013_2.

FORM create_gr  TABLES   p_et_return STRUCTURE zrfct005
                          p_goodsmvt_item STRUCTURE bapi2017_gm_item_create
                          p_lt_zsdt013 STRUCTURE zsdt013
                 USING    p_i_id TYPE zrfc_logid
                          p_i_canum TYPE canum
                          p_goodsmvt_header TYPE bapi2017_gm_head_01
                          p_ls_zsdt014 TYPE zsdt014
                 CHANGING p_e_code
                          p_e_msg
                          p_e_flow_end.
  DATA:message          TYPE c LENGTH 200,
       lt_return        LIKE TABLE OF bapiret2 WITH HEADER LINE,
       goodsmvt_item    LIKE  bapi2017_gm_item_create,
       materialdocument TYPE  bapi2017_gm_head_ret-mat_doc.

  DATA:ls_zrfct005 TYPE zrfct005.
  DATA:ls_zrfct002 TYPE zrfct002.
  DATA:lt_zsdt013 LIKE TABLE OF zsdt013,
       ls_zsdt013 LIKE LINE OF lt_zsdt013.
  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      goodsmvt_header  = p_goodsmvt_header
      goodsmvt_code    = '01'
    IMPORTING
      materialdocument = materialdocument
    TABLES
      goodsmvt_item    = p_goodsmvt_item[]
      return           = lt_return.
  CLEAR:message.
  LOOP AT lt_return WHERE type = 'A' OR type = 'E' .
    CONCATENATE message lt_return-message INTO message SEPARATED BY  '/'.
  ENDLOOP.
  IF  sy-subrc <> '0'.
    CALL METHOD zcl_rfc=>get_source
      EXPORTING
        i_id       = p_i_id
        i_canum    = p_i_canum
      IMPORTING
        e_zrfct002 = ls_zrfct002.
*          RECEIVING
*            R_SOURCE   = DATA(LS_SOURCE).
    LOOP AT p_lt_zsdt013 INTO ls_zsdt013.
      ls_zsdt013-objtype = ls_zrfct002-objtype_save.
      ls_zsdt013-zmblnr = materialdocument.
      MODIFY p_lt_zsdt013 FROM ls_zsdt013.
    ENDLOOP.
    MODIFY zsdt013 FROM TABLE p_lt_zsdt013.
*    CLEAR LT_ZSDT013[].
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    p_e_code = 'S'.
    CONCATENATE 'GR:' materialdocument '收货成功' INTO p_e_msg.

    CLEAR:ls_zrfct005.
    ls_zrfct005-status = '53'.
    ls_zrfct005-msgty = p_e_code.
    ls_zrfct005-msgid = '00'.
    ls_zrfct005-msgno = '001'.
    ls_zrfct005-msgv1 = p_e_msg.
    ls_zrfct005-msgv4 = materialdocument.
    APPEND ls_zrfct005 TO p_et_return.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    p_e_code = 'E'.
    p_e_msg = message.
  ENDIF.
ENDFORM.                    " CREATE_GR

 

标签:BAPI,zsdt013,zsdt012,MIGO,lt,item,ABAP,ls,goodsmvt
From: https://www.cnblogs.com/ap-ad-java-abap/p/16991600.html

相关文章

  • SAP ABAP CDS view 里 INNER JOIN 和 Association 的区别
    最近有朋友在我的知识星球里向我提问,SAPABAPCDSview的INNERJOIN和Association的功能可以理解为一样吗?(关于加入我的知识星球的方式,请移步本文文末)本文就来聊一......
  • WebApi 路由机制剖析
    从网上看了WEBAPI理解感觉不错分享一下一、MVC和WebApi路由机制比较1、MVC里面的路由在MVC里面,默认路由机制是通过url路径去匹配对应的action方法,比如/Home/GetUser这个......
  • WebApi 接口参数不再困惑:传参详解
    从网上看了WEBAPI理解感觉是不错的分享一下前言:还记得刚使用WebApi那会儿,被它的传参机制折腾了好久,查阅了半天资料。如今,使用WebApi也有段时间了,今天就记录下API接口传参......
  • SAP ABAP CDS view Association 引入的缘由
    ABAPCDSview支持三种join方式:InnerJoinLeftOuterjoinRightouterjoin我们使用ABAPDevelopmentTool的CDSview向导创建一个CDSview:向导里包含的$......
  • 在Asp.Net WebApi中使用DotNetZip压缩响应流过滤器
    usingIonic.Zlib;usingSystem;usingSystem.IO;usingSystem.Linq;usingSystem.Net.Http;usingSystem.Threading;usingSystem.Threading.Tasks;usingSystem.......
  • APAP:销售订单创建BAPI
    销售订单创建BAPI: SD_SALESDOCUMENT_CREATEDATA:lt_zsdt008LIKETABLEOFzsdt008,ls_zsdt008LIKELINEOFlt_zsdt008,ls_zsdt001TYPEzsdt001,......
  • ABAP:采购订单创建BAPI
    采购订单创建BAPI:BAPI_PO_CREATE1DATA:lt_zsdt008LIKETABLEOFzsdt008,ls_zsdt008LIKELINEOFlt_zsdt008,ls_zsdt001TYPEzsdt001,lt_z......
  • WebApi Autofac依赖注入配置
    publicclassAutofacConfig{///<summary>///IOC注册///</summary>publicstaticvoidRegister(){......
  • SAP ABAP CDS view 里 INNER JOIN 和 Association 的区别
    最近有朋友在我的[知识星球]里向我提问,SAPABAPCDSview的INNERJOIN和Association的功能可以理解为一样吗?本文就来聊一聊这个话题。既然CDSview里同时支持了INN......
  • 创建一个WebApi项目
    原文链接:https://www.bilibili.com/video/BV12L4y1b7ND/?spm_id_from=333.337.search-card.all.click&vd_source=23aa9dcacf4c7ddaed4172b5ffd451ab创建一个WebApi大致分......