METHOD document_post.
DATA ls_documentheader TYPE bapiache09. "表头
DATA ls_accountgl TYPE bapiacgl09.
DATA lt_accountgl TYPE STANDARD TABLE OF bapiacgl09. "总账项目
DATA ls_accountreceivable TYPE bapiacar09.
DATA lt_accountreceivable TYPE STANDARD TABLE OF bapiacar09. "客户项目
DATA ls_accountpayable TYPE bapiacap09.
DATA lt_accountpayable TYPE STANDARD TABLE OF bapiacap09. "供应商项目
DATA ls_currencyamount TYPE bapiaccr09.
DATA lt_currencyamount TYPE STANDARD TABLE OF bapiaccr09. "货币项目
DATA lt_currencyamount_tax TYPE STANDARD TABLE OF bapiaccr09. "货币项目
DATA ls_extension2 TYPE bapiparex.
DATA lt_extension2 TYPE STANDARD TABLE OF bapiparex. "扩展
DATA lt_criteria TYPE STANDARD TABLE OF bapiackec9. "COPA字段表
DATA ls_accounttax TYPE bapiactx09.
DATA lt_accounttax TYPE STANDARD TABLE OF bapiactx09.
DATA lv_obj_type TYPE bapiache09-obj_type.
DATA lv_obj_key TYPE bapiache09-obj_key.
DATA lv_obj_sys TYPE bapiache09-obj_sys.
DATA ls_return TYPE bapiret2.
DATA lt_return TYPE TABLE OF bapiret2.
DATA ls_mwdat TYPE rtax1u15.
DATA lt_mwdat TYPE STANDARD TABLE OF rtax1u15.
*行项目扩展
DATA ls_fi003 TYPE zsfi003.
DATA ls_fi004 TYPE zsfi004.
DATA ls_et_return TYPE LINE OF ztt_zsapex001.
DATA et_return TYPE ztt_zsapex001.
DATA lv_line_no TYPE i.
DATA lv_has_error TYPE c VALUE ''.
DATA ls_result TYPE zsfi_return.
* 定义日志变量
DATA lv_xml_in TYPE string.
DATA lv_xml_out TYPE string.
DATA lv_guid TYPE guid_32.
DATA ls_ztfi009 TYPE ztfi009.
*票据 ZSFI007
DATA ls_zsfi007 TYPE zsfi007. "票据
DATA lt_zsfi007 TYPE STANDARD TABLE OF zsfi007. "票据
CLEAR:ev_belnr,ev_gjahr,ev_rtype,ev_rtmsg.
* 凭证检查
document_check( EXPORTING is_bkpf = is_bkpf
CHANGING it_bseg = it_bseg
et_result = et_result ).
READ TABLE et_result TRANSPORTING NO FIELDS WITH KEY msgts = 'E'.
IF sy-subrc EQ 0.
ev_rtype = 'E'.
ev_rtmsg = '会计凭证过账失败'(002).
EXIT.
ENDIF.
CLEAR et_result.
*过帐码类型
SELECT * INTO TABLE @DATA(lt_tbsl)
FROM tbsl.
SORT lt_tbsl BY bschl.
CLEAR ls_documentheader.
CLEAR lt_accountgl.
CLEAR lt_accountreceivable.
CLEAR lt_accountpayable.
CLEAR lt_currencyamount.
CLEAR lt_criteria.
CLEAR lt_zsfi007.
CLEAR lt_extension2.
CLEAR lt_accounttax.
CLEAR lt_currencyamount_tax.
*凭证抬头赋值
ls_documentheader-comp_code = is_bkpf-bukrs. "公司代码
ls_documentheader-doc_type = is_bkpf-blart. "凭证类型
ls_documentheader-pstng_date = is_bkpf-budat. "记账日期
ls_documentheader-doc_date = is_bkpf-bldat. "凭证日期
ls_documentheader-fis_period = is_bkpf-monat. "会计期间
ls_documentheader-header_txt = is_bkpf-bktxt. "抬头文本
ls_documentheader-ref_doc_no = is_bkpf-xblnr. "参考凭证
ls_documentheader-username = sy-uname. "用户名
ls_documentheader-obj_type = is_bkpf-awtyp. "参考过程
ls_documentheader-obj_key = is_bkpf-awkey. "对象键值
ls_documentheader-glo_ref1_hd = is_bkpf-glo_ref1_hd. "凭证中的国家/地区特定的参考 1
ls_documentheader-glo_ref4_hd = is_bkpf-glo_ref4_hd. "凭证中的国家/地区特定的参考 4
lv_has_error = ''."用于判断行项目是否存在异常,如果存在跳出该凭证
*表头扩展
CLEAR ls_extension2.
IF is_bkpf-ldgrp IS NOT INITIAL.
ls_extension2-structure = 'ZSFI002'.
ls_extension2-valuepart1 = is_bkpf-ldgrp. "分类账组
APPEND ls_extension2 TO lt_extension2.
ENDIF.
*预制凭证
CLEAR ls_extension2.
IF iv_test EQ 'X'.
ls_extension2-structure = 'PARK'.
APPEND ls_extension2 TO lt_extension2.
ENDIF.
CLEAR: ls_fi004.
"ls_fi004-xblnr_alt = is_bkpf-xblnr_alt."备选参考
ls_fi004-xref1_hd = is_bkpf-xref1_hd."参考码 (标题) 1
zcl_pass=>zsfi004 = ls_fi004.
SORT it_bseg BY buzei.
lv_line_no = 1.
LOOP AT it_bseg ASSIGNING FIELD-SYMBOL(<fs_bseg>).
CLEAR ls_et_return.
READ TABLE lt_tbsl INTO DATA(ls_tbsl) WITH KEY bschl = <fs_bseg>-bschl BINARY SEARCH.
IF ls_tbsl-koart = 'D' . "客户项目
CLEAR ls_accountreceivable.
ls_accountreceivable-pmnttrms = <fs_bseg>-zterm. "付款条件
ls_accountreceivable-profit_ctr = <fs_bseg>-prctr. " 利润中心
ls_accountreceivable-itemno_acc = <fs_bseg>-buzei. "会计凭证行项目编号
ls_accountreceivable-customer = <fs_bseg>-kunnr. "客户编号
ls_accountreceivable-gl_account = <fs_bseg>-hkont.
ls_accountreceivable-sp_gl_ind = <fs_bseg>-umskz. "特别总账标识
ls_accountreceivable-tax_code = <fs_bseg>-mwskz. "税码
ls_accountreceivable-bline_date = <fs_bseg>-zfbdt. "基准日期
ls_accountreceivable-alloc_nmbr = <fs_bseg>-zuonr. "分配编号
ls_accountreceivable-item_text = <fs_bseg>-sgtxt. "行项目文本
ls_accountreceivable-ref_key_1 = <fs_bseg>-xref1. "参考1
ls_accountreceivable-ref_key_2 = <fs_bseg>-xref2. "参考2
ls_accountreceivable-ref_key_3 = <fs_bseg>-xref3. "参考3
ls_accountreceivable-sepa_mandate_id = <fs_bseg>-mndid."托管参考
IF NOT <fs_bseg>-bseg_zfbdt IS INITIAL.
ls_accountreceivable-bline_date = <fs_bseg>-bseg_zfbdt ."
ENDIF.
"应收票据 票据号. 写入行项目文本
IF NOT <fs_bseg>-bseg_zuonr IS INITIAL
AND ( <fs_bseg>-umskz = '1' OR <fs_bseg>-umskz = '2' ).
ls_accountreceivable-item_text = <fs_bseg>-bseg_zuonr."票据号.
ENDIF.
APPEND ls_accountreceivable TO lt_accountreceivable.
*应收票据 当特殊总账为1或者2时,需要添加票据
IF <fs_bseg>-umskz = '1' OR <fs_bseg>-umskz = '2'.
MOVE-CORRESPONDING <fs_bseg> TO ls_zsfi007.
READ TABLE it_bsed INTO DATA(ls_bsed) WITH KEY buzei = <fs_bseg>-buzei.
IF sy-subrc = 0.
MOVE-CORRESPONDING ls_bsed TO ls_zsfi007.
ENDIF.
ls_zsfi007-banks = <fs_bseg>-banks."银行所属国家/地区代码
ls_zsfi007-bankl = ls_bsed-bank."银行代码
ls_zsfi007-bankn = ls_bsed-accou."银行账户号码
ls_zsfi007-posnr = <fs_bseg>-buzei.
APPEND ls_zsfi007 TO lt_zsfi007.
CLEAR:ls_zsfi007,ls_bsed.
ENDIF.
ELSEIF ls_tbsl-koart = 'K'. "供应商项目
CLEAR ls_accountpayable.
ls_accountpayable-pmnttrms = <fs_bseg>-zterm. "付款条件
ls_accountpayable-profit_ctr = <fs_bseg>-prctr. " 利润中心
ls_accountpayable-itemno_acc = <fs_bseg>-buzei. "会计凭证行项目编号
ls_accountpayable-vendor_no = <fs_bseg>-lifnr. "供应商编号
ls_accountpayable-gl_account = <fs_bseg>-hkont.
ls_accountpayable-sp_gl_ind = <fs_bseg>-umskz. "特别总账标识
ls_accountpayable-tax_code = <fs_bseg>-mwskz. "税码
ls_accountpayable-bline_date = <fs_bseg>-zfbdt. "基准日期
ls_accountpayable-alloc_nmbr = <fs_bseg>-zuonr. "分配编号
ls_accountpayable-item_text = <fs_bseg>-sgtxt. "行项目文本
ls_accountpayable-ref_key_1 = <fs_bseg>-xref1. "参考1
ls_accountpayable-ref_key_2 = <fs_bseg>-xref2. "参考2
ls_accountpayable-ref_key_3 = <fs_bseg>-xref3. "参考3
ls_accountpayable-pmnt_block = <fs_bseg>-zlspr . "收付款冻结码
IF NOT <fs_bseg>-bseg_zfbdt IS INITIAL.
ls_accountpayable-bline_date = <fs_bseg>-bseg_zfbdt ."到期日
ENDIF.
IF NOT <fs_bseg>-bseg_zuonr IS INITIAL
AND ( <fs_bseg>-umskz = 'T' OR <fs_bseg>-umskz = 'W').
ls_accountpayable-item_text = <fs_bseg>-bseg_zuonr."票据号
ENDIF.
APPEND ls_accountpayable TO lt_accountpayable.
* 应付票据 当特殊总账为T或者W时,需要添加票据
IF <fs_bseg>-umskz = 'T' OR <fs_bseg>-umskz = 'W'.
MOVE-CORRESPONDING <fs_bseg> TO ls_zsfi007.
READ TABLE it_bsed INTO ls_bsed WITH KEY buzei = <fs_bseg>-buzei.
IF sy-subrc = 0.
MOVE-CORRESPONDING ls_bsed TO ls_zsfi007.
ENDIF.
ls_zsfi007-banks = <fs_bseg>-banks."银行所属国家/地区代码
ls_zsfi007-bankl = ls_bsed-bank."银行代码
ls_zsfi007-bankn = ls_bsed-accou."银行账户号码
ls_zsfi007-posnr = <fs_bseg>-buzei.
APPEND ls_zsfi007 TO lt_zsfi007.
CLEAR:ls_zsfi007,ls_bsed.
ENDIF.
ELSEIF ls_tbsl-koart = 'S' OR ls_tbsl-koart = 'A'."总账科目&资产科目"
CLEAR ls_accountgl.
ls_accountgl-itemno_acc = <fs_bseg>-buzei. "会计凭证行项目编号
ls_accountgl-gl_account = <fs_bseg>-hkont. " 总账科目 (供应商/客户号/总账科目/资产科目)
ls_accountgl-costcenter = <fs_bseg>-kostl. " 成本中心
ls_accountgl-profit_ctr = COND #( WHEN <fs_bseg>-prctr IS NOT INITIAL THEN <fs_bseg>-prctr ELSE ls_accountgl-profit_ctr ). " 利润中心
ls_accountgl-orderid = <fs_bseg>-aufnr. "内部订单
ls_accountgl-trade_id = <fs_bseg>-vbund. "VBUND 贸易伙伴的公司代码
ls_accountgl-tax_code = <fs_bseg>-mwskz. "税码
ls_accountgl-func_area = <fs_bseg>-fkber. "功能范围
ls_accountgl-plant = <fs_bseg>-werks. "工厂
ls_accountgl-material = <fs_bseg>-matnr. "物料
ls_accountgl-quantity = <fs_bseg>-menge. "数量
ls_accountgl-base_uom = <fs_bseg>-meins. "单位
ls_accountgl-alloc_nmbr = <fs_bseg>-zuonr. "分配编号
ls_accountgl-item_text = <fs_bseg>-sgtxt. "行项目文本
ls_accountgl-ref_key_1 = <fs_bseg>-xref1. "参考1
ls_accountgl-ref_key_2 = <fs_bseg>-xref2. "参考2
ls_accountgl-ref_key_3 = <fs_bseg>-xref3. "参考3
ls_accountgl-po_number = COND #( WHEN <fs_bseg>-ebeln IS NOT INITIAL THEN <fs_bseg>-ebeln ELSE ls_accountgl-po_number ) ."采购凭证
ls_accountgl-po_item = COND #( WHEN <fs_bseg>-ebelp IS NOT INITIAL THEN <fs_bseg>-ebelp ELSE ls_accountgl-po_item )."采购凭证行项目
ls_accountgl-wbs_element = COND #( WHEN <fs_bseg>-posid IS NOT INITIAL THEN <fs_bseg>-posid ELSE ls_accountgl-wbs_element )." WBS元素
ls_accountgl-asset_no = <fs_bseg>-anln1."主资产号
IF ls_accountgl-asset_no IS NOT INITIAL.
ls_accountgl-sub_number = '0000'."次资产号
ls_accountgl-acct_type = 'A'.
ENDIF.
APPEND ls_accountgl TO lt_accountgl.
ENDIF.
* 凭证金额*货币项目
IF <fs_bseg>-wrbtr IS NOT INITIAL.
CLEAR ls_currencyamount.
ls_currencyamount-itemno_acc = <fs_bseg>-buzei. "货币行项目
ls_currencyamount-curr_type = '00'. "凭证货币
ls_currencyamount-currency = is_bkpf-waers.
ls_currencyamount-amt_doccur = <fs_bseg>-wrbtr . "凭证金额
*日元处理
change_amount_to_sapdiaplay( EXPORTING currency = ls_currencyamount-currency
CHANGING amt_doccur = ls_currencyamount-amt_doccur ).
IF ls_tbsl-shkzg = 'H' .
ls_currencyamount-amt_doccur = 0 - ls_currencyamount-amt_doccur .
ENDIF.
ls_currencyamount-exch_rate = is_bkpf-kursf. "汇率
APPEND ls_currencyamount TO lt_currencyamount.
ENDIF.
*本币金额
IF <fs_bseg>-dmbtr IS NOT INITIAL.
CLEAR ls_currencyamount.
ls_currencyamount-itemno_acc = <fs_bseg>-buzei. "货币行项目
ls_currencyamount-curr_type = '10'. "本币金额
ls_currencyamount-amt_doccur = <fs_bseg>-dmbtr . "本币金额
SELECT SINGLE bukrs,waers FROM t001 INTO @DATA(ls_t001) WHERE bukrs = @is_bkpf-bukrs .
IF sy-subrc = 0.
ls_currencyamount-currency = ls_t001-waers.
ENDIF.
* 如果为贷方,金额为负数
IF ls_tbsl-shkzg = 'H' .
ls_currencyamount-amt_doccur = 0 - ls_currencyamount-amt_doccur .
ENDIF.
ls_currencyamount-exch_rate = is_bkpf-kursf. "汇率
APPEND ls_currencyamount TO lt_currencyamount.
ENDIF.
*行项目扩展
CLEAR ls_fi003.
CLEAR ls_extension2.
IF <fs_bseg>-umskz EQ 'A' AND is_bkpf-blart EQ 'ZB'.
ls_fi003-bstat = 'S'. "预付申请需将bstat设置成'S'
ls_fi003-umskz = 'F'.
ls_fi003-zumsk = 'A'.
ENDIF.
ls_fi003-mndid = COND #( WHEN ls_tbsl-koart = 'K' THEN <fs_bseg>-mndid ELSE '' ).. "每个收款方的托管唯一参考
ls_fi003-rstgr = <fs_bseg>-rstgr. "付款原因
ls_fi003-ebeln = <fs_bseg>-ebeln. "采购订单
ls_fi003-ebelp = <fs_bseg>-ebelp. "采购订单项目
ls_fi003-anbwa = <fs_bseg>-anbwa. "资产交易类型
ls_fi003-xnegp = <fs_bseg>-xnegp. "反记账标识
IF NOT ls_fi003 IS INITIAL.
ls_fi003-posnr = <fs_bseg>-buzei.
ls_extension2-valuepart1 = ls_fi003.
ls_extension2-structure = 'ZSFI003'.
APPEND ls_extension2 TO lt_extension2.
ENDIF.
*获利能力COPA字段
IF <fs_bseg>-prctr IS NOT INITIAL.
lt_criteria = VALUE #( BASE lt_criteria ( itemno_acc = <fs_bseg>-buzei fieldname = 'PRCTR' character = <fs_bseg>-prctr ) ).
ENDIF.
IF <fs_bseg>-werks_pa IS NOT INITIAL.
lt_criteria = VALUE #( BASE lt_criteria ( itemno_acc = <fs_bseg>-buzei fieldname = 'WERKS' character = <fs_bseg>-werks_pa ) ).
ENDIF.
IF <fs_bseg>-artnr_pa IS NOT INITIAL.
lt_criteria = VALUE #( BASE lt_criteria ( itemno_acc = <fs_bseg>-buzei fieldname = 'ARTNR' character = <fs_bseg>-artnr_pa ) ).
ENDIF.
IF <fs_bseg>-kndnr_pa IS NOT INITIAL.
lt_criteria = VALUE #( BASE lt_criteria ( itemno_acc = <fs_bseg>-buzei fieldname = 'KNDNR' character = <fs_bseg>-kndnr_pa ) ).
ENDIF.
lv_line_no = lv_line_no + 1.
ENDLOOP.
*客户项目含有税码
LOOP AT lt_accountreceivable INTO ls_accountreceivable WHERE tax_code IS NOT INITIAL.
READ TABLE it_bseg INTO DATA(ls_bseg) WITH KEY buzei = ls_accountreceivable-itemno_acc.
IF sy-subrc = 0 .
calculate_amount( EXPORTING iv_bukrs = is_bkpf-bukrs
iv_tax_code = ls_accountreceivable-tax_code
iv_waers = is_bkpf-waers
IMPORTING et_mwdat = lt_mwdat ).
READ TABLE lt_mwdat INDEX 1 INTO ls_mwdat.
CHECK sy-subrc EQ 0.
ls_accounttax-itemno_acc = lv_line_no.
ls_accounttax-gl_account = ls_mwdat-hkont.
ls_accounttax-cond_key = ls_mwdat-kschl.
ls_accounttax-tax_code = ls_accountreceivable-tax_code.
APPEND ls_accounttax TO lt_accounttax.
LOOP AT lt_currencyamount INTO ls_currencyamount WHERE itemno_acc EQ ls_accountreceivable-itemno_acc.
APPEND INITIAL LINE TO lt_currencyamount_tax ASSIGNING FIELD-SYMBOL(<fs_amount>).
<fs_amount>-itemno_acc = lv_line_no. "货币行项目
<fs_amount>-curr_type = ls_currencyamount-curr_type. "本币金额
<fs_amount>-currency = ls_currencyamount-currency. "功能性货币单位
<fs_amount>-amt_doccur = 0. "功能性货币金额
<fs_amount>-amt_base = ls_currencyamount-amt_doccur.
ENDLOOP.
ADD 1 TO lv_line_no.
CLEAR:lt_mwdat,ls_accounttax.
ENDIF.
CLEAR ls_bseg.
ENDLOOP.
*供应商项目含有税码
LOOP AT lt_accountpayable INTO ls_accountpayable WHERE tax_code IS NOT INITIAL.
READ TABLE it_bseg INTO ls_bseg WITH KEY buzei = ls_accountpayable-itemno_acc.
IF sy-subrc = 0 .
calculate_amount( EXPORTING iv_bukrs = is_bkpf-bukrs
iv_tax_code = ls_accountpayable-tax_code
iv_waers = is_bkpf-waers
IMPORTING et_mwdat = lt_mwdat ).
READ TABLE lt_mwdat INDEX 1 INTO ls_mwdat.
CHECK sy-subrc EQ 0.
ls_accounttax-itemno_acc = lv_line_no.
ls_accounttax-gl_account = ls_mwdat-hkont.
ls_accounttax-cond_key = ls_mwdat-kschl.
ls_accounttax-tax_code = ls_accountpayable-tax_code.
APPEND ls_accounttax TO lt_accounttax.
LOOP AT lt_currencyamount INTO ls_currencyamount WHERE itemno_acc EQ ls_accountpayable-itemno_acc.
APPEND INITIAL LINE TO lt_currencyamount_tax ASSIGNING <fs_amount>.
<fs_amount>-itemno_acc = lv_line_no. "货币行项目
<fs_amount>-curr_type = ls_currencyamount-curr_type. "本币金额
<fs_amount>-currency = ls_currencyamount-currency. "功能性货币单位
<fs_amount>-amt_doccur = 0. "功能性货币金额
READ TABLE it_bseg INTO ls_bseg WITH KEY buzei = ls_accountpayable-itemno_acc.
IF sy-subrc = 0.
<fs_amount>-amt_doccur = ls_bseg-wmwst. "税额
ENDIF.
<fs_amount>-amt_base = ls_currencyamount-amt_doccur.
ENDLOOP.
CLEAR:lt_mwdat,ls_accounttax.
ENDIF.
CLEAR ls_bseg.
ENDLOOP.
APPEND LINES OF lt_currencyamount_tax TO lt_currencyamount.
* 调用凭证导入BAPI
IF lines( lt_zsfi007 ) > 0.
SET PARAMETER ID 'ZZSP_GL_IND' FIELD 'W'.
EXPORT lt_zsfi007 = lt_zsfi007 TO MEMORY ID 'ZCI_COBL'.
ENDIF.
SET UPDATE TASK LOCAL.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = ls_documentheader
IMPORTING
obj_type = lv_obj_type
obj_key = lv_obj_key
obj_sys = lv_obj_sys
TABLES
accountgl = lt_accountgl
accountreceivable = lt_accountreceivable
accountpayable = lt_accountpayable
accounttax = lt_accounttax
currencyamount = lt_currencyamount
extension2 = lt_extension2
criteria = lt_criteria
return = lt_return.
CLEAR: ev_rtype,ev_rtmsg.
LOOP AT lt_return INTO ls_return WHERE type CA 'AEX'.
MESSAGE ID ls_return-id TYPE ls_return-type NUMBER ls_return-number
WITH ls_return-message_v1 ls_return-message_v2
ls_return-message_v3 ls_return-message_v4
INTO DATA(lv_msg).
ev_rtype = 'E'.
ev_rtmsg = |{ ev_rtmsg }{ lv_msg };|.
ENDLOOP.
IF sy-subrc NE 0.
ev_belnr = lv_obj_key(10).
ev_gjahr = lv_obj_key+14(4).
ev_rtype = 'S'.
ev_rtmsg = TEXT-001 .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
ev_rtype = 'E'.
ev_rtmsg = TEXT-002 && ev_rtmsg.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
LOOP AT it_bseg INTO DATA(ls_temp).
ls_result = VALUE #( glo_ref4_hd = is_bkpf-glo_ref4_hd docln = ls_temp-buzei bukrs = is_bkpf-bukrs monat = is_bkpf-monat
belnr = ev_belnr gjahr = ev_gjahr msgts = ev_rtype ).
ls_result-text = COND #( WHEN ev_rtype EQ 'E' THEN ev_rtmsg
ELSE |{ is_bkpf-bukrs }/{ ev_gjahr }/{ ev_belnr ALPHA = OUT }/{ is_bkpf-monat }/{ TEXT-001 }| ).
CONDENSE ls_result-text NO-GAPS.
APPEND ls_result TO et_result.
CLEAR ls_result.
ENDLOOP.
ENDMETHOD.
- 预制凭证增强
新增表头扩展接口(例子:PARK)标识未预制凭证,添加到扩展表中,如下
对BADI :BADI_ACC_DOCUMENT(在调用科目接口前更改外部凭证)新增增强实施,在IF_EX_ACC_DOCUMENT~CHANGE中更改ACCHD-STATUS_NEW = ‘2’
*预制凭证增强
READ TABLE c_extension2 INTO wa_extension WITH KEY structure = 'PARK'.
IF sy-subrc = 0.
MOVE '2' TO c_acchd-status_new.
DELETE c_extension2 INDEX sy-tabix.
ENDIF.
- 预付申请增强
通预制凭证类似,再调用BAPI创建之前向扩展表新增预付申请标识,次数新增了行项目扩展接口fi003,将bstat,umskz, zumsk这是如下值
*行项目扩展
CLEAR ls_fi003.
CLEAR ls_extension2.
IF <fs_bseg>-umskz EQ 'A' AND is_bkpf-blart EQ 'ZB'.
ls_fi003-bstat = 'S'. "预付申请需将bstat设置成'S'
ls_fi003-umskz = 'F'.
ls_fi003-zumsk = 'A'.
ENDIF.
同理需要再BADI_ACC_DOCUMENT(在调用科目接口前更改外部凭证)新增增强实施IF_EX_ACC_DOCUMENT~CHANGE中以上值疯爱到对应行项目中,同时更改表头c_acchd-glvor = 'RFST'.此处包含行项目其他字段的增强
LOOP AT c_extension2 INTO wa_extension.
AT NEW structure.
CREATE DATA l_ref TYPE (wa_extension-structure).
ASSIGN l_ref->* TO <l_struc>.
ENDAT.
CONCATENATE wa_extension-valuepart1 wa_extension-valuepart2
wa_extension-valuepart3 wa_extension-valuepart4
INTO ext_value.
MOVE ext_value TO <l_struc>.
ASSIGN COMPONENT 'POSNR' OF STRUCTURE <l_struc> TO <l_field>.
READ TABLE c_accit WITH KEY posnr = <l_field>
INTO wa_accit.
IF sy-subrc IS INITIAL.
"预付申请增强BSTAT = 'S'
IF wa_extension-structure = 'ZSFI003'.
MOVE-CORRESPONDING <l_struc> TO ls_zsfi003.
IF ls_zsfi003-bstat EQ 'S'.
c_acchd-glvor = 'RFST'. "预付申请凭证表头glvor 需设置成 'RFST'
ELSE.
ls_zsfi003-umskz = wa_accit-umskz.
ls_zsfi003-zumsk = wa_accit-zumsk.
ENDIF.
ls_zsfi003-mndid = COND #( WHEN ls_zsfi003-mndid IS INITIAL THEN wa_accit-mndid ELSE ls_zsfi003-mndid ).
ls_zsfi003-xnegp = COND #( WHEN ls_zsfi003-xnegp IS INITIAL THEN wa_accit-xnegp ELSE ls_zsfi003-xnegp ).
MOVE-CORRESPONDING ls_zsfi003 TO <l_struc> .
ENDIF.
"预申请增强BSTAT = 'S'
MOVE-CORRESPONDING <l_struc> TO wa_accit.
MODIFY c_accit FROM wa_accit INDEX sy-tabix.
ENDIF.
ENDLOOP.
- 表头xref1_hd 字段增强写入
ls_fi004-xref1_hd = is_bkpf-xref1_hd."参考码 (标题) 1
zcl_pass=>zsfi004 = ls_fi004.
同理需要在BADI_ACC_DOCUMENT(在调用科目接口前更改外部凭证)新增的增强实施IF_EX_ACC_DOCUMENT~CHANGE方法中将xref1_hd赋值给表头对应字段
DATA: lt_xbseg TYPE STANDARD TABLE OF bseg,
ls_xbseg TYPE bseg,
ls_xbkpf TYPE bkpf,
lt_xbkpf TYPE STANDARD TABLE OF bkpf.
MOVE-CORRESPONDING c_acchd TO ls_xbkpf.
ls_zsfi004 = zcl_pass=>zsfi004." 备选参考,参考码 增强
LOOP AT c_accit INTO DATA(ls_accit).
"add by zhaojiajia for wuhaoxian 2024/3/27 备选参考,参考码 增强
IF ls_zsfi004-xref1_hd IS NOT INITIAL.
ls_accit-xref1_hd = ls_zsfi004-xref1_hd.
MODIFY c_accit FROM ls_accit.
ENDIF.
"备选参考,参考码 增强
MOVE-CORRESPONDING ls_accit TO ls_xbkpf.
MOVE-CORRESPONDING ls_accit TO ls_xbseg.
ls_xbseg-buzei = ls_accit-posnr+7(3).
APPEND ls_xbseg TO lt_xbseg.
ENDLOOP.
MOVE-CORRESPONDING ls_zsfi004 TO ls_xbkpf."备选参考,参考码 增强
APPEND ls_xbkpf TO lt_xbkpf.
CALL FUNCTION 'FI_SUBSTITUTION_DOC'
TABLES
io_xbseg = lt_xbseg
io_xbkpf = lt_xbkpf.
- xblnr_alt字段增强写入
同xref1_hd增强类似,调用BAPI_ACC_DOCUMENT_POST之前将xblnr_alt字段赋值到凭证表头扩展结构中,但是比较特别的是此字段在BADI_ACC_DOCUMENT(在调用科目接口前更改外部凭证)新增的增强实施IF_EX_ACC_DOCUMENT~CHANGE方法中更改表头字段无效.
增强可加入到凭证表头的替代事件中(00001120),步骤如下:
Tocde:FIBF
点击函数模块会跳转到标准的增强模版函数,复制SAMPLE_PROCESS_00001120添加增强代码如下,在此处更改凭证表头参数,此处一定得更改T_BKPFSUB表对应字段,否则不生效
- 汇票凭证信息写入BSED、BSEC表
票据信息也是同理在调用过账BAPI之前将值记录到行项目扩展结构中,在包含文件LFACIF5D中新增隐式增强如下
LOOP AT XBSEG WHERE UMSKZ = 'W' or umskz = 'T' or umskz = '1' or umskz = '2'.
MOVE-CORRESPONDING XBSEG TO XBSED.
LV_ITEMNO_ACC = XBSEG-BUZEI.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LV_ITEMNO_ACC
IMPORTING
OUTPUT = LV_ITEMNO_ACC
.
READ TABLE LT_zsfi007 WITH KEY POSNR = LV_ITEMNO_ACC.
IF SY-SUBRC = 0.
XBSED-WDATE = LT_zsfi007-WDATE .
XBSED-WNAME = LT_zsfi007-WNAME.
XBSED-WBZOG = LT_zsfi007-WBZOG.
XBSED-WBANK = LT_zsfi007-WBANK.
XBSED-WELGF = cond #( when LT_zsfi007-WELGF is not INITIAL then LT_zsfi007-WELGF else XBSED-WELGF ).
XBSED-BANK = cond #( when LT_zsfi007-BANKL is not INITIAL then LT_zsfi007-BANKL else XBSED-BANK )."出票银行代码
XBSED-ACCOU = cond #( when LT_zsfi007-BANKN is not INITIAL then LT_zsfi007-BANKN else XBSED-ACCOU )."银行账户
CLEAR XBSEc.
XBSEc-BANKL = cond #( when LT_zsfi007-BANKL is not INITIAL then LT_zsfi007-BANKL else XBSEc-BANKL )."银行代码
XBSEc-BANKS = cond #( when LT_zsfi007-BANKS is not INITIAL then LT_zsfi007-BANKS else XBSEc-BANKS )."银行国家
XBSEc-BANKN = cond #( when LT_zsfi007-BANKN is not INITIAL then LT_zsfi007-BANKN else XBSEc-BANKN )."银行账户
IF XBSEC IS NOT INITIAL.
READ TABLE XBSEc WITH KEY BUZEI = XBSEG-BUZEI.
IF SY-SUBRC NE 0.
XBSEc = VALUE #( BASE XBSEc BUKRS = XBSED-BUKRS BELNR = XBSED-BELNR GJAHR = XBSED-GJAHR BUZEI = XBSED-BUZEI ).
ENDIF.
APPEND XBSEC.
XBSEG-XCPDD = 'X'."此处如果不打标识'X'的话前台页面部分票据信息会不展示
MODIFY XBSEG.
ENDIF.
APPEND XBSED.
ENDIF.
ENDLOOP.
函数FI_DOCUMENT_CHECK的开始和结尾去修改CHAR_W的值。函数开始判断特别总账标识为W,将CHAR_W改为'U',函数结尾将CHAR_W改回去
ENHANCEMENT 1 ZFI_DOC_POST_BOE. "active version
*BAPI_ACC_DOCUMENT_POST 过账时,特殊总账标记W无法记账
DATA:LV_SP_GL_IND TYPE BAPIACAR09-SP_GL_IND.
CLEAR:LV_SP_GL_IND.
GET PARAMETER ID 'ZZSP_GL_IND' FIELD LV_SP_GL_IND.
IF LV_SP_GL_IND = 'W'.
CHAR_W = 'U'.
ENDIF.
ENDENHANCEMENT.
ENHANCEMENT 2 ZFI_DOC_POST_BOE. "active version
*BAPI_ACC_DOCUMENT_POST 过账时,特殊总账标记W无法记账
CLEAR:LV_SP_GL_IND.
GET PARAMETER ID 'ZZSP_GL_IND' FIELD LV_SP_GL_IND.
IF LV_SP_GL_IND = 'W'.
CHAR_W = 'W'.
ENDIF.
ENDENHANCEMENT.
*$*$-End: (2)---------------------------------------------------------------------------------$*$*
ENDFUNCTION.