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

Getting error in BAPI_ACC_DOCUMENT_POST

Former Member
0 Likes
7,075

Hi all, I'm using this BAPI, and it works fine,

but now the requirement is to add the tax calculation.

I add the i_accountax to the call:

* Posting to accounting.

     CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

       EXPORTING

         documentheader    = w_header

       IMPORTING

         obj_type          = l_type

         obj_key           = l_key

         obj_sys           = l_sys

       TABLES

         accountgl         = i_accountgl

         accountreceivable = i_accountre

         accounttax        = i_accountax

         currencyamount    = i_curren

         return            = i_return.

I execute the BAPI with following data:

w_header
BUS_ACTRFBU
USERNAMECGOMEZ
HEADER_TXTVTA. PROD. Y/O SERVI
COMP_CODE3000
DOC_DATE20120625
PSTNG_DATE20120625
FISC_YEAR2012
FIS_PERIOD6
DOC_TYPEDR
REF_DOC_NO117

i_curren
ITEMNO_ACCCURRENCYAMT_DOCCURAMT_BASETAX_AMT
30MXN48418.4000-41740.0000-6678.4000-
20MXN34962.4000-30140.0000-4822.4000-
10MXN83380.87188011500.8
i_accountre
ITEMNO_ACCCUSTOMERGL_ACCOUNTCOMP_CODEPMNTTRMSBLINE_DATEITEM_TEXTTAX_CODE
103000051210003000NT3020120625Venta Aceite UsadoA2
i_accountgl
ITEMNO_ACCGL_ACCOUNTITEM_TEXTCOMP_CODEPLANTFIS_PERIODFISC_YEARPSTNG_DATEVALUE_DATETAX_CODECOSTCENTER
20700100Aceite Usado, Nov 2030003000620122012062520120625A23061000002
30700100Aceite Usado, Dic 2030003000620122012062520120625A23061000002

And i_accountax:

ITEMNO_ACC

GL_ACCOUNT

TAX_CODE

DIRECT_TAX

30

230005

A2

X

20

230005

A2

X

10

230005

A2

X

When I test the code, I get the error:

E RW 14           FI/CO interface: Line item entered several times $ 0000000010 0 QASCLNT010

What am I doing wrong?

I will appreciate any guidance with this.

17 REPLIES 17
Read only

Former Member
0 Likes
5,264

Hi

I suppose the problem is you're appending some items twice: one in customer or g/l section and one in tax section.

You need to insert those items in one section only, so in tax section you should set only one item (I suppose 40) for tax

Max

Read only

0 Likes
5,264

Thanks for your reply Max,

I changed the information i_accountax as you suggested, I also added the COND_KEY:

ITEMNO_ACCGL_ACCOUNTCOND_KEYTAX_CODEDIRECT_TAX
40230005MWASA2X

But now returns the error:

No currency line exists for line item 0000000040
0000000000000040


ACCOUNTTAX

Read only

0 Likes
5,264

Check this link

http://www.sapfans.com/forums/viewtopic.php?t=137643&highlight=bapiaccdocumentpost

it's very similar to your requirement.

Read only

0 Likes
5,264

Hi

You need to add the line in currency section of course:

You can use the fm CALCULATE_TAX_FROM_NET_AMOUNT in order to calculate the amount to be assigned

Max

Read only

0 Likes
5,264

Thanks for reply Max, I think I don't have to calculate the tax myself,

we are going to get that info from a file. In i_curren I have to add the

line and 11500.8 is the tax amount, but I don't know how to fill correctly

the i_curren structure, I'm getting the error:

Balance in transaction currency

i_curren
ITEMNO_ACCCURRENCYAMT_DOCCURAMT_BASETAX_AMT
30MXN48418.4000-41740.0000-6678.4000-
20MXN34962.4000-30140.0000-4822.4000-
10MXN83380.871880

11500.8

How should I fill the row missing?

Read only

0 Likes
5,264

Hi

I believe you need to tranfer the net amount to G/L item:

ITEMNO_ACC
CURRENCY
AMOUNT
10MXN83380.80
20MXN-30140.00
30MXN-41740.00
40MXN-11500.80

I don't believe you need to fill the tax and base amount

Max

Read only

0 Likes
5,264

Thanks a lot Max!

That solved the problem

Now I need to add the witholding tax calculation, I have the data in the file too, but I don't know how to fill the accountwt table. I'm filling the tables this way:

i_accountwt

ITEMNO_ACC

WT_TYPE

WT_CODE

BAS_AMT_LC

AWH_AMT_LC

12

M6

2

71880.0000-

11500.8000-

i_accountax

ITEMNO_ACC

GL_ACCOUNT

COND_KEY

ACCT_KEY

TAX_CODE

DIRECT_TAX

11

230005

MWAS

MWS

A2

X

i_curren

ITEMNO_ACC

CURRENCY

AMT_DOCUR

AMT_BASE

TAX_AMT

30

MXN

     41740.0000-

6678.4000-

20

MX 

     30140.0000

4822.4000-

11

MXN

     11500.8000

71880.0000

12

MXN

      11500.8000

71880.0000

10

MXN

83380.8000

71880.0000

11500.8000

What am I doing wrong?

Read only

0 Likes
5,264

Hi

I suppose the ITEMNO_ACC  is item number of item vendor, so here you need to indicate the base amount only (usually the withholding tax value will be calculated automatically while clearing the document):

ITEMNO_ACCWT_TYPEWT_CODEBAS_AMT_TC
<vendor item number>M62base amount

The base amount depends on the type of withholding tax code: usually it's just a part only of the net amount of vendor

Max

Read only

0 Likes
5,264

Thanks again Max,

I changed the i_accountwt as you suggested.

But It doesn't appear the witholding tax line in the document at the end. I filled i_curren this way:

And this is the document generated:

Any idea how to solve the issue?

Read only

0 Likes
5,264

Hi

The witholding tax shouldn't be shown in the items of the document, but in a special section of your document.

You should see the a push button in the menu bar to go to withholding tax data.

Max

Read only

0 Likes
5,264

The thing is that is showing that line in a document generated manually.

Perhaps is a configuration issue?

Read only

0 Likes
5,264

Hi,

I think you do not need to append negative amount, just provide posting keys and based on posting keys SAP will calculate the balance.

Regards,

Prashant

Read only

0 Likes
5,264

Hi Karina,

How would you solve this, i am facing same. Could you please help me out.

Thanks in advance.

Ramesh J.

Read only

StarDev
Participant
0 Likes
5,264

Hello karina.

Could you please help me out. I am also stuck with the same problem. How to fill the accounttax and corresponding currencyamount enteries for service tax calculation ? I am using

  CALCULATE_TAX_FROM_NET_AMOUNT to calculate the tax amount. How should I pass it into various tables of bapi. What should be the AMT-base, amt-doccur for posting key 40 ?

Read only

Former Member
0 Likes
5,264

This message was moderated.

Read only

0 Likes
5,264

Hi,

Please find the code:

CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
     EXPORTING
       I_BUKRS                 = wa_hdr2-bukrs
       I_MWSKZ                 = wa_hdr2-mwskz
*     I_TXJCD                 = ' '
       I_WAERS                 = 'INR'
       I_WRBTR                 = wrbtr
    IMPORTING
*     E_FWNAV                 =
*     E_FWNVV                 =
      E_FWSTE                 = fwste
    tables
      T_MWDAT                 = T_MWDAT
  .
   IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.
   wa_hdr2-ZRB_STAMT1 = wrbtr + fwste.
*dtlamt = wa_hdr2-ZRB_STAMT.
*condense dtlamt.

ENDIF.

***G/L bill wise Line item entries
it_accgl-ITEMNO_ACC = count.
it_accgl-GL_ACCOUNT = wa_hdr2-saknr1.
it_accgl-item_text  = wa_hdr2-zrb_schno.
it_accgl-comp_code  = wa_hdr2-bukrs.

*read table it_aufk with key aufnr = wa_hdr2-aufnr.
*IF sy-subrc = 0.
*it_accgl-bus_area   = it_aufk-gsber.
*it_accgl-item_text  = it_aufk-ktext.
*ENDIF.
*it_accgl-plant      = wa_hdr-werks.
it_accgl-FISC_YEAR  = l_gjahr."wa_hdr2-gjahr.
*it_accgl-VENDOR_NO   = wa_hdr2-lifnr.
it_accgl-TAX_CODE    = wa_hdr2-mwskz.
*it_accgl-ALLOC_NMBR = wa_hdr2-zrb_refno. " Doubt

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
   EXPORTING
     INPUT         = wa_hdr2-kostl
  IMPORTING
    OUTPUT        = it_accgl-COSTCENTER.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
   EXPORTING
     INPUT         = wa_hdr2-prctr
  IMPORTING
    OUTPUT        = it_accgl-PROFIT_CTR.

*it_accgl-COSTCENTER = wa_hdr2-kostl.
*it_accgl-PROFIT_CTR = wa_hdr2-prctr.
*it_accgl-orderid    = wa_hdr2-aufnr. " Order Number
*it_accgl-BILL_TYPE  = it_wb2-fkart.
**it_accgl-sales_ord  = it_wb2-auble.
**it_accgl-S_ORD_ITEM = wa_hdr2-posnr.
*it_accgl-DISTR_CHAN = it_wb2-vtweg.
*it_accgl-DIVISION   = wa_hdr2-spart.
*it_accgl-SALESORG   = wa_hdr2-vkorg.
*it_accgl-sales_grp  = it_wb2-vkgrp.
*it_accgl-sales_off  = it_wb2-vkbur.
*it_accgl-sold_to    = wa_hdr2-kunnr.
**it_accgl-DE_CRE_IND = 'S'.
*it_accgl-BASE_UOM   = 'TO'.
*it_accgl-INV_QTY_SU = wa_hdr2-fkimg.
*it_accgl-MATERIAL   = it_wb2-matnr.
append it_accgl.
clear it_accgl.

*IF wa_hdr2-shkzg = 'S'.
*cramt = 0 - cramt.
**wa_hdr-zrb_secamt = 0 - wa_hdr-zrb_secamt.
*ENDIF.







**************Vendor
  it_vend-ITEMNO_ACC = 1.
  it_vend-VENDOR_NO = wa_hdr2-lifnr.
  it_vend-tax_code  = wa_hdr2-mwskz.
  it_vend-comp_code = wa_hdr2-bukrs.
* read table it_aufk with key aufnr = wa_hdr2-aufnr.
* IF sy-subrc = 0.
* it_vend-bus_area   = it_aufk-gsber.
* it_vend-item_text  = it_aufk-ktext.
* ENDIF.
  it_vend-ALLOC_NMBR = wa_hdr2-aufnr.
  IT_VEND-BUSINESSPLACE wa_hdr2-bupla."werks.
  IT_VEND-SECTIONCODE wa_hdr2-bupla."werks.
* it_vend-ref_key_1 = wa_hdr-aufnr.
* it_vend-bline_date = us_dt.
  SELECT SINGLE ZTERM from lfb1 INTO it_vend-PMNTTRMS WHERE lifnr = wa_hdr2-lifnr.
* it_vend-PMNTTRMS =
  if wrbtr is not initial.
  append it_vend.
  endif.


*IF wa_hdr2-shkzg = 'H'.
wa_hdr2-ZRB_STAMT1 = 0 - wa_hdr2-ZRB_STAMT1. "Vendor Amt
*ENDIF.

**************Vendor


it_curr-ITEMNO_ACC = 1.
it_curr-CURRENCY   = 'INR'.
it_curr-AMT_DOCCUR = wa_hdr2-ZRB_STAMT1.
append it_curr.
clear it_curr.

  clear it_cust.

if wrbtr is not initial.
*cramt = 0 - cramt.
it_curr-ITEMNO_ACC = count.
it_curr-CURRENCY   = 'INR'.
it_curr-AMT_DOCCUR = wrbtr.
append it_curr.
endif.
clear it_curr.



****** Filling Tax Table
count = count + 1.
LOOP AT t_mwdat.

it_curr-ITEMNO_ACC = count.
it_curr-AMT_DOCCUR = t_mwdat-wmwst.
it_curr-CURRENCY   = 'INR'.
it_curr-amt_base   = t_mwdat-kawrt.

it_tax-ITEMNO_ACC  = count.
it_tax-GL_ACCOUNT  = t_mwdat-hkont.
it_tax-COND_KEY    = t_mwdat-KSCHL.
it_tax-ACCT_KEY    = t_mwdat-KTOSL.
it_tax-TAX_CODE    = wa_hdr2-mwskz.

it_tax-DIRECT_TAX  = 'X'.


append it_curr.
append it_tax.
clear: it_tax,it_curr.
count = count + 1.

ENDLOOP.

*****filling Withholding Tax

loop at it_taxcode.
READ TABLE IT_LFBW WITH KEY WITHT = it_taxcode-WITHT.
IF SY-SUBRC = 0.
it_wtax-ITEMNO_ACC  = 1.
it_wtax-WT_TYPE     = it_taxcode-WITHT.
it_wtax-WT_CODE     = it_taxcode-WT_WITHCD.

append it_wtax.
clear it_wtax.
ENDIF.
ENDLOOP.


*****Filling Document Header
  if cramt is not initial.
  wa_dochdr-USERNAME = sy-uname.
  wa_dochdr-HEADER_TXT = wa_hdr2-zrb_schno."
  wa_dochdr-comp_code = wa_hdr2-bukrs.
  wa_dochdr-DOC_DATE   = wa_hdr2-bldat."us_dt.
  wa_dochdr-PSTNG_DATE = us_dt.
  wa_dochdr-FISC_YEAR  = l_gjahr."wa_hdr2-gjahr.
*IF wa_hdr-shkzg = 'H'.
* wa_dochdr-DOC_TYPE   = 'KR'.
* elseif wa_hdr-shkzg = 'S'.
  wa_dochdr-DOC_TYPE   = 'KR'.
*endif.
  wa_dochdr-ref_doc_no = wa_hdr2-ZRB_CRID."'Vendor A/C'.
endif.



sort it_accgl[] by ITEMNO_ACC.
sort it_curr[] by ITEMNO_ACC.
sort it_accgl1[] by ITEMNO_ACC.
sort it_curr1[] by ITEMNO_ACC.
l_error = 0.
if WRBTR is not initial.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
   EXPORTING
     DOCUMENTHEADER          = wa_dochdr
  TABLES
    ACCOUNTGL                = it_accgl
    ACCOUNTRECEIVABLE        = it_cust
    ACCOUNTPAYABLE           = it_vend
    ACCOUNTTAX               = it_tax
    CURRENCYAMOUNT           = it_curr
    CRITERIA                 = it_crit
     RETURN                  = it_ret
     ACCOUNTWT               = it_wtax.

if no error found:


CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
   EXPORTING
     DOCUMENTHEADER          = wa_dochdr
  IMPORTING
    OBJ_KEY                  = wa_objkey
  TABLES
    ACCOUNTGL                = it_accgl
    ACCOUNTRECEIVABLE        = it_cust
    ACCOUNTPAYABLE           = it_vend
    ACCOUNTTAX               = it_tax
    CURRENCYAMOUNT           = it_curr
    CRITERIA                 = it_crit
     RETURN                  = it_ret
     ACCOUNTWT               = it_wtax.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    WAIT          = 'X'
* IMPORTING
*   RETURN        =
           .

Regards

Pankaj Mittal

Read only

0 Likes
5,264

Hi Adesh,

Before writing any code, create a test case data in SE37 .. So that it will be helpful to identify the any other problem while posting the document.

Regards

Pankaj Mittal