Application Development 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: 

BAPI_ACC_DOCUMENT_POST with Tax

Former Member

Hi All

I have a requirement that I need to do postings by calling the BAPI_ACC_DOCUMENT_POST. I've done everything except Tax postings. For tax posting I try to use the FM CALCULATE_TAX_FROM_NET_AMOUNT. However, I don't know how to fill the structures of BAPI from the values returned by this FM.

Please help me how to fill the structures(mainly, ACCOUNTGL, ACCOUNTTAX & CURRENCYAMOUNT) of BAPI while using this calculate tax FM.

Thanks

Skysen.

13 REPLIES 13

Former Member
0 Kudos

Hi

For the tax line you need to fill ACCOUNTTAX, not ACCOUNTGL, and transfer the value to CURRENCYAMOUNT.

If u use fm CALCULATE_TAX_FROM_NET_AMOUNT, it should return the tax value to be transfered to CURRENCYAMOUNT-AMT_DOCCUR, the base amount to CURRENCYAMOUNT-AMT_BASE.

In ACCOUNTTAX u should transfer

ACCOUNTTAX-TAX_CODE   = <vat code>
      ACCOUNTTAX-COND_KEY   = T_MWDAT-KSCHL (from CALCULATE_TAX_FROM_NET_AMOUNT).
      ACCOUNTTAX-TAXJURCODE = T_MWDAT-TXJCD ( from CALCULATE_TAX_FROM_NET_AMOUNT).
      ACCOUNTTAX-TAXJURCODE_DEEP  = T_MWDAT-TXJCD_DEEP (from CALCULATE_TAX_FROM_NET_AMOUNT).
      ACCOUNTTAX-TAXJURCODE_LEVEL = T_MWDAT-TXJLV (from CALCULATE_TAX_FROM_NET_AMOUNT).

Max

0 Kudos

Hi Max

Thanks again for your help.

Now, I'm struggling in filling the currencyamount structure.

Please take a look at my code for currencyamount strucuture below:

lv_amt = it_data-wrbtr.

CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'

EXPORTING

i_bukrs = gv_bukrs

i_mwskz = gv_mwskz

i_waers = lv_currency

i_wrbtr = lv_amt

TABLES

t_mwdat = it_mwdat.

IF sy-subrc = 0.

it_currencyamount-amt_base = it_mwdat-kawrt.

it_currencyamount-amt_doccur = ( it_currencyamount-amt_base * it_mwdat-msatz ) / 100.

it_currencyamount-tax_amt = it_mwdat-wmwst.

IF gv_shkzg = 'H'.

it_currencyamount-amt_doccur = it_currencyamount-amt_doccur * -1.

ENDIF.

Else.

  • For non-tax line items

it_currencyamount-amt_base = it_data-wmwst.

it_currencyamount-amt_doccur = it_data-wrbtr.

IF gv_shkzg = 'H'.

it_currencyamount-amt_doccur = it_currencyamount-amt_doccur * -1.

ENDIF.

ENDIF.

Can you please tell me if this is correct. Because the amount is not tally for this code. Please correct me if I'm wrong.

Thank you

Skysen.

0 Kudos

Hi

IF u use CALCULATE_TAX_FROM_NET_AMOUNT it means LV_AMT is just the base, so u don't need to get it from fm, the fm returns the tax value, so u don't need to calculate it after calling the fm:

 LV_AMT = IT_DATA-WRBTR.
CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
  EXPORTING
    I_BUKRS           = GV_BUKRS
    I_MWSKZ           = GV_MWSKZ
    I_WAERS           = LV_CURRENCY
    I_WRBTR           = LV_AMT
  TABLES
    T_MWDAT           = IT_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.
  IT_CURRENCYAMOUNT-ITEMNO_ACC = ITEMNO_ACC.
* Currency type
  IT_CURRENCYAMOUNT-CURR_TYPE     = '00'.
  IT_CURRENCYAMOUNT-CURRENCY      = LV_CURRENCY.
* Base Amount
  IT_CURRENCYAMOUNT-AMT_BASE   = LV_AMT.
* Tax value
  IT_CURRENCYAMOUNT-AMT_DOCCUR =  IT_MWDAT-WMWST.
  IF GV_SHKZG = 'H'.
    IT_CURRENCYAMOUNT-AMT_DOCCUR = IT_CURRENCYAMOUNT-AMT_DOCCUR * -1.
    IT_CURRENCYAMOUNT-AMT_BASE   = IT_CURRENCYAMOUNT-AMT_BASE   * -1.
  ENDIF.
  
  IT_ACCOUNTTAX-ITEMNO_ACC       = ITEMNO_ACC.
  IT_ACCOUNTTAX-TAX_CODE         = GV_MWSKZ.
  IT_ACCOUNTTAX-COND_KEY         = IT_MWDAT-KSCHL.
  IT_ACCOUNTTAX-TAXJURCODE       = IT_MWDAT-TXJCD.
  IT_ACCOUNTTAX-TAXJURCODE_DEEP  = IT_MWDAT-TXJCD_DEEP.
  IT_ACCOUNTTAX-TAXJURCODE_LEVEL = IT_MWDAT-TXJLV.
  APPEND ACCOUNTTAX.
ELSE.
"-----> It means the vat code is not good for company code, so probably it's wrong
ENDIF.

Max

0 Kudos

HI Max

Thank you for the reply.

Actually, in the source internal table I'm getting 1 header & 2 line items. The first line item doesn't have tax field. So tax need not to be calculated for this line item. But the 2nd line item contains the tax. So only for the 2nd line item I've to calculate the tax.

So, I've declared one global flag for tax field. If that is checked, then my program has to call the CALCULATE_TAX_FROM_NET_AMOUNT otherwise, for the AMT_DOCCUR field i'm assigning WRBTR from internal table.

Please see the pseudo code of this:

LOOP AT it_data.

....

....

*&--


For Non-tax lines--


IT_CURRENCYAMOUNT-ITEMNO_ACC = ITEMNO_ACC.

it_currencyamount-amt_doccur = it_data-wrbtr.

it_currencyamount-tax_amt = it_data-wmwst.

IF gv_shkzg = 'H'.

it_currencyamount-amt_doccur = it_currencyamount-amt_doccur * -1.

ENDIF.

IF gv_tax_flag = 'X'

*&--


For Tax lines--


CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'

EXPORTING

I_BUKRS = GV_BUKRS

I_MWSKZ = GV_MWSKZ

I_WAERS = LV_CURRENCY

I_WRBTR = LV_AMT

TABLES

T_MWDAT = IT_MWDAT

IF SY-SUBRC = 0.

IT_CURRENCYAMOUNT-ITEMNO_ACC = ITEMNO_ACC.

  • Currency type

IT_CURRENCYAMOUNT-CURR_TYPE = '00'.

IT_CURRENCYAMOUNT-CURRENCY = LV_CURRENCY.

  • Base Amount

IT_CURRENCYAMOUNT-AMT_BASE = LV_AMT.

  • Tax value

IT_CURRENCYAMOUNT-AMT_DOCCUR = IT_MWDAT-WMWST.

IF GV_SHKZG = 'H'.

IT_CURRENCYAMOUNT-AMT_DOCCUR = IT_CURRENCYAMOUNT-AMT_DOCCUR * -1.

IT_CURRENCYAMOUNT-AMT_BASE = IT_CURRENCYAMOUNT-AMT_BASE * -1.

ENDIF.

IT_ACCOUNTTAX-ITEMNO_ACC = ITEMNO_ACC.

IT_ACCOUNTTAX-TAX_CODE = GV_MWSKZ.

IT_ACCOUNTTAX-COND_KEY = IT_MWDAT-KSCHL.

IT_ACCOUNTTAX-TAXJURCODE = IT_MWDAT-TXJCD.

IT_ACCOUNTTAX-TAXJURCODE_DEEP = IT_MWDAT-TXJCD_DEEP.

IT_ACCOUNTTAX-TAXJURCODE_LEVEL = IT_MWDAT-TXJLV.

APPEND ACCOUNTTAX.

ENDIF.

ENDLOOP.

So as per the code above, it creates 2 line items in CURRENCYAMOUNT stru for one Tax Line. First line contains actual WRBTR as in internal table and 2nd line contain the WMWST(tax amount) returned by the FM, for the AMT_DOCCUR field.

For example, the internal table contains the following tax line;

BUKRS BLART BLDAT BUDAT WAERS BSCHL SAKNR WRBTR MWSKZ PRCTR SGTXT

CO01 SA 03.06.2009 03.06.2009 EUR 50 331055 500 U1 R11500 Test3

In CurrencyAMOUNT stru I'm getting the following 2 line items for the above 1 line;

ITEMNO_ACC = 1

AMT_DOCCUR = 500

AMT_BASE = 0

ITEMNO_ACC = 2

AMT_DOCCUR = 62.50

AMT_BASE = 500

Please tell me if this is correct or not.

If this is correct, then please tell me whether I need to manually increase the Item number for the secord line item of the tax line.

Thanks for your help.

Skysen

0 Kudos

Hi

Yes u need to increment the item counter for every new item, you report should have a format like this:

LOOP AT IT_DATA.
  CLEAR IT_CURRENCYAMOUNT.
  CLEAR IT_ACCOUNTTAX.
  CLEAR IT_ACCOUNTGL.
  
  ITEMNO_ACC = ITEMNO_ACC + 1.
  
  IF GV_TAX_FLAG = 'X'. " Tax line
    CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
      EXPORTING
        I_BUKRS = GV_BUKRS
        I_MWSKZ = GV_MWSKZ
        I_WAERS = LV_CURRENCY
        I_WRBTR = LV_AMT
      TABLES
        T_MWDAT = IT_MWDAT.
    IF SY-SUBRC = 0.
      IT_CURRENCYAMOUNT-ITEMNO_ACC = ITEMNO_ACC.
      IT_CURRENCYAMOUNT-CURR_TYPE  = '00'.
      IT_CURRENCYAMOUNT-CURRENCY   = LV_CURRENCY.
      IT_CURRENCYAMOUNT-AMT_BASE   = LV_AMT.
      IT_CURRENCYAMOUNT-AMT_DOCCUR = IT_MWDAT-WMWST.
      IF GV_SHKZG = 'H'.
        IT_CURRENCYAMOUNT-AMT_DOCCUR = IT_CURRENCYAMOUNT-AMT_DOCCUR * -1.
        IT_CURRENCYAMOUNT-AMT_BASE   = IT_CURRENCYAMOUNT-AMT_BASE * -1.
      ENDIF.
      APPEND IT_CURRENCYAMOUNT.
      IT_ACCOUNTTAX-ITEMNO_ACC       = ITEMNO_ACC.
      IT_ACCOUNTTAX-TAX_CODE         = GV_MWSKZ.
      IT_ACCOUNTTAX-COND_KEY         = IT_MWDAT-KSCHL.
      IT_ACCOUNTTAX-TAXJURCODE       = IT_MWDAT-TXJCD.
      IT_ACCOUNTTAX-TAXJURCODE_DEEP  = IT_MWDAT-TXJCD_DEEP.
      IT_ACCOUNTTAX-TAXJURCODE_LEVEL = IT_MWDAT-TXJLV.
      APPEND ACCOUNTTAX.
    ELSE.
*&---------------------FOR NON-TAXLINES---------------------------------
      IT_CURRENCYAMOUNT-ITEMNO_ACC = ITEMNO_ACC.
      IT_CURRENCYAMOUNT-ITEMNO_ACC = ITEMNO_ACC.
      IT_CURRENCYAMOUNT-CURR_TYPE  = '00'.
      IT_CURRENCYAMOUNT-CURRENCY   = LV_CURRENCY.      
      IT_CURRENCYAMOUNT-AMT_DOCCUR = IT_DATA-WRBTR.
      IF GV_SHKZG = 'H'.
       IT_CURRENCYAMOUNT-AMT_DOCCUR = IT_CURRENCYAMOUNT-AMT_DOCCUR * -1.
      ENDIF.
      APPEND IT_CURRENCYAMOUNT.
      
      IT_ACCOUNTGL-ITEMNO_ACC = ITEMNO_ACC.
      IT_ACCOUNTGL-GL_ACCOUNT = <account number>.
      IT_ACCOUNTGL-<field>    = <other data>.
      
      APPEND IT_ACCOUNTGL.
    
    ENDIF.
  ENDLOOP.

U make sure the total of amount of every item is equal to zero.

Max

0 Kudos

HI Max

Sorry for late reply. I wasn't able to come online for a week.

Actually, I tried with the same logic what u proposed. It's working.

However, I'm getting the "balance in transaction currency" error. This is due to balance is not tallied. But, in the original file the amount is given correctly.

The thing is, as per the code, if the line item contains Tax then we fill the tax amount(WMWST) in AMT_DOCCUR field and rest of the amount goes to AMT_BASE. For non-tax line items we directly pass the whole document currency to AMT_DOCCUR field. This is the problem.

For example, I have 3 line item. First doesn't have tax. Rest have. The Amount for 1st line item is 250; 2nd line item 250; 3rd - 500.

As the 1st line doesn't have Tax we fill AMT_DOCCUR with 250.

As 2nd line item have tax I apply CALCULATE_TAX_FROM_NET_AMOUT and pass the tax amount to AMT_DOCCUR and document amount to AMT_BASE. That is, say, calculated tax amount(WMWST) is 62.50. So only 62.50 goes to AMT_DOCCUR and 250 goes to AMT_BASE.

Same for 3rd line item. 62.50. So only 62.50 goes to AMT_DOCCUR and 250 goes to AMT_BASE.

But the BAPI takes AMT_DOCCUR for tallying the amount.

So it calculates like ; 25062.5062.50. This is why the amount is not getting tallied.

Please let me know our code is fine.

Or, am I missing something else.

Thank you in advance.

Skysen

0 Kudos

Hi

If you've these 3 items in input:

1- + 250 no tax;

2- + 250 with tax;

3- - 500 with tax;

So:

2- + 250 --- tax 25 % -


> tax value 62,50

3- - 500 --- tax 25% -


> tax value 125;

???

0 Kudos

Hi Max

I'm afraid I don't get that.

Here I'm giving the source and processed data:

Source file:

WRBTR     Tax
250             No
250             Yes
500             Yes

After the execution of the code with the said logic, the currencyamount internal table have following data;

AMT_DOCCUR            AMT_BASE
250.0000                       0.0000
62.5000                         250.0000
125.000-                        500.0000-

(Here balance is -62.50 in AMT_DOCCUR field. This to be adjusted)

Please tell me how to correct this in the code.

Thank you

Skysen.

Edited by: Senthil Vadivel on Sep 22, 2009 4:57 PM

0 Kudos

Hi

That' right, so u should transfer the following items:

A) + 250

B) + 250

C) - 500

  • Tax

B-1) - 62,50 (-250,00)

C-1) + 125,00 (500)

The master data of A), B) and C) has to be transfered to ACCOUNTGL, the master data of B-1) and C-1) to ACCOUNTTAX, all amounts to CURRENCYAMOUNT.

The totals of amount appended in Icurrencyamount internal table has to be ZERO, but don't rember if it needs to update the items where the tax is calculated or BAPI'll automatically update it

So u can try to run the BAPI twice:

First time: transfer to the amount above to CURRENCYAMOUNT

If doesn't work, try

A) + 250

B) + 250 + 62,50 = + 312,50

C) - 500 -125,00 = - 625,00

  • Tax

B-1) - 62,50 (-250,00)

C-1) + 125,00 (500)

Max

0 Kudos

Hi Max

Thanks a lot for your help.

Now I'm able to achieve tax calculation inside my code.

A small correction I was done was the Accounttax needs to be updated at the end. With this I've achieved it with your help.

Thanks again for your help and all quick replies.

Regards

Skysen.

0 Kudos

Senthil, Is there any chance you can post your results?

Im struggling to get this tax posting to work

Edited by: tslatter on Jul 14, 2010 8:43 AM

Former Member
0 Kudos

hi all, i create document(fb01) across BAPI_ACC_DOCUMENT_POST with Tax,

what is message "When you utilize the fast data transfer function, the 'foreign currency translation for tax items' function is not supported."

System Response

It is not possible to carry out this function in conjunction with the fast data transfer function.

Procedure

You can post this transaction using standard batch input functions. It may be possible to have it copied into a batch input session automatically.

How me create document with tax? help me please.

0 Kudos

Hi All,

I am also facing the same problem.

If passing the curr-type as 10 posting is happening.

If 00 is passed it gives error,Foreign currency translation not supported for tax calculation

Kinldy help urgently,

Thanks and Regards,

Nuzhat