首页 > 其他分享 >ABAP:VF01销售开票BAPI

ABAP:VF01销售开票BAPI

时间:2022-12-19 11:11:53浏览次数:58  
标签:zsdt008 VF01 BAPI zsdt017 lt ABAP ls TABLE TYPE

VF01销售开票BAPI:

FUNCTION zsdfu007.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  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:lt_zsdt013 TYPE TABLE OF zsdt013,
       ls_zsdt013 LIKE LINE OF lt_zsdt013,
       ls_zsdt016 TYPE zsdt016,
       lt_zsdt016 TYPE TABLE OF zsdt016,
       lt_zsdt018 TYPE TABLE OF zsdt018,
       ls_zsdt018 LIKE LINE OF lt_zsdt018,
       lt_zsdt017 TYPE TABLE OF zsdt017,
       ls_zsdt017 LIKE LINE OF lt_zsdt017.

  DATA:BEGIN OF ls_objkey,
         ebeln  TYPE ekko-ebeln,
         objkey TYPE zsdt008-objkey.
  DATA:END OF ls_objkey.
  DATA lt_objkey LIKE TABLE OF ls_objkey.
  DATA:BEGIN OF ls_zrfc_logid,
         zrfc_logid TYPE zsdt013-zrfc_logid,
         objkey     TYPE zsdt013-objkey,
         zrfcid     TYPE zsdt013-zrfcid,
       END OF ls_zrfc_logid.
  DATA lt_zrfc_logid LIKE TABLE OF ls_zrfc_logid.
  DATA:ls_zrfct002 TYPE zrfct002.
  DATA:ls_creatordatain TYPE bapicreatordata,
       lt_billing       TYPE STANDARD TABLE OF bapivbrk,
       ls_billing       TYPE bapivbrk.
  DATA:lt_likp TYPE TABLE OF likp WITH HEADER LINE.
  TYPES BEGIN OF ty_zsdt008.
          INCLUDE TYPE zsdt008.
  TYPES vbeln TYPE vbak-vbeln.
  TYPES ebeln TYPE ekko-ebeln.
  TYPES END OF ty_zsdt008.
  DATA:ls_zsdt008 TYPE ty_zsdt008.
  DATA:lt_zsdt008 TYPE TABLE OF ty_zsdt008.
  DATA:ls_zsdt0082 TYPE  ty_zsdt008.
  DATA:lt_zsdt0082 TYPE TABLE OF ty_zsdt008.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_zsdt018
     FROM zsdt018
     WHERE zrfc_logid = i_id.
  IF lt_zsdt018 IS INITIAL.
    e_code = 'E'.
    e_msg  = '无可执行数据'.
    RETURN.
  ENDIF.
  CALL METHOD zcl_rfc=>get_source
    EXPORTING
      i_id       = i_id
      i_canum    = i_canum
    IMPORTING
      e_zrfct002 = ls_zrfct002.
  DATA:lv_zrfc_logid TYPE zrfc_logid.

  SELECT SINGLE * INTO ls_zsdt016 FROM zsdt016 WHERE zrfcid = ls_zrfct002-zrfcid AND canum = i_canum." AND bsart = ls_zsdt018-bsart.
  LOOP AT lt_zsdt018 INTO ls_zsdt018.
    ls_objkey-objkey = ls_zsdt018-ebeln.
    ls_objkey-ebeln = ls_zsdt018-ebeln.
    COLLECT ls_objkey INTO lt_objkey.
  ENDLOOP.
  SELECT
    *
    INTO TABLE lt_zsdt0082
    FROM zsdt008
    FOR ALL ENTRIES IN lt_objkey
    WHERE objkey = lt_objkey-objkey
    AND zrfcid = ls_zsdt016-zzrfcid.

  IF  lt_zsdt0082 IS NOT INITIAL.
    SELECT *
      INTO TABLE lt_zsdt008
      FROM zsdt008
      FOR ALL ENTRIES IN lt_zsdt0082
      WHERE zrfc_logid = lt_zsdt0082-zrfc_logid
      AND canum = ls_zsdt016-zcanum.
    LOOP AT lt_zsdt008 INTO ls_zsdt008.
      ls_zsdt008-vbeln = ls_zsdt008-objkey.
      MODIFY lt_zsdt008 FROM ls_zsdt008.
    ENDLOOP.
  ENDIF.

*  IF sy-subrc <> 0.
  IF lt_zsdt008 IS INITIAL.
    e_code = 'E'.
    e_msg  = '无可执行数据'.
    RETURN.
  ENDIF.
  DATA:ls_vbak TYPE vbak,
       lt_vbak TYPE TABLE OF vbak,
       ls_vbap TYPE vbap,
       lt_vbap TYPE TABLE OF vbap.
  IF lt_zsdt008 IS NOT INITIAL.
    SELECT
      *
      INTO TABLE lt_vbak
      FROM vbak
      FOR ALL ENTRIES IN lt_zsdt008
      WHERE vbeln = lt_zsdt008-vbeln.

    SELECT
      *
      INTO TABLE lt_vbap
      FROM vbap
      FOR ALL ENTRIES IN lt_zsdt008
    WHERE vbeln = lt_zsdt008-vbeln.
  ENDIF.

  DATA:lv_posnr TYPE vbap-posnr.

****ADD BY ZJ 20221205 S 删除免费赠品
  DELETE lt_zsdt018 WHERE flag = 'X'.
****ADD BY ZJ 20221205 E 删除免费赠品

  LOOP AT lt_zsdt018 INTO ls_zsdt018.
    READ TABLE lt_objkey INTO ls_objkey WITH KEY ebeln = ls_zsdt018-ebeln.
    IF sy-subrc = 0.
      READ TABLE lt_zsdt0082 INTO ls_zsdt0082 WITH KEY objkey = ls_objkey-objkey.
      IF sy-subrc = 0.
        READ TABLE lt_zsdt008 INTO ls_zsdt008 WITH  KEY zrfc_logid = ls_zsdt0082-zrfc_logid.
        IF sy-subrc = 0.
          READ TABLE lt_vbak INTO ls_vbak WITH KEY vbeln = ls_zsdt008-vbeln.
        ENDIF.
      ENDIF.
    ENDIF.
    lv_posnr = ls_zsdt018-ebelp.
    READ TABLE lt_vbap INTO ls_vbap WITH KEY posnr = lv_posnr vbeln = ls_zsdt008-vbeln.
    ls_creatordatain-created_by = sy-uname.
    ls_creatordatain-created_on = ls_zsdt018-bldat.
    ls_billing-ref_doc    = ls_vbak-vbeln.
    ls_billing-ref_doc_ca    = ls_vbak-vbtyp.
    ls_billing-ref_item    = ls_vbap-posnr.
    ls_billing-bill_date  =  ls_zsdt018-budat.
    ls_billing-req_qty = ls_zsdt018-menge.
****begin  of  jt-hpz 20221129  销售订单发票按采购订单行汇总
    COLLECT ls_billing INTO lt_billing.
    AT END OF ebeln.
      ls_zsdt017-canum = i_canum.
      ls_zsdt017-objtype = ls_zrfct002-objtype_save.
      ls_zsdt017-zrfcid = ls_zrfct002-zrfcid.
      ls_zsdt017-zrfc_logid = i_id.
      ls_zsdt017-zzrfc_logid = ls_zsdt008-zrfc_logid.
      ls_zsdt017-zcanum = ls_zsdt008-canum.
      ls_zsdt017-zobjkey = ls_zsdt008-objkey.
      ls_zsdt017-zobjtype = ls_zsdt008-objtype.
      APPEND ls_zsdt017 TO lt_zsdt017.
    ENDAT.
  ENDLOOP.
  PERFORM create_bl TABLES  et_return lt_billing lt_zsdt017 USING i_id i_canum ls_creatordatain CHANGING e_code e_msg e_flow_end.
  REFRESH:lt_billing,lt_zsdt017.
ENDFUNCTION.
FORM create_bl  TABLES   p_et_return STRUCTURE zrfct005
                         lt_billing STRUCTURE  bapivbrk
                         lt_zsdt017 STRUCTURE  zsdt017
                USING    p_i_id TYPE zrfc_logid
                         p_i_canum TYPE canum
                         ls_creatordatain TYPE bapicreatordata
                CHANGING p_e_code
                         p_e_msg
                         p_e_flow_end.
  DATA:  lt_return1 TYPE STANDARD TABLE OF bapireturn1,
         lt_errors  TYPE STANDARD TABLE OF bapivbrkerrors,
         lt_success TYPE STANDARD TABLE OF bapivbrksuccess,
         ls_billing TYPE bapivbrk,
         ls_return1 TYPE bapireturn1,
         ls_errors  TYPE bapivbrkerrors,
         ls_success TYPE bapivbrksuccess.
  DATA:BEGIN OF ls_bill_doc,
         bill_doc TYPE bapivbrksuccess-bill_doc,
       END OF ls_bill_doc,
       lt_bill_doc LIKE TABLE OF ls_bill_doc.
  DATA ls_zsdt017 TYPE zsdt017.
  DATA:ls_zrfct005 TYPE zrfct005.
  DATA:message   TYPE c LENGTH 200.
  DATA:bill_doc   TYPE c LENGTH 200.
  DATA:lt_condition TYPE TABLE OF bapikomv,
       lt_bapisucc  TYPE TABLE OF bapisucc.
  CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE'
    EXPORTING
      creatordatain = ls_creatordatain
    TABLES
      billingdatain = lt_billing
      errors        = lt_errors
      return        = lt_return1
      success       = lt_success.
  WAIT UP TO '0.5' SECONDS."不加没有返回消息
  IF lt_success[] IS NOT INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    LOOP AT lt_success INTO ls_success.
      ls_bill_doc-bill_doc = ls_success-bill_doc.
      COLLECT ls_bill_doc INTO lt_bill_doc.
    ENDLOOP.
    IF sy-subrc EQ 0.
      LOOP AT lt_zsdt017 INTO ls_zsdt017.
        LOOP AT lt_bill_doc INTO ls_bill_doc.
          ls_zsdt017-objtype = 'BL'.
          ls_zsdt017-objkey = ls_bill_doc-bill_doc."发票凭证
          MODIFY lt_zsdt017 FROM ls_zsdt017.
        ENDLOOP.
      ENDLOOP.
      MODIFY zsdt017 FROM TABLE lt_zsdt017.
      p_e_code = 'S'.
      LOOP AT lt_bill_doc INTO ls_bill_doc.
        CONCATENATE bill_doc ls_bill_doc-bill_doc ',' INTO bill_doc.
      ENDLOOP.
      CONCATENATE 'BL:' bill_doc '创建成功' 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 = ls_success-bill_doc.
      APPEND ls_zrfct005 TO p_et_return.
    ENDIF.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    LOOP AT lt_return1 INTO ls_return1 WHERE type = 'E' OR type = 'A'.
      CONCATENATE message ls_return1-message INTO message.
    ENDLOOP.
    p_e_code = 'E'.
    p_e_msg = message.
  ENDIF.
ENDFORM.  

 

标签:zsdt008,VF01,BAPI,zsdt017,lt,ABAP,ls,TABLE,TYPE
From: https://www.cnblogs.com/ap-ad-java-abap/p/16991683.html

相关文章

  • 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:向导里包含的$......
  • 在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,......