录制MIRO的方法 function zfeis_miro_recorder . *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" REFERENCE(HEADERDATA) LIKE BAPI_INCINV_CREATE_HEADER STRUCTURE *" BAPI_INCINV_CREATE_HEADER *" REFERENCE(ZUONR) TYPE DZUONR *" REFERENCE(CHARG) TYPE BCROOM *" REFERENCE(INVOICE) TYPE XBLNR *" EXPORTING *" VALUE(INVOICEDOCNUMBER) LIKE BAPI_INCINV_FLD-INV_DOC_NO *" VALUE(FISCALYEAR) LIKE BAPI_INCINV_FLD-FISC_YEAR *" TABLES *" ITEMDATA STRUCTURE BAPI_INCINV_CREATE_ITEM *" ACCOUNTINGDATA STRUCTURE BAPI_INCINV_CREATE_ACCOUNT OPTIONAL *" GLACCOUNTDATA STRUCTURE BAPI_INCINV_CREATE_MATERIAL OPTIONAL *" MATERIALDATA STRUCTURE BAPI_INCINV_CREATE_MATERIAL OPTIONAL *" TAXDATA STRUCTURE BAPI_INCINV_CREATE_TAX OPTIONAL *" WITHTAXDATA STRUCTURE BAPI_INCINV_CREATE_WITHTAX OPTIONAL *" VENDORITEMSPLITDATA STRUCTURE BAPI_INCINV_CREATE_VENDORSPLIT *" OPTIONAL *" RETURN STRUCTURE BAPIRET2 OPTIONAL *"---------------------------------------------------------------------- * Created by amao 2007-08-24 * Modify log: data: lv_val01(16) type c, lv_val02(16) type c, lv_val03(16) type c, lv_dmbtr like bseg-dmbtr, lv_menge like bseg-menge. data: save_tabix(2) type c. type-pools: mmcr, mrm. data: f_display like boole-boole, tab_drseg_old type mmcr_tdrseg, rbkpv type mrm_rbkpv, xlimit type mmcr_tlimit, ydrseg type mmcr_drseg occurs 1 with header line, t_errprot type mrm_errprot occurs 100 with header line, t_ebelntab type table of ebelntab with header line. data: begin of xmsel_best occurs 1. include structure rbselbest. data: end of xmsel_best. *------- Mehrfachselektion Lieferschein ------------------------------* data: begin of ymsel_lifs occurs 1. include structure rbsellifs. data: end of ymsel_lifs. data: begin of xmsel_lifs occurs 1. include structure rbsellifs. data: end of xmsel_lifs. *------- Mehrfachselektion Erfassungsbl鋞ter -------------------------* data: begin of ymsel_erfb occurs 1. include structure rbselerfb. data: end of ymsel_erfb. data: begin of xmsel_erfb occurs 1. include structure rbselerfb. data: end of xmsel_erfb. *------- Mehrfachselektion Frachtbrief -------------------------------* data: begin of ymsel_frbr occurs 1. include structure rbselfrbr. data: end of ymsel_frbr. data: begin of xmsel_frbr occurs 1. include structure rbselfrbr. data: end of xmsel_frbr. *------- Mehrfachselektion Werk --------------------------------------* data: begin of ymsel_werk occurs 1. include structure rbselwerk. data: end of ymsel_werk. data: begin of xmsel_werk occurs 1. include structure rbselwerk. data: end of xmsel_werk. *------- Mehrfachselektion Transport zum Lieferant -------------------* data: begin of ymsel_tran occurs 1. include structure eksel. data: end of ymsel_tran. data: begin of xmsel_tran occurs 1. include structure letra_iv_fields. data: end of xmsel_tran. *-- Bezug auf Lieferant, Tabelle Zuordnung ---------------------------* data: begin of t_msel_zuord occurs 1, xzuord like rbkpb-xzuordli, xtext(20), lfdatab like rbkpb-lfdatabli, lfdatbis like rbkpb-lfdatbisli, pos_shkzg like rm08m-posl_shkzg, end of t_msel_zuord. * 执行事务'MIRO' refresh: t_bdc, t_bdcmsg. * 1,更改公司代码 perform fm_set_bdc: tables t_bdc using 'X' 'SAPLACHD' '1000', tables t_bdc using ' ' 'BDC_OKCODE' '=ENTR', tables t_bdc using ' ' 'BKPF-BUKRS' '8200', tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '/ENEWCC', tables t_bdc using ' ' 'INVFO-BLDAT' headerdata-doc_date, tables t_bdc using ' ' 'INVFO-BUDAT' headerdata-pstng_date, tables t_bdc using ' ' 'INVFO-XBLNR' headerdata-ref_doc_no, tables t_bdc using 'X' 'SAPLACHD' '1000', tables t_bdc using ' ' 'BDC_OKCODE' '=ENTR', tables t_bdc using ' ' 'BKPF-BUKRS' '8200'. * 1-1,第一屏幕为输入公司代码(帐户登陆首次用MIRO时需要输入公司代码) call transaction 'MIRO' using t_bdc mode 'N' "Background performance update 'S' "local updata messages into t_bdcmsg. "all message table * 1-2,第一屏幕不输入公司代码(系统默认为上次操作的公司代码) delete t_bdc from 1 to 3. call transaction 'MIRO' using t_bdc mode 'N' "Background performance update 'S' "local updata messages into t_bdcmsg. "all message table read table itemdata index 1. * 2,查找条件类型或参考(物料凭证)对应的发票项目号 xmsel_best-gjahr = sy-datum(4). xmsel_best-ebeln = itemdata-po_number. xmsel_best-ebelp = itemdata-po_item. append xmsel_best. select single * from ekko as a where a~ebeln eq itemdata-po_number. rbkpv-gjahr = sy-datum(4). rbkpv-budat = sy-datum. rbkpv-bldat = sy-datum. rbkpv-xblnr = invoice. rbkpv-bukrs = ekko-bukrs. rbkpv-lifnr = ekko-lifnr. rbkpv-waers = ekko-waers. rbkpv-kursf = ekko-wkurs. rbkpv-mwskz1 = itemdata-tax_code. rbkpv-xzuordli = 'X'. rbkpv-xzuordrt = 'X'. if not itemdata-cond_type is initial. rbkpv-xbnk = 'X'. rbkpv-xware = ''. else. rbkpv-xbnk = ''. rbkpv-xware = 'X'. endif. rbkpv-xbest = 'X'. export xmsel_best to memory id 'xmsel_best'. export rbkpv to memory id 'rbkpv'. submit zmrm_assignment and return. import ydrseg to ydrseg from memory id 'ydrseg'. * 3,录入数据 loop at itemdata. refresh: t_bdc, t_bdcmsg. clear: lv_val01, lv_val02, t_bdc, t_bdcmsg. move headerdata-gross_amount to lv_dmbtr. move lv_dmbtr to lv_val01. clear lv_dmbtr. move itemdata-item_amount to lv_dmbtr. move lv_dmbtr to lv_val02. move itemdata-quantity to lv_menge. move lv_menge to lv_val03. clear lv_menge. perform fm_set_bdc: tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '/00', tables t_bdc using ' ' 'RM08M-VORGANG' '1', tables t_bdc using ' ' 'INVFO-BLDAT' headerdata-doc_date, tables t_bdc using ' ' 'INVFO-BUDAT' headerdata-pstng_date, tables t_bdc using ' ' 'INVFO-XBLNR' headerdata-ref_doc_no, tables t_bdc using ' ' 'INVFO-WAERS' headerdata-currency, tables t_bdc using ' ' 'INVFO-MWSKZ' itemdata-tax_code, tables t_bdc using ' ' 'INVFO-SGTXT' charg, tables t_bdc using ' ' 'RM08M-REFERENZBELEGTYP' '1', tables t_bdc using ' ' 'RM08M-EBELN' itemdata-po_number, tables t_bdc using ' ' 'RM08M-EBELP' itemdata-po_item. case itemdata-cond_type. * 3-1,本金 when ''. perform fm_set_bdc: tables t_bdc using ' ' 'RM08M-XWARE_BNK' '1'. when others. * 3-2,费用 perform fm_set_bdc: tables t_bdc using ' ' 'RM08M-XWARE_BNK' '2'. endcase. perform fm_set_bdc: tables t_bdc using ' ' 'RM08M-ITEM_LIST_VERSION' '7_6310', tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '=ADMA'. case itemdata-cond_type. * 3-1,本金 when ''. loop at ydrseg where ebeln eq itemdata-po_number and ebelp eq itemdata-po_item and lfbnr eq itemdata-ref_doc. clear save_tabix. move sy-tabix to save_tabix. perform fm_set_bdc: tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '=POS', tables t_bdc using ' ' 'RM08M-SKIP_TO' save_tabix, tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '/00', tables t_bdc using ' ' 'DRSEG-WRBTR(01)' lv_val02, tables t_bdc using ' ' 'DRSEG-MENGE(01)' lv_val03. endloop. * 3-2,费用 when others. loop at ydrseg where ebeln = itemdata-po_number and ebelp = itemdata-po_item and kschl = itemdata-cond_type. clear save_tabix. move sy-tabix to save_tabix. perform fm_set_bdc: tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '=POS', tables t_bdc using ' ' 'RM08M-SKIP_TO' save_tabix, tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '/00', tables t_bdc using ' ' 'DRSEG-WRBTR(01)' lv_val02, tables t_bdc using ' ' 'DRSEG-MENGE(01)' lv_val03. endloop. endcase. perform fm_set_bdc: tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '=DUMMY', tables t_bdc using ' ' 'INVFO-XMWST' 'X', tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '=HEADER_PAY', tables t_bdc using ' ' 'INVFO-WRBTR' lv_val01, tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '=HEADER_FI', tables t_bdc using 'X' 'SAPLMR1M' '6000', tables t_bdc using ' ' 'BDC_OKCODE' '=BU', tables t_bdc using ' ' 'INVFO-ZUONR' zuonr, tables t_bdc using ' ' 'INVFO-BKTXT' '国际事务处请款'. call transaction 'MIRO' using t_bdc mode v_mode "Background performance update 'S' "local updata messages into t_bdcmsg. "all message table case itemdata-cond_type. when ''. read table t_bdcmsg with key msgtyp = 'S' msgid = 'M8' msgnr = '060'. if sy-subrc eq 0. return-type = 'S'. invoicedocnumber = t_bdcmsg-msgv1. fiscalyear = sy-datum(4). message id t_bdcmsg-msgid type 'S' number t_bdcmsg-msgnr with t_bdcmsg-msgv1 t_bdcmsg-msgv2 t_bdcmsg-msgv3 t_bdcmsg-msgv4 into return-message. append return. clear return. else. loop at t_bdcmsg. return-type = 'E'. message id t_bdcmsg-msgid type 'S' number t_bdcmsg-msgnr with t_bdcmsg-msgv1 t_bdcmsg-msgv2 t_bdcmsg-msgv3 t_bdcmsg-msgv4 into return-message. append return. clear return. endloop. endif. when others. read table t_bdcmsg with key msgtyp = 'S' msgid = 'M8' msgnr = '075'. if sy-subrc eq 0. return-type = 'S'. invoicedocnumber = t_bdcmsg-msgv1. fiscalyear = sy-datum(4). message id t_bdcmsg-msgid type 'S' number t_bdcmsg-msgnr with t_bdcmsg-msgv1 t_bdcmsg-msgv2 t_bdcmsg-msgv3 t_bdcmsg-msgv4 into return-message. append return. clear return. else. loop at t_bdcmsg. return-type = 'E'. message id t_bdcmsg-msgid type 'S' number t_bdcmsg-msgnr with t_bdcmsg-msgv1 t_bdcmsg-msgv2 t_bdcmsg-msgv3 t_bdcmsg-msgv4 into return-message. append return. clear return. endloop. endif. endcase. endloop. endfunction. zmrm_assignment and return: report zmrm_assignment . *Created by amao 2007-08-24 *Modify log: type-pools: mmcr, mrm. data: f_display like boole-boole, tab_drseg_old type mmcr_tdrseg, rbkpv type mrm_rbkpv, xlimit type mmcr_tlimit, ydrseg type mmcr_drseg occurs 1 with header line, t_errprot type mrm_errprot occurs 100 with header line, t_ebelntab type table of ebelntab with header line. data: begin of xmsel_best occurs 1. include structure rbselbest. data: end of xmsel_best. *------- Mehrfachselektion Lieferschein ------------------------------* data: begin of ymsel_lifs occurs 1. include structure rbsellifs. data: end of ymsel_lifs. data: begin of xmsel_lifs occurs 1. include structure rbsellifs. data: end of xmsel_lifs. *------- Mehrfachselektion Erfassungsbl鋞ter -------------------------* data: begin of ymsel_erfb occurs 1. include structure rbselerfb. data: end of ymsel_erfb. data: begin of xmsel_erfb occurs 1. include structure rbselerfb. data: end of xmsel_erfb. *------- Mehrfachselektion Frachtbrief -------------------------------* data: begin of ymsel_frbr occurs 1. include structure rbselfrbr. data: end of ymsel_frbr. data: begin of xmsel_frbr occurs 1. include structure rbselfrbr. data: end of xmsel_frbr. *------- Mehrfachselektion Werk --------------------------------------* data: begin of ymsel_werk occurs 1. include structure rbselwerk. data: end of ymsel_werk. data: begin of xmsel_werk occurs 1. include structure rbselwerk. data: end of xmsel_werk. *------- Mehrfachselektion Transport zum Lieferant -------------------* data: begin of ymsel_tran occurs 1. include structure eksel. data: end of ymsel_tran. data: begin of xmsel_tran occurs 1. include structure letra_iv_fields. data: end of xmsel_tran. *-- Bezug auf Lieferant, Tabelle Zuordnung ---------------------------* data: begin of t_msel_zuord occurs 1, xzuord like rbkpb-xzuordli, xtext(20), lfdatab like rbkpb-lfdatabli, lfdatbis like rbkpb-lfdatbisli, pos_shkzg like rm08m-posl_shkzg, end of t_msel_zuord. import xmsel_best to xmsel_best from memory id 'xmsel_best'. import rbkpv from memory id 'rbkpv'. call function 'MRM_ASSIGNMENT' tables t_drseg = ydrseg t_rbselbest = xmsel_best t_rbsellifs = xmsel_lifs t_rbselfrbr = xmsel_frbr t_rbselwerk = xmsel_werk t_rbselerfb = xmsel_erfb t_errprot = t_errprot changing c_rbkpv = rbkpv t_limit = xlimit. export ydrseg to memory id 'ydrseg'.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/617619/viewspace-224895/,如需转载,请注明出处,否则将追究法律责任。