函数使用五:MIR7 发票预制 BAPI_INCOMINGINVOICE_PARK

Posted ^ω^SAp傻X^o^

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了函数使用五:MIR7 发票预制 BAPI_INCOMINGINVOICE_PARK相关的知识,希望对你有一定的参考价值。

引自:http://blog.csdn.net/champaignwolf/article/details/51422329

FUNCTION zincominginvoice_park.

*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(CODE) TYPE  CHAR01
*"     VALUE(MESSAGE) TYPE  CHAR200
*"  TABLES
*"      INPUT STRUCTURE  ZFC_INCOMINGINVOICE_PARK_INPUT OPTIONAL
*"----------------------------------------------------------------------

  DATA: vp_eind(1),
        ls_headerdata       LIKE bapi_incinv_create_header,
        lt_itemdata         LIKE TABLE OF bapi_incinv_create_item,
        ls_itemdata         LIKE bapi_incinv_create_item,
        lt_materialdata     LIKE TABLE OF bapi_incinv_create_material,
        ls_materialdata     LIKE bapi_incinv_create_material,
        lt_taxdata          LIKE TABLE OF bapi_incinv_create_tax,
        ls_taxdata          LIKE bapi_incinv_create_tax,
        lt_return           LIKE TABLE OF bapiret2,
        ls_return           LIKE bapiret2,
        lv_invoicedocnumber LIKE bapi_incinv_fld-inv_doc_no,
        lv_fiscalyear       LIKE bapi_incinv_fld-fisc_year.

  DATA:lv_mwskz LIKE ekpo-mwskz.
  DATA:lv_rblgp TYPE rblgp.
*1/3 invoice_ind=‘X‘ db_cr_ind=‘S‘ (抬头),  2/4 invoice_ind=‘‘ db_cr_ind=‘H‘  (外部物料相关项目)
*1/2 de_cre_ind =‘‘   ,  3/4 de_cre_ind=‘X‘   (po采购订单相关项目)


* BAPI赋值
  CLEAR input.
  READ TABLE input INDEX 1.
  IF sy-subrc EQ 0.
    ls_headerdata-invoice_ind  = ‘X‘." sp_head-xrech.    "发票标志
*  ls_headerdata-doc_type     = ‘RE‘."sp_head-blart.
    ls_headerdata-doc_date     = sy-datum."sp_head-bldat.
    ls_headerdata-pstng_date   = sy-datum. "sp_head-budat.
    ls_headerdata-bline_date   = sy-datum. "sp_head-zfbdt.    "基线日期/付款计算的起始日期

    ls_headerdata-comp_code    = ‘6100‘."sp_head-bukrs.
    SELECT SINGLE
           waers
           INTO ls_headerdata-currency
           FROM ekko
           WHERE ebeln = input-ebeln.

*    ls_headerdata-gross_amount = ‘24‘."sp_head-rmwwr.    "总金额
*  ls_headerdata-del_costs    = sp_head-beznk.    "未计划的交货费
*  ls_headerdata-pmnttrms     = sp_head-zterm.    "付款条件
*  ls_headerdata-alloc_nmbr   = sp_head-zuonr.    "分配编号/外部发票号码
*  ls_headerdata-diff_inv     = sp_head-lifnr.    "出票方/供应商
*  ls_headerdata-ref_doc_no   = sp_head-xblnr.
    ls_headerdata-header_txt   = input-bktxt."‘123‘."sp_head-bktxt.
    ls_headerdata-item_text    = input-sgtxt."‘456‘."sp_head-sgtxt.
  ENDIF.


  CLEAR lv_rblgp.
  LOOP AT input.
    lv_rblgp = lv_rblgp + 1.
    CLEAR lv_mwskz.
    SELECT SINGLE
           mwskz
           meins
           INTO (lv_mwskz,ls_itemdata-po_unit)
           FROM ekpo
           WHERE ebeln = input-ebeln
             AND ebelp = input-ebelp.

    ls_headerdata-gross_amount = ls_headerdata-gross_amount + input-wrbtr.

    ls_itemdata-invoice_doc_item = lv_rblgp."ls_poitem-buzei.   "发票行项目号
    ls_itemdata-po_number        = input-ebeln."‘4500038014‘."ls_poitem-ebeln.
    ls_itemdata-po_item          = input-ebelp."‘10‘."ls_poitem-ebelp.

    SELECT SINGLE
           belnr
           gjahr
           buzei
           INTO (ls_itemdata-ref_doc,ls_itemdata-ref_doc_year,ls_itemdata-ref_doc_it  )
           FROM ekbe
           WHERE ebeln = input-ebeln
             AND ebelp = input-ebelp
             AND belnr = input-mblnr.
*    ls_itemdata-ref_doc          = ‘5000188866‘."ls_poitem-lfbnr.
*    ls_itemdata-ref_doc_year     = ‘2016‘."ls_poitem-lfgja.
*    ls_itemdata-ref_doc_it       = ‘1‘."ls_poitem-lfpos.

    ls_itemdata-item_amount      = input-wrbtr."‘24‘."ls_poitem-wrbtr.
    ls_itemdata-quantity         = input-menge."‘2‘."ls_poitem-menge.
*    ls_itemdata-po_unit          = ‘EA‘."ls_poitem-meins.
    ls_itemdata-tax_code         = lv_mwskz."ls_poitem-mwskz.

    APPEND ls_itemdata TO lt_itemdata.
    CLEAR: ls_itemdata.



    "  LOOP AT tp_baitem INTO ls_baitem.
    ls_materialdata-invoice_doc_item = lv_rblgp."ls_baitem-buzei.
    ls_materialdata-material         = input-matnr."‘VBJHH05000000000‘."ls_baitem-matnr.
    ls_materialdata-val_area         = ‘6100‘."ls_baitem-bwkey.    "评估范围/工厂
    ls_materialdata-valuation_type   = ‘6100‘."ls_baitem-bwtar.    "评估类型
    ls_materialdata-db_cr_ind        = ‘S‘."ls_baitem-shkzg.    "借方/贷方标识
    ls_materialdata-item_amount      = ‘0‘."ls_baitem-wrbtr.
    ls_materialdata-quantity         = input-menge."ls_baitem-menge.
    SELECT SINGLE
           meins
           INTO ls_materialdata-base_uom
           FROM mara
           WHERE matnr = input-matnr.
*    ls_materialdata-base_uom         = ‘EA‘."ls_baitem-meins.
    ls_materialdata-tax_code         = lv_mwskz."ls_baitem-mwskz.
    APPEND ls_materialdata TO lt_materialdata.
    CLEAR: ls_materialdata.



    ls_taxdata-tax_code   = lv_mwskz."ls_taitem-mwskz.
    "    ls_taxdata-tax_amount = ‘‘."ls_taitem-wrbtr.
    APPEND ls_taxdata TO lt_taxdata.
    CLEAR: ls_taxdata.
  ENDLOOP.


  CALL FUNCTION ‘BAPI_INCOMINGINVOICE_PARK‘
    EXPORTING
      headerdata          = ls_headerdata
*     ADDRESSDATA         =
    IMPORTING
      invoicedocnumber    = lv_invoicedocnumber
      fiscalyear          = lv_fiscalyear
    TABLES
      itemdata            = lt_itemdata
*     ACCOUNTINGDATA      =
*     GLACCOUNTDATA       =
      materialdata        = lt_materialdata
      taxdata             = lt_taxdata
*     WITHTAXDATA         =
*     VENDORITEMSPLITDATA =
      return              = lt_return.

  IF lv_invoicedocnumber IS INITIAL OR lv_fiscalyear IS INITIAL.
    vp_eind = ‘X‘.
  ENDIF.


  IF vp_eind = ‘X‘.
    CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘.

    code = ‘1‘.
    LOOP AT lt_return INTO ls_return WHERE type = ‘E‘.
      IF message IS INITIAL.
        message = ls_return-message.
      ELSE.
        CONCATENATE message ‘;‘ ls_return-message INTO message.
      ENDIF.

      CONCATENATE ‘预制发票失败:‘ message INTO message.
    ENDLOOP.


  ELSE.
    CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘
      EXPORTING
        wait = ‘X‘.
    code = ‘0‘.
    CONCATENATE ‘预制发票成功,发票号:‘ lv_invoicedocnumber ‘发票年度:‘ lv_fiscalyear INTO message.
  ENDIF.



ENDFUNCTION.







































以上是关于函数使用五:MIR7 发票预制 BAPI_INCOMINGINVOICE_PARK的主要内容,如果未能解决你的问题,请参考以下文章

ABAP系列SAP ABAP MIR7预制凭证BAPI

[问题解决]创建预制发票(BAPI_INCOMINGINVOICE_PARK)时报错”采购凭证的帐户设置00不存在”

发票校验的差异科目如何转走

MIR7采购订单带出参考凭证 参考日期 增强

sap中凭证已过账,生成财务凭证,发现有错,有啥办发可以冲销

接入微信电子发票流程步骤