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

ABAP:MIGO收货冲销BAPI

时间:2022-12-19 11:34:44浏览次数:42  
标签:BAPI zsdt013 MIGO head zsdt022 item ABAP ls TYPE

MIGO收货冲销BAPI

FUNCTION zsdfu014.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_ID) TYPE  ZRFC_LOGID OPTIONAL
*"     VALUE(I_CANUM) TYPE  CANUM OPTIONAL
*"  EXPORTING
*"     VALUE(E_CODE) TYPE  MSGTY
*"     VALUE(E_MSG) TYPE  MSGTXT
*"     VALUE(E_FLOW_END) TYPE  CHAR01
*"  TABLES
*"      ET_RETURN STRUCTURE  ZRFCT005 OPTIONAL
*"----------------------------------------------------------------------
  DATA:ls_zsdt022 TYPE zsdt022.
  DATA:ls_zsdt013_1 TYPE zsdt013,
       lt_zsdt013   TYPE TABLE OF zsdt013,
       ls_zsdt013_2 TYPE zsdt013.

  SELECT * INTO TABLE @DATA(lt_zsdt022) FROM zsdt022 WHERE zrfc_logid = @i_id.
  IF lt_zsdt022 IS INITIAL.
    e_code = 'E'.
    e_msg = '无可执行数据'.
    RETURN.
  ENDIF.

  DATA:ls_head     TYPE bapi2017_gm_head_02,
       ls_head_ret TYPE bapi2017_gm_head_ret,
       lt_return   TYPE TABLE OF bapiret2,
       ls_return   TYPE bapiret2.

  DATA:message TYPE c LENGTH 200.
  DATA:ls_zrfct002 TYPE zrfct002,
       ls_zsdt013  TYPE zsdt013,
       ls_zrfct005 TYPE zrfct005.

  DATA:ls_head_im TYPE bapi2017_gm_head_01,
       ls_head_ex TYPE bapi2017_gm_head_ret,
       lt_item    TYPE TABLE OF bapi2017_gm_item_create,
       ls_item    TYPE bapi2017_gm_item_create.
  DATA:lv_mblnr TYPE bapi2017_gm_serialnumber.
  LOOP AT lt_zsdt022 INTO ls_zsdt022.

    ls_head_im-pstng_date = ls_zsdt022-budat.
    ls_head_im-ref_doc_no = ls_zsdt022-xblnr.
    ls_head_im-doc_date = ls_zsdt022-budat.
    ls_head_im-pr_uname = sy-uname.

    ls_item-material = ls_zsdt022-matnr.
    ls_item-plant = ls_zsdt022-werks.
    ls_item-stge_loc = ls_zsdt022-lgort.
    ls_item-batch = ls_zsdt022-charg.
    ls_item-move_type = ls_zsdt022-bwart.
    ls_item-entry_qnt = ls_zsdt022-menge.
    ls_item-mvt_ind = 'B'.
    ls_item-po_number = ls_zsdt022-ebeln.
    ls_item-po_item = ls_zsdt022-ebelp.
    ls_item-ref_doc = ls_zsdt022-zmblnr.
    ls_item-ref_doc_it = ls_zsdt022-zeile.
    ls_item-move_reas = ls_zsdt022-grund.
    APPEND ls_item TO lt_item.

    SELECT SINGLE * INTO ls_zsdt013_1 FROM zsdt013 WHERE zmblnr = ls_zsdt022-zmblnr.
    ls_zsdt013-zrfc_logid = i_id.
    ls_zsdt013-canum = i_canum.
    ls_zsdt013-zzrfc_logid = ls_zsdt013_1-zrfc_logid.
    ls_zsdt013-zcanum = ls_zsdt013_1-canum.
    ls_zsdt013-mblnr = ls_zsdt022-mblnr.
    ls_zsdt013-mjahr = ls_zsdt022-mjahr.
    ls_zsdt013-zrfc_logid_2 = ls_zsdt013_1-zrfc_logid.
    ls_zsdt013-canum_2 = ls_zsdt013_1-canum.
    ls_zsdt013-zzrfc_logid_2 = ls_zsdt013_1-zzrfc_logid.
    ls_zsdt013-zcanum_2 = ls_zsdt013_1-zcanum.
    ls_zsdt013-objtype = 'GS'.
    ls_zsdt013-objkey = ls_zsdt013_1-objkey.
    ls_zsdt013-zobjtype = 'PO'.
    ls_zsdt013-zobjkey = ls_zsdt013_1-zobjkey.
    ls_zsdt013-zrfcid = ls_zsdt013_1-zrfcid.
    APPEND ls_zsdt013 TO lt_zsdt013.
    CLEAR:ls_zsdt022,ls_item,ls_zsdt013,ls_zsdt013_1.
  ENDLOOP.


  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      goodsmvt_header  = ls_head_im
      goodsmvt_code    = '01'
    IMPORTING
      goodsmvt_headret = ls_head_ex
    TABLES
      goodsmvt_item    = lt_item
      return           = lt_return.

  LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
    CONCATENATE message ls_return-message INTO message SEPARATED BY  '/'.
  ENDLOOP.
  IF sy-subrc NE 0.
    CALL METHOD zcl_rfc=>get_source
      EXPORTING
        i_id       = i_id
        i_canum    = i_canum
      IMPORTING
        e_zrfct002 = ls_zrfct002.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    e_code = 'S'.
    CONCATENATE  ls_head-mat_doc '冲销成功' INTO e_msg.

    CLEAR:ls_zrfct005.
    ls_zrfct005-status = '53'.
    ls_zrfct005-msgty = e_code.
    ls_zrfct005-msgid = '00'.
    ls_zrfct005-msgno = '001'.
    ls_zrfct005-msgv1 = e_msg.
    ls_zrfct005-msgv4 = ls_head_ex-mat_doc.
    APPEND ls_zrfct005 TO et_return.


    ls_zsdt013_2-zmblnr = ls_head_ex-mat_doc.
    ls_zsdt013_2-fkstol = 'X'.
    MODIFY lt_zsdt013 FROM ls_zsdt013_2
                      TRANSPORTING zmblnr fkstol
                      WHERE zmblnr IS INITIAL.

    MODIFY zsdt013 FROM TABLE lt_zsdt013.

  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    e_code = 'E'.
    e_msg = message.
  ENDIF.
ENDFUNCTION.

 

标签:BAPI,zsdt013,MIGO,head,zsdt022,item,ABAP,ls,TYPE
From: https://www.cnblogs.com/ap-ad-java-abap/p/16991726.html

相关文章

  • ABAP:ME22N采购订单修改BAPI
    ME22N采购订单修改BAPI:FUNCTIONzsdfu015.*"----------------------------------------------------------------------*"*"本地接口:*"IMPORTING*"VALUE(I_I......
  • ABAP:VF01销售开票BAPI
    VF01销售开票BAPI:FUNCTIONzsdfu007.*"----------------------------------------------------------------------*"*"本地接口:*"IMPORTING*"VALUE(I_ID)TY......
  • ABAP:ME22N采购订单修改增强
    ME22N采购订单修改增强:BADI名称:ME_PROCESS_PO_CUST SE18找到BADI创建实施        找到对应的方法:PROCESS_HEADER:methodIF_EX_ME_PROCES......
  • ABAP:VA02销售订单修改BAPI
    VA02销售订单修改BAPIFUNCTIONzsdfu016.*"----------------------------------------------------------------------*"*"本地接口:*"IMPORTING*"VALUE(I_ID)......
  • ABAP:销售订单审批及反审函数
    销售订单审批及反审函数:DATA:ls_zsdt028TYPEzsdt028,lt_zsdt028TYPETABLEOFzsdt028,ls_zsdt008TYPEzsdt008,lt_zsdt008TYPETABLE......
  • ABAP:MIGO收货BAPI
    MIGO收货BAPI:DATA:lt_zsdt008TYPETABLEOFzsdt008,ls_zsdt008LIKELINEOFlt_zsdt008,ls_zsdt008_2LIKELINEOFlt_zsdt008,ls_z......
  • 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:向导里包含的$......