*&---------------------------------------------------------------------*
*&      Form  FRM_INCOMINGINVOICE_PARK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LT_POITEM  text
*      -->P_LT_BAITEM  text
*      -->P_LT_TAITEM  text
*      -->P_LT_MSG  text
*      -->P_LS_HEAD  text
*      <--P_LV_EIND  text
*----------------------------------------------------------------------*
FORM frm_incominginvoice_park  TABLES   tp_poitem STRUCTURE zrmxmms013
                                        tp_baitem STRUCTURE zrmxmms014
                                        tp_taitem STRUCTURE zrmxmms015
                                        tp_msg STRUCTURE zifsret01
                               USING    sp_head LIKE zrmxmms012
                                        sp_ifdataout LIKE zifrmx_dataout_007p01
                               CHANGING vp_eind.

 


  DATA: lt_poitem     TYPE zifrmx_datain_007p01-po_item,
        ls_poitem     TYPE LINE OF zifrmx_datain_007p01-po_item,
        lt_baitem     TYPE zifrmx_datain_007p01-ba_item,
        ls_baitem     TYPE LINE OF zifrmx_datain_007p01-ba_item,
        lt_taitem     TYPE zifrmx_datain_007p01-ta_item,
        ls_taitem     TYPE LINE OF zifrmx_datain_007p01-ta_item,
        ls_msg        TYPE zifsret01,

        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.


*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赋值
  ls_headerdata-invoice_ind  = sp_head-xrech.    "发票标志
  ls_headerdata-doc_type     = sp_head-blart.
  ls_headerdata-doc_date     = sp_head-bldat.
  ls_headerdata-pstng_date   = sp_head-budat.
  ls_headerdata-bline_date   = sp_head-zfbdt.    "基线日期/付款计算的起始日期
  ls_headerdata-comp_code    = sp_head-bukrs.
  ls_headerdata-currency     = sp_head-waers.
  ls_headerdata-gross_amount = 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   = sp_head-bktxt.
  ls_headerdata-item_text    = sp_head-sgtxt.


  LOOP AT tp_poitem INTO ls_poitem.
    ls_itemdata-invoice_doc_item = ls_poitem-buzei.   "发票行项目号
    ls_itemdata-po_number        = ls_poitem-ebeln.
    ls_itemdata-po_item          = ls_poitem-ebelp.
    ls_itemdata-ref_doc          = ls_poitem-lfbnr.
    ls_itemdata-ref_doc_year     = ls_poitem-lfgja.
    ls_itemdata-ref_doc_it       = ls_poitem-lfpos.
    ls_itemdata-item_amount      = ls_poitem-wrbtr.
    ls_itemdata-quantity         = ls_poitem-menge.
    ls_itemdata-po_unit          = ls_poitem-meins.
    ls_itemdata-tax_code         = ls_poitem-mwskz.
    ls_itemdata-de_cre_ind       = ls_poitem-tbtkz.   "标识:后续借/贷
    ls_itemdata-cond_type        = ls_poitem-kschl.   "条件类型
    ls_itemdata-freight_ven      = ls_poitem-lifnr.   "供应商或债权人的帐号
    APPEND ls_itemdata TO lt_itemdata.
    CLEAR: ls_itemdata.
  ENDLOOP.


  LOOP AT tp_baitem INTO ls_baitem.
    ls_materialdata-invoice_doc_item = ls_baitem-buzei.
    ls_materialdata-material         = ls_baitem-matnr.
    ls_materialdata-val_area         = ls_baitem-bwkey.    "评估范围/工厂
    ls_materialdata-valuation_type   = ls_baitem-bwtar.    "评估类型
    ls_materialdata-db_cr_ind        = ls_baitem-shkzg.    "借方/贷方标识
    ls_materialdata-item_amount      = ls_baitem-wrbtr.
    ls_materialdata-quantity         = ls_baitem-menge.
    ls_materialdata-base_uom         = ls_baitem-meins.
    ls_materialdata-tax_code         = ls_baitem-mwskz.
    APPEND ls_materialdata TO lt_materialdata.
    CLEAR: ls_materialdata.
  ENDLOOP.


  LOOP AT tp_taitem INTO ls_taitem.
    ls_taxdata-tax_code   = 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'.

    LOOP AT lt_return INTO ls_return.
      ls_msg-class   = 'BUS'.
      ls_msg-msgtyp  = ls_return-type.
      ls_msg-msgno   = ls_return-number.
      ls_msg-msgtxt  = ls_return-message.
      APPEND ls_msg TO tp_msg.
      CLEAR ls_msg.
    ENDLOOP.

  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait 'X'.

    sp_ifdataout-eblnr = lv_invoicedocnumber.
    sp_ifdataout-gjahr = lv_fiscalyear.

  ENDIF.


ENDFORM.                    " FRM_INCOMINGINVOICE_PARK

posted on 2010-08-23 10:54  zhumk  阅读(3548)  评论(0编辑  收藏  举报