https://www.freesion.com/article/6364448776/
REPORT zmiro. DATA: g_ztype TYPE bapi_mtype, g_zmessage TYPE bapi_msg. DATA: wa_headerdata TYPE bapi_incinv_create_header. DATA: g_invoicedocnumber TYPE bapi_incinv_fld-inv_doc_no, g_fiscalyear TYPE bapi_incinv_fld-fisc_year, wa_itemdata TYPE bapi_incinv_create_item, it_itemdata LIKE STANDARD TABLE OF wa_itemdata, wa_taxdata TYPE bapi_incinv_create_tax, it_taxdata LIKE STANDARD TABLE OF wa_taxdata, wa_accountingdata TYPE bapi_incinv_create_account, it_accountingdata LIKE STANDARD TABLE OF wa_accountingdata, wa_materialdata TYPE bapi_incinv_create_material, it_materialdata LIKE STANDARD TABLE OF wa_materialdata, wa_glaccountdata TYPE bapi_incinv_create_gl_account, it_glaccountdata LIKE STANDARD TABLE OF wa_glaccountdata. DATA: g_rblgp TYPE rblgp. DATA: wa_return TYPE bapiret2, it_return LIKE STANDARD TABLE OF wa_return. *CLEAR: e_result. *SELECT SINGLE * belnr * gjahr * FROM rbkp * INTO (e_result-belnr, e_result-gjahr) * WHERE zuonr EQ iw_head-alloc_nmbr. *IF sy-subrc = 0. * e_result-msgtype = 'E'. * CONCATENATE 'FSSC单号:' * iw_head-alloc_nmbr * '已存在对应的过账发票' * INTO * e_result-msgtext. *ELSE. CLEAR: wa_headerdata. wa_headerdata-invoice_ind = 'X'. "记帐发票 wa_headerdata-doc_type = 'SA'. wa_headerdata-doc_date = sy-datum. wa_headerdata-pstng_date = sy-datum. *wa_headerdata-ref_doc_no = iw_head-ref_doc_no. wa_headerdata-comp_code = '8101'. *wa_headerdata-diff_inv = 'TEST04'. *wa_headerdata-diff_inv = |{ wa_headerdata-diff_inv ALPHA = IN }|. wa_headerdata-gross_amount = 0. wa_headerdata-currency = 'MXN'. wa_headerdata-header_txt = '123456765432'. wa_headerdata-pmnttrms = 'GA01'. *wa_headerdata-alloc_nmbr = iw_head-alloc_nmbr. CLEAR: it_taxdata. CLEAR:wa_taxdata. wa_taxdata-tax_code = 'V0'. wa_taxdata-tax_amount = 0. APPEND wa_taxdata TO it_taxdata. CLEAR: it_materialdata. *LOOP AT it_material INTO DATA(wa_material). CLEAR: wa_materialdata. wa_materialdata-invoice_doc_item = 1. wa_materialdata-material = 'AC1C-CB8-A0-R6-A'. CALL FUNCTION 'CONVERSION_EXIT_MATN5_INPUT' EXPORTING input = wa_materialdata-material IMPORTING output = wa_materialdata-material EXCEPTIONS length_error = 1 OTHERS = 2. wa_materialdata-val_area = '8101'. * wa_materialdata-valuation_type = wa_material-valuation_type. wa_materialdata-db_cr_ind = 'S'. wa_materialdata-item_amount = 1000. wa_materialdata-quantity = 1. wa_materialdata-base_uom = 'PC'. CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' EXPORTING input = wa_materialdata-base_uom * LANGUAGE = SY-LANGU IMPORTING output = wa_materialdata-base_uom EXCEPTIONS unit_not_found = 1 OTHERS = 2. wa_materialdata-tax_code = 'V0'. APPEND wa_materialdata TO it_materialdata. *ENDLOOP. CLEAR: it_glaccountdata. *LOOP AT it_glaccount INTO DATA(wa_glaccount). CLEAR: wa_glaccountdata. wa_glaccountdata-invoice_doc_item = 1. wa_glaccountdata-comp_code = '8101'. wa_glaccountdata-gl_account = '2221010001'. wa_glaccountdata-gl_account = |{ wa_glaccountdata-gl_account ALPHA = IN }|. wa_glaccountdata-item_amount = 600. wa_glaccountdata-db_cr_ind = 'H'. * wa_glaccountdata-costcenter = wa_glaccount-costcenter. * wa_glaccountdata-costcenter = |{ wa_glaccountdata-costcenter ALPHA = IN }|. * wa_glaccountdata-func_area = wa_glaccount-func_area. * wa_glaccountdata-profit_ctr = wa_glaccount-profit_ctr. * wa_glaccountdata-profit_ctr = |{ wa_glaccountdata-profit_ctr ALPHA = IN }|. wa_glaccountdata-plant = '8101'. *wa_glaccountdata-tax_code = 'V0'. APPEND wa_glaccountdata TO it_glaccountdata. CLEAR: wa_glaccountdata. wa_glaccountdata-invoice_doc_item = 2. wa_glaccountdata-comp_code = '8101'. wa_glaccountdata-gl_account = '2221130000'. wa_glaccountdata-gl_account = |{ wa_glaccountdata-gl_account ALPHA = IN }|. wa_glaccountdata-item_amount = 400. wa_glaccountdata-db_cr_ind = 'H'. * wa_glaccountdata-costcenter = wa_glaccount-costcenter. * wa_glaccountdata-costcenter = |{ wa_glaccountdata-costcenter ALPHA = IN }|. * wa_glaccountdata-func_area = wa_glaccount-func_area. * wa_glaccountdata-profit_ctr = wa_glaccount-profit_ctr. * wa_glaccountdata-profit_ctr = |{ wa_glaccountdata-profit_ctr ALPHA = IN }|. wa_glaccountdata-plant = '8101'. *wa_glaccountdata-tax_code = 'V0'. APPEND wa_glaccountdata TO it_glaccountdata. *ENDLOOP. SELECT * INTO TABLE @DATA(ut_out) FROM ekpo WHERE ebeln EQ '8500000187'. LOOP AT ut_out INTO DATA(ls_out). wa_itemdata-invoice_doc_item = sy-tabix. wa_itemdata-po_number = ls_out-ebeln. "ENTER THE PO NUMBER wa_itemdata-po_item = ls_out-ebelp. "ENTER THE PO ITEM NUMBER wa_itemdata-tax_code = 'V0'. "税码 * wa_itemdata-item_amount = '1000'. "不含税金额 * wa_itemdata-quantity = ls_out-menge. "数量 * wa_itemdata-po_unit = ls_out-meins. "单位 wa_itemdata-de_cre_ind = 'X'. *IF ls_alv-zdoc055 IS NOT INITIAL. SELECT SINGLE matdoc~lfbnr matdoc~lfbja matdoc~lfpos INTO ( wa_itemdata-ref_doc, wa_itemdata-ref_doc_year, wa_itemdata-ref_doc_it ) FROM matdoc WHERE ebeln EQ ls_out-ebeln AND ebelp EQ ls_out-ebelp . *wa_itemdata-item_text = p_sh. "税号 APPEND wa_itemdata TO it_itemdata. ENDLOOP. CLEAR: g_ztype, g_zmessage. CLEAR: g_invoicedocnumber, g_fiscalyear, it_return. CALL FUNCTION 'MESSAGES_INITIALIZE'. CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE' EXPORTING headerdata = wa_headerdata * ADDRESSDATA = IMPORTING invoicedocnumber = g_invoicedocnumber fiscalyear = g_fiscalyear TABLES itemdata = it_itemdata * ACCOUNTINGDATA = glaccountdata = it_glaccountdata materialdata = it_materialdata taxdata = it_taxdata * WITHTAXDATA = * VENDORITEMSPLITDATA = return = it_return * EXTENSIONIN = * TM_ITEMDATA = * NFMETALLITMS = * ASSETDATA = . LOOP AT it_return INTO wa_return WHERE type = 'A' OR type = 'E'. EXIT. ENDLOOP. IF sy-subrc = 0. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' . LOOP AT it_return INTO wa_return WHERE type = 'A' OR type = 'E'. CONCATENATE g_zmessage wa_return-message INTO g_zmessage. ENDLOOP. g_ztype = 'E'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X' * IMPORTING * RETURN = . g_ztype = 'S'. CONCATENATE '预制发票' g_invoicedocnumber '年度' g_fiscalyear ',创建成功!' INTO g_zmessage. * e_result-belnr = g_invoicedocnumber. * e_result-gjahr = g_fiscalyear. ENDIF. *e_result-msgtype = g_ztype. *e_result-msgtext = g_zmessage. *ENDIF.
标签:MIRO,itemdata,wa,glaccountdata,MIR7,SAP,TYPE,headerdata,materialdata From: https://www.cnblogs.com/ZJY-1314/p/17645141.html