Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Tax calculation in BAPI_ACC_DOCUMENT_POST

Former Member
0 Likes
3,180

Hi all,

We have a program in which BDC (Call Transaction) is used to do postings to GL accounts with transaction FB01.

Now, the requirement is to use BAPI ‘BAPI_ACC_DOCUMENT_POST’ to do the postings. I did with bapi but one problem is coming in this. The tax data is calculated and displayed in the document but posting is not made to the tax account when done with bapi.

If you have any pointers regarding this, please provide the same.

Thanks and regards,

Ridhima

Hi all,

We have a program in which BDC (Call Transaction) is used to do postings to GL accounts with transaction FB01.

Now, the requirement is to use BAPI ‘BAPI_ACC_DOCUMENT_POST’ to do the postings. I did with bapi but one problem is coming in this. The tax data is calculated and displayed in the document but posting is not made to the tax account when done with bapi.

If you have any pointers regarding this, please provide the same.

Thanks and regards,

Ridhima

7 REPLIES 7
Read only

Former Member
0 Likes
1,581

Hi,

Check the following code :



*&---------------------------------------------------------------------*
*&      Form  fill_account_tax
*&---------------------------------------------------------------------*
FORM fill_account_tax USING p_compt CHANGING p_tax_amount.
* ACCOUNTTAX
  PERFORM calculate_vat_amount USING t_notilus-comp_code
                                     t_notilus-vat_cod
                                     t_notilus-amt_doccur
                            CHANGING p_tax_amount
                                     accounttax-tax_code
                                     accounttax-tax_rate
                                     accounttax-acct_key
                                     accounttax-gl_account
                                     accounttax-cond_key.
  accounttax-tax_date   = sy-datum.
  accounttax-itemno_acc = p_compt.
  accounttax-itemno_tax = p_compt - 1.
  APPEND accounttax.

ENDFORM.                    " fill_account_tax
*&---------------------------------------------------------------------*
*&      Form  calculate_vat_amount
*&---------------------------------------------------------------------*
FORM calculate_vat_amount  USING    p_comp_code
                                    p_vat_cod
                                    p_amount
                           CHANGING tax_amount
                                    w_vat_cod
                                    w_msatz
                                    w_ktosl
                                    w_hkont
                                    w_kschl.

  DATA : BEGIN OF t_mwdat OCCURS 0.
          INCLUDE STRUCTURE rtax1u15.
  DATA : END OF t_mwdat.

  DATA : w_ttc LIKE bseg-wrbtr.
  w_ttc = p_amount.

  CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
    EXPORTING
      i_bukrs           = p_comp_code
      i_mwskz           = p_vat_cod
      i_waers           = 'EUR'
      i_wrbtr           = w_ttc
    TABLES
      t_mwdat           = t_mwdat
    EXCEPTIONS
      bukrs_not_found   = 1
      country_not_found = 2
      mwskz_not_defined = 3
      mwskz_not_valid   = 4
      ktosl_not_found   = 5
      kalsm_not_found   = 6
      parameter_error   = 7
      knumh_not_found   = 8
      kschl_not_found   = 9
      unknown_error     = 10
      account_not_found = 11
      txjcd_not_valid   = 12
      OTHERS            = 13.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CLEAR t_mwdat.
  READ TABLE t_mwdat INDEX 1. "INTO s_mwdat
* w_tax_amount = t_mwdat-WMWST.
  w_tax_amount = t_notilus-vat_amount.
  w_ktosl      = t_mwdat-ktosl.
  w_hkont      = t_mwdat-hkont.
  w_kschl      = t_mwdat-kschl.
  w_msatz      = t_mwdat-msatz.
  w_vat_cod    = p_vat_cod.


ENDFORM.                    " calculate_vat_amount



(...)
* call BAPI-function in this system
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
      documentheader = documentheader
    IMPORTING
      obj_type       = l_type
      obj_key        = l_key
      obj_sys        = l_sys
    TABLES
      accountgl      = accountgl
      accountpayable = accountpayable
      currencyamount = currencyamount
      accounttax     = accounttax
      extension1     = extension1
      return         = return.

Hope this helps,

Erwan

Read only

Former Member
0 Likes
1,581

Thanks for your response.

The thing is that we customization settings done to calculate tax. So we dont need to calculate tax.

I am just passing tax code and tax jurisdiction in the accountgl structure of bapi.

Tax is calculated but posting is not done to the tax account.

Read only

0 Likes
1,581

Can I know what you put in the following field :

documentheader-compo_acc ?

I suggest to keep it blank.

Erwan

Read only

Former Member
0 Likes
1,581

It is blank. I am not entering anything in this.

Read only

0 Likes
1,581

Ok, I guess you did'nt use the accounttax structure ?

Perhaps, you should fill it...

Read only

Former Member
0 Likes
1,581

Hi Radhima,

I thnk you need to use the same formula for calculating tax in program before posting the value & assing the calculated value to bapi & field & pass it. Because the BAPI post the values directly to tables based on functions without using screens.

Ashvender

Read only

Former Member
0 Likes
1,581

I tried populaitng accounttax sturcture also and passed tax code and tax jurisdiction in this instead of accountgl. but now it gives the error 'balance in transaction currency'. But when i dont populate the accounttax, document is created.