美文网首页
error bapi BAPI_ACC_DOCUMENT_POS

error bapi BAPI_ACC_DOCUMENT_POS

作者: 想跳出大海的鱼 | 来源:发表于2022-09-09 10:04 被阅读0次

    FI会计凭证导入-TAX参数报错 Tax insertion for 'xxxx'> impossible due to tax base 0

    参考网址:error bapi BAPI_ACC_DOCUMENT_POST 848 FF | SAP Community

    参考步骤

    实际代码

    FORM frm_create_exp  TABLES   it_exp_item TYPE zttif_hly_exp_log

                         CHANGING lt_return    TYPE zbapiret2_t

                                  iv_no_commit TYPE flag.

      DATA:ls_documentheader    TYPE bapiache09,

           lt_accountreceivable TYPE TABLE OF bapiacar09,

           lt_accountpayable    TYPE TABLE OF bapiacap09,

           lt_accountgl         TYPE TABLE OF bapiacgl09,

           lt_currencyamount    TYPE TABLE OF bapiaccr09,

           lt_accounttax        TYPE TABLE OF bapiactx09,

           lt_criteria          TYPE TABLE OF bapiackec9.

      DATA:ls_extension2        TYPE zsfiexten2,

           ls_extension_accit   TYPE accit,

           ls_extension_acccr   TYPE acccr,

           lt_extension         TYPE STANDARD TABLE OF bapiparex,

           ls_extension         TYPE bapiparex.

    *  DATA:lt_return            TYPE TABLE OF bapiret2.

      DATA:lt_mwdat             TYPE TABLE OF rtax1u15.

      DATA:ls_color             TYPE slis_specialcol_alv.

      DATA:lv_itemno            TYPE posnr_acc.

      DATA lv_objkey            TYPE bapiache09-obj_key.

      DATA:lv_msg               TYPE bapi_msg.

      DATA:lv_hkont             TYPE hkont.

      DATA:lv_buzei             TYPE POSNR_ACC.

      DATA:LINES                TYPE POSNR_ACC.

      DATA:lv_suminfo           TYPE anln1.

      DATA: gr_uuid_error TYPE REF TO cx_uuid_error,

            gv_error      TYPE string.

      DATA:BEGIN OF gt_criteria_value OCCURS 0,

             zuuid  TYPE uuid,

             zfield TYPE char50,

             zvalue TYPE char50,

           END OF gt_criteria_value.

      .

      REFRESH gt_criteria_value.

      LOOP AT it_exp_item INTO DATA(ls_data).

        TRY.

            ls_data-zuuid = cl_system_uuid=>create_uuid_c22_static( ).

          CATCH cx_uuid_error INTO gr_uuid_error.

            gv_error = gr_uuid_error->get_text( ).

        ENDTRY.

    *No.30~34根据录入数据派生出所有特征值

        "销售订单号

        IF ls_data-vbeln IS NOT INITIAL.

          gt_criteria_value-zfield = 'KAUFN'.

          gt_criteria_value-zvalue = ls_data-vbeln.

          gt_criteria_value-zvalue = ls_data-zuuid.

          APPEND  gt_criteria_value.

        ENDIF.

        "销售订单行项目号

        IF ls_data-vbeln IS NOT INITIAL.

          gt_criteria_value-zfield = 'KDPOS'.

          gt_criteria_value-zvalue = ls_data-posnr.

          gt_criteria_value-zvalue = ls_data-zuuid.

          APPEND  gt_criteria_value.

        ENDIF.

        "客户号

        IF ls_data-vbeln IS NOT INITIAL.

          gt_criteria_value-zfield = 'KNDNR'.

          gt_criteria_value-zvalue = ls_data-kunnr.

          gt_criteria_value-zvalue = ls_data-zuuid.

          APPEND  gt_criteria_value.

        ENDIF.

        "产品号

        IF ls_data-vbeln IS NOT INITIAL.

          gt_criteria_value-zfield = 'ARTNR'.

          gt_criteria_value-zvalue = ls_data-artnr.

          gt_criteria_value-zvalue = ls_data-zuuid.

          APPEND  gt_criteria_value.

        ENDIF.

        "分销渠道

        IF ls_data-vbeln IS NOT INITIAL.

          gt_criteria_value-zfield = 'VTWEG'.

          gt_criteria_value-zvalue = ls_data-vtweg.

          gt_criteria_value-zvalue = ls_data-zuuid.

          APPEND  gt_criteria_value.

        ENDIF.

        MODIFY it_exp_item FROM ls_data.

      ENDLOOP.

      SELECT * INTO TABLE @DATA(lt_tbsl)

         FROM tbsl.

      SELECT * FROM t074

        WHERE ktopl EQ @gv_ktopl

        INTO TABLE @DATA(lt_t074).

      lines = lines( it_exp_item ).

      CLEAR lv_buzei.

      LOOP AT it_exp_item  ASSIGNING FIELD-SYMBOL(<line>).

        IF <line>-buzei IS NOT INITIAL.

          lv_buzei = <line>-buzei.

        ELSE.

          lv_buzei = lv_buzei + 1.

          <line>-buzei = lv_buzei.

        ENDIF.

        READ TABLE lt_tbsl INTO DATA(ls_tbsl)

                           WITH KEY bschl = <line>-bschl.

        IF ls_tbsl-koart = 'S' OR "总账科目

           ls_tbsl-koart = 'A' OR

           ls_tbsl-koart = 'M'.

          IF ls_tbsl-koart = 'S' OR ls_tbsl-koart = 'M'.

            IF <line>-hkont IS INITIAL.

              <line>-hkont = <line>-suminfo.

            ENDIF.

            lv_suminfo = ''.

          ELSE.

            lv_suminfo = <line>-suminfo.

          ENDIF.

          lt_accountgl = VALUE #( BASE lt_accountgl (

                            itemno_acc = lv_buzei

                            item_text  = <line>-sgtxt                  "项目文本

                            acct_type  = ls_tbsl-koart

                            gl_account = |{ <line>-hkont ALPHA = IN }| "总账科目

                            asset_no   = lv_suminfo  "客户/供应商/总账科目/固定资产编号

                            sub_number = '0000'

                            costcenter = |{ <line>-kostl ALPHA = IN }| "成本中心

                            alloc_nmbr = <line>-zuonr    "分配

                            ref_key_1  = <line>-xref1    "参考代码1

                            ref_key_2  = <line>-xref2    "参考代码2

                            profit_ctr = <line>-prctr    "利润中心

                            housebankid = <line>-hbkid   "开户行

                            tax_code   = <line>-mwskz    "税码

    *                          cs_trans_t = <line>-umsks

                             ) ).

        ELSEIF ls_tbsl-koart = 'D'."客户应收

          READ TABLE lt_t074 INTO DATA(ls_t074)

                             WITH KEY koart = ls_tbsl-koart

                                      umskz = <line>-umskz.

          IF sy-subrc EQ 0.

            lt_accountreceivable = VALUE #( BASE lt_accountreceivable (

                              itemno_acc = lv_buzei

                              item_text  = <line>-sgtxt

                              customer   = |{ <line>-suminfo ALPHA = IN }|

                              gl_account = |{ ls_t074-skont ALPHA = IN }|

                              sp_gl_ind  = <line>-umskz

                              alloc_nmbr = <line>-zuonr

                              ref_key_1  = <line>-xref1

                              ref_key_2  = <line>-xref2

                              profit_ctr = <line>-prctr

                              bank_id    = <line>-hbkid

                              tax_code   = <line>-mwskz

                               ) ).

          ELSE.

            lt_accountreceivable = VALUE #( BASE lt_accountreceivable (

                              itemno_acc = lv_buzei

                              item_text  = <line>-sgtxt

                              customer   = |{ <line>-suminfo ALPHA = IN }|

                              gl_account = |{ <line>-hkont ALPHA = IN }|

                              sp_gl_ind  = <line>-umskz

                              alloc_nmbr = <line>-zuonr

                              ref_key_1  = <line>-xref1

                              ref_key_2  = <line>-xref2

                              profit_ctr = <line>-prctr

                              bank_id    = <line>-hbkid

                              tax_code   = <line>-mwskz

                               ) ).

          ENDIF.

        ELSEIF ls_tbsl-koart = 'K'."供应商应付

          READ TABLE lt_t074 INTO ls_t074

                             WITH KEY koart = ls_tbsl-koart

                                      umskz = <line>-umskz.

          IF sy-subrc EQ 0.

            lt_accountpayable = VALUE #( BASE lt_accountpayable (

                              itemno_acc = lv_buzei

                              item_text  = <line>-sgtxt

                              vendor_no  = |{ <line>-suminfo ALPHA = IN }|

                              gl_account = |{ ls_t074-skont ALPHA = IN }|

                              sp_gl_ind  = <line>-umskz

                              alloc_nmbr = <line>-zuonr

                              ref_key_1  = <line>-xref1

                              ref_key_2  = <line>-xref2

                              profit_ctr = <line>-prctr

                              bank_id    = <line>-hbkid

                              pmnttrms   = <line>-zterm  "收付条件

                              tax_code   = <line>-mwskz

                               ) ).

          ELSE.

            lt_accountpayable = VALUE #( BASE lt_accountpayable (

                              itemno_acc = lv_buzei

                              item_text  = <line>-sgtxt

                              vendor_no  = |{ <line>-suminfo ALPHA = IN }|

                              gl_account = |{ <line>-hkont ALPHA = IN }|

                              sp_gl_ind  = <line>-umskz

                              alloc_nmbr = <line>-zuonr

                              ref_key_1  = <line>-xref1

                              ref_key_2  = <line>-xref2

                              profit_ctr = <line>-prctr

                              bank_id    = <line>-hbkid

                              pmnttrms   = <line>-zterm

                              tax_code   = <line>-mwskz

                               ) ).

          ENDIF.

        ENDIF.

        "criteria

        LOOP AT gt_criteria_value   WHERE zuuid =  <line>-zuuid.

          lt_criteria = VALUE #( BASE lt_criteria ( itemno_acc = lv_buzei

                                                fieldname  = gt_criteria_value-zfield

                                                character  = gt_criteria_value-zvalue ) ).

        ENDLOOP.

        "CURRENCYAMOUNT

        lt_currencyamount = VALUE #( BASE lt_currencyamount (

                              itemno_acc = lv_buzei

                              currency   = <line>-waers

                              amt_doccur = COND string(

                                                WHEN ls_tbsl-shkzg = 'H'

                                                  THEN -1 * <line>-wrbtr "凭证货币金额

                                                  ELSE <line>-wrbtr )

                              curr_type  = '00'

                              exch_rate  = <line>-kursf

                              ) ).

        IF <line>-waers NE gv_waers.

          IF <line>-dmbtr IS INITIAL.

            <line>-dmbtr = <line>-wrbtr * <line>-kursf.

          ENDIF.

          lt_currencyamount = VALUE #( BASE lt_currencyamount (

                                itemno_acc = lv_buzei

                                currency   = gv_waers

                                amt_doccur = COND string(

                                                  WHEN ls_tbsl-shkzg = 'H'

                                                    THEN -1 * <line>-dmbtr  "按本位币计的金额

                                                    ELSE <line>-dmbtr   )

                                curr_type  = '10'

                                exch_rate  = <line>-kursf

                                ) ).

        ENDIF.

        IF NOT <line>-mwskz IS INITIAL.

          CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'

            EXPORTING

              i_bukrs = <line>-bukrs

              i_mwskz = <line>-mwskz

              i_waers = <line>-waers

              i_wrbtr = <line>-wrbtr

            TABLES

              t_mwdat = lt_mwdat.

          LOOP AT lt_mwdat INTO DATA(ls_mwdat).

            lines = lines + 1.

            "CURRENCYAMOUNT

            lt_currencyamount = VALUE #( BASE lt_currencyamount (

                                  itemno_acc = lines

                                  currency   = gv_waers"<line>-waers

    *                              amt_doccur = COND string(

    *                                                WHEN ls_tbsl-shkzg = 'H'

    *                                                  THEN -1 * ls_mwdat-wmwst

    *                                                  ELSE ls_mwdat-wmwst )

                                  amt_base   = ls_mwdat-kawrt

                                  curr_type  = '00'

                                  exch_rate  = <line>-kursf

                                  ) ).

            "ACCOUNTTAX

            lt_accounttax = VALUE #( BASE lt_accounttax (

                                itemno_acc = lines

                                tax_code   = <line>-mwskz

                                acct_key   = ls_mwdat-ktosl

                                cond_key   = ls_mwdat-kschl

                                taxjurcode = ls_mwdat-txjcd

                                taxjurcode_deep  = ls_mwdat-txjcd_deep

                                taxjurcode_level = ls_mwdat-txjlv

                               ) ).

          ENDLOOP.

        ELSE.

    *      IF <line>-waers = gv_waers.

    *        IF <line>-dmbtr IS INITIAL.

    *          <line>-dmbtr = <line>-wrbtr.

    *        ENDIF.

    *        lt_currencyamount = VALUE #( BASE lt_currencyamount (

    *                              itemno_acc = lv_buzei

    *                              currency   = gv_waers

    *                              amt_doccur = COND string(

    *                                                WHEN ls_tbsl-shkzg = 'H'

    *                                                  THEN -1 * <line>-dmbtr "按本位币计的金额

    *                                                  ELSE <line>-dmbtr )

    *                              curr_type  = '10'

    *                              exch_rate  = <line>-kursf

    *                              ) ).

    *      ENDIF.

        ENDIF.

        SORT lt_currencyamount BY itemno_acc.

        CLEAR ls_extension2.

        ls_extension2 = VALUE #(

                          posnr      = lv_buzei

                          bschl      = <line>-bschl "记帐代码

                          rstgr      = <line>-rstgr "原因代码

    *                        anbwa      = <line>-umsks

                          umskz      = <line>-umskz "特别总账标识

                          zlsch      = <line>-zlsch "付款方式

                          zlspr      = <line>-zlspr "冻结付款

                          xnegp      = <line>-xnegp "标识: 反记帐

    *                        bupla      = lv_bupla

                        ).

        lt_extension = VALUE #( BASE lt_extension (

                        structure  = 'ZSFIEXTEN2'

                        valuepart2 = ls_extension2

                          ) ).

        IF NOT <line>-mwskz IS INITIAL.

         lt_extension = VALUE #( BASE lt_extension (

                         structure  = 'ACCIT'

                         valuepart1 = lv_buzei"LINES

                         valuepart2 = 'TAXIT'

                         valuepart3 = 'X'

                           ) ).

          lt_extension = VALUE #( BASE lt_extension (

                         structure  = 'ACCCR'

                         valuepart1 = lv_buzei"LINES

                         valuepart2 = 'FWBAS'

                         valuepart3 = <line>-wrbtr

                           ) ).

        ENDIF.

        CLEAR:ls_t074.

        ls_documentheader = VALUE #(

                     obj_type   = 'BKPFF'

                     obj_key    = '$'

                     bus_act    = 'RFBU'

                     doc_type   = <line>-blart "凭证类型

                     comp_code  = <line>-bukrs "公司代码

                     doc_date   = <line>-bldat "凭证日期

                     pstng_date = <line>-budat "记账日期

                     fis_period = <line>-monat "期间

                     ref_doc_no = <line>-xblnr "参考文本

                     header_txt = <line>-bktxt "凭证抬头文本

                     username   = sy-uname

                     ).

      ENDLOOP.

      IF iv_no_commit = abap_true.

        CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'

          EXPORTING

            documentheader    = ls_documentheader

          TABLES

            accountgl         = lt_accountgl

            accountreceivable = lt_accountreceivable

            accountpayable    = lt_accountpayable

            currencyamount    = lt_currencyamount

            criteria          = lt_criteria

            accounttax        = lt_accounttax

            return = lt_return

            extension2        = lt_extension.

      ELSE.

        CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

          EXPORTING

            documentheader    = ls_documentheader

          IMPORTING

            obj_key           = lv_objkey

          TABLES

            accountgl         = lt_accountgl

            accountreceivable = lt_accountreceivable

            accountpayable    = lt_accountpayable

            currencyamount    = lt_currencyamount

            criteria          = lt_criteria

            accounttax        = lt_accounttax

            return = lt_return

            extension2        = lt_extension.

        READ TABLE lt_return ASSIGNING FIELD-SYMBOL(<fs_return>)

                             WITH KEY type = 'S'.

        IF sy-subrc EQ 0.

          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

            EXPORTING

              wait = 'X'.

          <fs_return>-message_v1 = lv_objkey.

        ELSE.

          READ TABLE lt_return ASSIGNING <fs_return>

                             WITH KEY type = 'E'.

          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

        ENDIF.

        LOOP AT it_exp_item ASSIGNING FIELD-SYMBOL(<fs_data>).

          <fs_data>-belnr   = lv_objkey.

          <fs_data>-ztype   = <fs_return>-type.

          LOOP AT  lt_return ASSIGNING <fs_return>.

            <fs_data>-message = <fs_data>-message && <fs_return>-message.

          ENDLOOP.

        ENDLOOP.

      ENDIF.

      CLEAR:ls_tbsl,

            lv_objkey,

            lv_msg,

            ls_color,

            ls_extension2,

            ls_extension,

            ls_documentheader.

      FREE:lt_accountgl,

           lt_accountreceivable,

           lt_accountpayable,

           lt_currencyamount,

           lt_accounttax,

           lt_extension,

           lt_mwdat.

    ENDFORM.

    增强点是这个:BADI_ACC_DOCUMENT

    实际增强代码

    METHOD if_ex_acc_document~change.

      DATA: wa_extension   TYPE bapiparex,

            ext_value(960) TYPE c,

            wa_accit       TYPE accit,

            wa_acccr       TYPE acccr,

            l_ref          TYPE REF TO data.

      FIELD-SYMBOLS: <l_struc> TYPE any,

                     <l_field> TYPE any.

      SORT c_extension2 BY structure.

      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.

        IF wa_extension-structure = 'ZSFIEXTEN2'.

          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.

            MOVE-CORRESPONDING <l_struc> TO wa_accit.

            MODIFY c_accit FROM wa_accit INDEX sy-tabix.

          ENDIF.

        ELSEIF wa_extension-structure = 'ACCCR'.

          READ TABLE c_acccr WITH KEY posnr = wa_extension-valuepart1

          INTO wa_acccr.

          IF sy-subrc IS INITIAL.

            wa_acccr-fwbas = wa_extension-valuepart3.

            MODIFY c_acccr FROM wa_acccr INDEX sy-tabix.

          ENDIF.

        ELSEIF wa_extension-structure = 'ACCIT'.

          READ TABLE c_accit WITH KEY posnr = wa_extension-valuepart1

          INTO wa_accit.

          IF sy-subrc IS INITIAL.

            wa_accit-taxit = wa_extension-valuepart3.

            MODIFY c_accit FROM wa_accit INDEX sy-tabix.

          ENDIF.

        ENDIF.

      ENDLOOP.

    ENDMETHOD.

    相关文章

      网友评论

          本文标题:error bapi BAPI_ACC_DOCUMENT_POS

          本文链接:https://www.haomeiwen.com/subject/bnvanrtx.html