标签:else append rom art call optional res 日期 ice
引自: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
标签:else append rom art call optional res 日期 ice
原文地址:http://www.cnblogs.com/sapSB/p/6839372.html