BAPI_ACC_DOCUMENT_POST 凭证过账及增强

news2024/12/23 10:32:28
  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.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1630519.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

LVS/NAT工作模式介绍及配置

1.1 LVS/NAT模式工作原理 LVS&#xff08;Linux Virtual Server&#xff09;的网络地址转换&#xff08;NAT&#xff09;模式是一种在网络层&#xff08;第四层&#xff09;实现负载均衡的方法。在NAT模式中&#xff0c;Director Server&#xff08;DS&#xff09;充当所有服务…

[Diffusion Model笔记] DDPM数学推导版 2024.04.23

本文是观看以下视频的笔记&#xff1a; https://www.bilibili.com/video/BV1CU4y1i7jn/?p4&spm_id_frompageDriver 其他参考 https://zhuanlan.zhihu.com/p/614147698 https://zhuanlan.zhihu.com/p/563661713 这个写的非常详细&#xff1a; https://www.zhihu.com/ques…

【新手必读】Airtest测试Android手机常见的设置问题

经常有新手同学在使用Airtest测试Android手机的时候&#xff0c;遇到各式各样的问题&#xff0c;其中很大一部分&#xff0c;都是因为Android手机的设置不当&#xff0c;比如&#xff1a; 因为没有登录华为/荣耀/小米账号&#xff0c;而无法开启USB调试功能 因为没有关闭防止恶…

06_Scala流程控制

文章目录 [toc] 1.流程控制**小结&#xff1a;** **2. Scala中流程控制没有三元运算符****2.1 Scala中如果逻辑代码只有一行可以省略花括号****小结&#xff1a;** **3. 循环控制****3.1 for控制****3.2循环守卫 --> 循环表达式添加逻辑判断****3.3 循环步长 --> 表示循环…

IntelliJ IDEA 如何启用 JDK 预览特性

IntelliJ IDEA 也可以启用 JDK 的预览特性。 针对项目&#xff0c;选择项目结构。 配置是在语言结构上。 单击语言结构上的 SDK 默认&#xff0c;往下拉&#xff0c;就可以看到针对新版本的选项。 同时还可以看到那些版本是支持新特性预览的&#xff0c;那些版本是不支持新特…

Python 使用相对路径读取文件失败

python open一个问及那时使用绝对路径可以&#xff0c;但是使用相对路径时报错&#xff0c;找不到指定文件 解决步骤如下&#xff1a; 添加Python配置 在新增的配置Json文件添加下图红框这一行

Linux——(关于权限常见的3个问题)

文章目录 1.修改文件或者目录的拥有者和所属组1.1chown指令1.2chgrp指令 2.常见的权限三个问题2.1对应一个目录&#xff0c;如果要进入&#xff0c;需要什么权限&#xff1f;2.2为什么我们创建的文件默认权限不是7772.2.1关于Linux下的权限掩码 2.3文件能否被删除取决于什么2.3…

与Apollo共创生态:Apollo7周年大会自动驾驶生态利剑出鞘

前言 4月22日&#xff0c;百度Apollo在北京车展前夕举办了以“破晓•拥抱智变时刻”为主题的智能汽车产品发布会&#xff0c;围绕汽车智能化&#xff0c;发布了智驾、智舱、智图等全新升级的“驾舱图”系列产品。 1、7周年大会 自2013年百度开始布局自动驾驶&#xff0c;201…

吴恩达2022机器学习专项课程(一) 6.2 逻辑回归第三周课后实验:Lab2逻辑回归

问题预览/关键词 逻辑回归预测分类创建逻辑回归算法Sigmoid函数Sigmoid函数的表示sigmoid输出的结果Numpy计算指数的方法实验python实现sigmoid函数打印输入的z值和sigmoid计算的值可视化z值和sigmoid的值添加更多数据&#xff0c;使用逻辑回归可以正常预测分类![在这里插入图片…

GMSSL编译iOS

一、GMSSL-2.x 国密SDK源码下载&#xff0c;对GMSSL库进行编译生成对应的静态库。执行如下命令&#xff1a; cd到SDK源码目录 cd /Users/xxxx/Downloads/GMSSLV2-master查看SDK适用环境 ./config上图中错误解决方法 使用文本编辑器打开SDK目录下Configure、test/build.info、…

第十五届蓝桥杯省赛第二场C/C++B组C题【传送阵】题解(AC)

解题思路 由于 a a a 数组是一个 1 1 1 到 n n n 的一个排列&#xff0c;那么形成的一定是如下形式&#xff1a; 一定会构成几个点的循环&#xff0c;或者是几个单独的点。 从任意点开始&#xff0c;如果能进入一个循环&#xff0c;一定可以将整个循环的宝藏都拿走&#x…

android room 数据库升级的原则

1.如果新加了一张数据表则什么都不用干直接database那里将数据库版本升1 就可以nichuang 在entities里增加新加的entity ProviderMeta.DB_VERSION 版本号增1 room会自动生成 一个ProviderMeta.DB_VERSION 版本号的json文件 比如实例中升级到70 就会生成一个70.json的文件这是r…

发电厂智能巡检机器人:让发电厂更安全、更高效

在发电厂的众多应用场景中&#xff0c;升压站、化学车间、空冷塔、输煤皮带、综合管廊等&#xff0c;一直以来都是人工巡检的主战场。然而&#xff0c;这些场所环境极为复杂&#xff0c;人工巡检面临着诸多难题&#xff0c;强度大、频率低、间隔长等问题突出。这使得设备在运行…

三星应用TRIZ创新方法的经验分享:探索科技前沿的奥秘

TRIZ&#xff0c;即发明问题解决理论&#xff0c;于1946年被提出。它是一种基于知识和经验的创新方法&#xff0c;旨在帮助人们快速有效地解决各种复杂问题。TRIZ理论包含了大量的创新原理、算法和工具&#xff0c;可以帮助企业快速识别问题、寻找解决方案&#xff0c;并推动创…

【前端】VUE项目创建

在所需文件夹中打开cmd命令行窗口&#xff0c;输入vue ui 进入web可视化界面选择创建新项目 根据需求依次完成下列选择&#xff0c;下列是参考配置&#xff0c;完成后点击创建项目即可 最终显示完成

Opencv | 边缘提取

目录 一. 边缘检测1. 边缘的定义2. Sobel算子 边缘提取3. Scharr算子 边缘提取4. Laplacian算子 边缘提取5. Canny 边缘检测算法5.1 计算梯度的强度及方向5.2 非极大值抑制5.3 双阈值检测5.4 抑制孤立弱边缘 二. 轮廓信息1. 获取轮廓信息2. 画轮廓 一. 边缘检测 1. 边缘的定义…

智慧图书管理|基于SSM+vue的网上服装商城系统(源码+数据库+文档)

智慧图书管理目录 基于SSMvue的网上服装商城系统 一、前言 二、系统设计 三、系统功能设计 1.1 服装列表 1.2 公告信息管理 1.3 公告类型管理 四、数据库设计 五、核心代码 六、论文参考 七、最新计算机毕设选题推荐 八、源码获取&#xff1a; 博主介绍&#xff1…

webpack 入口和出口的最佳实践

入口和出口的最佳实践 {ignore} 具体情况具体分析 下面是一些经典场景 一个页面一个JS 外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传 源码结构 |—— src|—— pageA 页面A的代码目录|—— index.js 页面A的启动模块|—— ...|—— pageB 页面…

分享一些常用的内外网文件传输工具

内外网隔离后的文件传输是网络安全领域中一个常见而又重要的问题。随着信息技术的快速发展&#xff0c;网络安全问题日益凸显&#xff0c;内外网隔离成为了许多企业和组织保护内部信息安全的重要手段。然而&#xff0c;内外网隔离后如何有效地进行文件传输&#xff0c;成为了摆…

【sgSearch_v2】自定义组件:常用搜索栏筛选框组件(展开后更多搜索内容悬浮于其他组件之上,不影响整体布局高度)。

sgSearch_v2源码 <template><div:class"$options.name":expand"expandSearch":showCollapseBtn"showCollapseBtn"keyup.enter"(expandSearch true), $emit(keyupEnter, {})"><ul class"search-list">&l…