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

Problem with TAX-Line using BAPI_ACC_DOCUMENT_POST

Former Member
0 Likes
2,385

Hi friends!

I'm stuck for days now and hope you can help me!

I want to automate Invoice posting via BAPI_ACC_DOCUMENT_POST which our company is posting manualy through FB01 right now.

Here is a sample Invoice posted through FB01 that I want to post with the BAPI:

1 218.76 u20AC (=Vendor Line INCLUDING TAX) --> 183.83u20AC without TAX

2 93.46 u20AC (= first customer position in invoice, NO TAX)

3 31.90u20AC (= second customer position in invoice, NO TAX)

4 58.47 (= third customer position in invoice. NO TAX)

5 34.93 (= TAX) --> 34.93u20AC + 183.83u20AC = 218.76u20AC

I use BAPI_ACC_DOCUMENT_POST to generate exactly the same invoice as posted above with FB01.

The Problem is, my Invoice don't has the TAX-Line and I don't know why...I read hundreds of threads here on how to populate accounttax-table but no success!

Right now I can only post a Invoice with BAPI_ACC_DOCUMENT_POST without TAX; thats why I use the amount of 183.93u20AC for the first position (=vendor); otherwise I would get the error that the invoice is not balanced and the SUM is no

When I check the Table BSET there is even a entry for my invoice but the tax is set to zero allthough I set

currencyamount-AMT_BASE = '34.93'

Here is my code:


*&---------------------------------------------------------------------*
*       KOPFDATEN
*----------------------------------------------------------------------*
        documentheader-BUS_ACT = 'RFBU'.
        documentheader-USERNAME = sy-uname.
        documentheader-HEADER_TXT = 'some text'.
        documentheader-COMP_CODE = '0025'.
        documentheader-DOC_DATE = sy-datum - 10.
        documentheader-PSTNG_DATE = sy-datum.
        documentheader-DOC_TYPE = 'KR'.
        documentheader-REF_DOC_NO = 'some ref doc no'.

*&---------------------------------------------------------------------*
*       First Line in Invoice (Vendor)
*----------------------------------------------------------------------*
        accountpayable-ITEMNO_ACC = 1.                                         
        accountpayable-VENDOR_NO = '0000017770'.                             
        accountpayable-BUS_AREA = '0005'.                                     
        accountpayable-PMNTTRMS = 'ZB30'.                                      
        accountpayable-ALLOC_NMBR = 'some text'.                               
        accountpayable-ITEM_TEXT = 'some text'.                                
        accountpayable-TAX_CODE = 'K1'.                                        
        accountpayable-PARTNER_BK = '2'.                                      
        APPEND accountpayable.

        currencyamount-ITEMNO_ACC = 1.
        currencyamount-curr_type = '00'.
        currencyamount-CURRENCY = 'EUR'.
        currencyamount-AMT_DOCCUR = ( 218.76 - 34.93 ) * -1.    "= 183.83u20AC which is the SUM without TAX
*        currencyamount-AMT_DOCCUR = ( 218.76 ) * -1.    "the actual amount for position 1 that I need to use INCLUDING TAX
        APPEND currencyamount.

*&---------------------------------------------------------------------*
*       Lines 2...n-1 = Customers
*----------------------------------------------------------------------*
        LOOP AT lt_cvs_pos.
          accountgl-ITEMNO_ACC = sy-tabix + 1.
          accountgl-GL_ACCOUNT = '0000447400'.
          accountgl-ITEM_TEXT = 'some text'.
          accountgl-BUS_AREA = '0005'.
          accountgl-ALLOC_NMBR = 'some text'.
          accountgl-TAX_CODE = 'K1'.
          accountgl-COSTCENTER = '108'.                      
          APPEND accountgl.

          currencyamount-ITEMNO_ACC = sy-tabix + 1.
          currencyamount-curr_type = '00'.
          currencyamount-CURRENCY = 'EUR'.
          currencyamount-AMT_DOCCUR = <the three invoice amounts: 93.46u20AC, 31.90u20AC and 58.47u20AC all with NO TAX included>.
          APPEND currencyamount.
          n = sy-tabix + 1.
        ENDLOOP.

*&---------------------------------------------------------------------*
*       POSITIONSDATEN n befüllen = Umsatzsteuer
*----------------------------------------------------------------------*
        accounttax-ITEMNO_ACC = n.                             "n=5 in this case
*        accounttax-gl_account = '0000152100'.
        accounttax-cond_key = 'MWVS'.                                          
        accounttax-acct_key = 'VST'.
        accounttax-tax_code = 'K1'.
*        accounttax-tax_rate = '19'.
*        accounttax-tax_date = sy-datum.
*        accounttax-itemno_tax = 1.

        currencyamount-ITEMNO_ACC = n.
        currencyamount-curr_type = '00'.                                      
        currencyamount-CURRENCY = 'EUR'.
        currencyamount-AMT_DOCCUR = '218.76'.
        currencyamount-AMT_BASE = '34.93'. 
        APPEND currencyamount.

*&---------------------------------------------------------------------*
*       Daten verbuchen
*----------------------------------------------------------------------*
        CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
          EXPORTING
            documentheader = documentheader
          TABLES
            accountgl = accountgl
            accountpayable = accountpayable
            accounttax = accounttax
            currencyamount = currencyamount
            return = return.

I don't understand what I'm doing wrong as everything looks fine to me but as I said no TAX-Line is posted allthough specified here.

When I check Table BSET for the created invoice there is also a entry there but the tax-amount = 0.

any help please?!!!?

1 ACCEPTED SOLUTION
Read only

Former Member
1,730

test

 test 

4 REPLIES 4
Read only

Former Member
1,731

test

 test 

Read only

0 Likes
1,730

Hi jazy,

I can not see the Append to the internal table ACCOUNTTAX.

You can also try:

accounttax-itemno_acc = n + 1.

accounttax-itemno_tax = n.

Regards,

Carlos.

Read only

0 Likes
1,730

Hi Carlos,

OMG sometimes the solutions are too simple for one to see

THAT WAS THE PROBLEM...I had forgotten the APPEND

Now I have one last question/problem

I Think everything will work fine now - the only thing is, I get the error message when calling the BAPI that the balance of the invoice is not zero.

Is there a way to debug and see what amounts the BAPI would save to the TABLES so I can exactly see on what Invocie position I have to adjust the amount so the balance is equal because right now I just see the problem, but I don't now if the TAX-calculation is wrong or the customer-line-amounts...I hope you understand what I mean

cheers,

jazy

Read only

0 Likes
1,730

ok I could solve the balance-problem myself !

the invoice is now posted correctly and I'm happy and done with this project

thx again carlos!!!!

cheers