ABAP-MIRO创建发票BAPI

 1 *发票bapi参数
 2 DATA:gs_headerdata TYPE bapi_incinv_create_header,
 3      gt_itemdata   TYPE TABLE OF bapi_incinv_create_item,
 4      gs_itemdata   TYPE bapi_incinv_create_item,
 5      gt_taxdata    TYPE TABLE OF bapi_incinv_create_tax,
 6      gs_taxdata    TYPE bapi_incinv_create_tax,
 7      gv_number     TYPE bapi_incinv_fld-inv_doc_no,
 8      gv_year       TYPE bapi_incinv_fld-fisc_year.
 9 
10 gs_headerdata-invoice_ind = 'X' .
11 gs_headerdata-doc_type = 'RE' ."单据类型(RE表示采购订单)
12 gs_headerdata-doc_date = sy-datum .
13 gs_headerdata-ref_doc_no = gv_docno .
14 gs_headerdata-comp_code = 'RIZJ' .
15 gs_headerdata-currency = 'CNY' .
16 gs_headerdata-pstng_date = sy-datum .
17 gs_headerdata-pmnttrms = '0005' .
18 gs_headerdata-bline_date = sy-datum .
19 
20 LOOP AT gt_vbrp ASSIGNING FIELD-SYMBOL(<fs_vbrp2>) .
21 
22   CLEAR gs_itemdata .
23   CLEAR gs_taxdata .
24 
25   gv_ebelp = gv_ebelp + 10 .
26   gs_headerdata-gross_amount = gs_headerdata-gross_amount + <fs_vbrp2>-netwr .
27 
28   gs_itemdata-invoice_doc_item = gv_ebelp .
29   gs_itemdata-po_number = gv_ebeln .
30   gs_itemdata-po_item = gv_ebelp .
31   gs_itemdata-tax_code = 'J0' .
32   gs_itemdata-item_amount = <fs_vbrp2>-netwr .
33   gs_itemdata-quantity = <fs_vbrp2>-fkimg .
34   gs_itemdata-po_unit = <fs_vbrp2>-vrkme .
35   APPEND gs_itemdata TO gt_itemdata .
36 
37   gs_taxdata-tax_code = 'J0' .
38   APPEND gs_taxdata TO gt_taxdata .
39 
40 ENDLOOP .
41 
42 CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
43   EXPORTING
44     headerdata       = gs_headerdata
45 *   ADDRESSDATA      =
46 *   OILDATA          =
47   IMPORTING
48     invoicedocnumber = gv_number
49     fiscalyear       = gv_year
50   TABLES
51     itemdata         = gt_itemdata
52 *   ACCOUNTINGDATA   =
53 *   GLACCOUNTDATA    =
54 *   MATERIALDATA     =
55     taxdata          = gt_taxdata
56 *   WITHTAXDATA      =
57 *   VENDORITEMSPLITDATA       =
58     return           = gt_return
59 *   EXTENSIONIN      =
60 *   TM_ITEMDATA      =
61 *   NFMETALLITMS     =
62 *   ASSETDATA        =
63   .
64 
65 IF line_exists( gt_return[ type = 'E' ] ) OR line_exists( gt_return[ type = 'A' ] ).
66 
67   CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
68 
69 ELSE.
70 
71   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
72     EXPORTING
73       wait = 'X'.
74 
75 ENDIF.
posted @ 2022-06-20 15:20  TigerMan  阅读(481)  评论(0编辑  收藏  举报