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

make BAPI_ACC_DOCUMENT_POST calculate tax.

Former Member
0 Likes
26,662

Hey guys, when using TA FB01, there is a checkbox "calculate tax".

i´m using the BAPI_ACC_DOCUMENT_POST. and i cant find anything correspondant here.

Any ideas, hints, workarounds?

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
15,659

hi Florian,

it won't make, you have to calculate tax on your own before the BAPI call and fill the ACCOUNTTAX parameter (tables) accordingly. For each line, which represents a line for VAT, you need a line in table ACCOUNTTAX.

hope this helps

ec

10 REPLIES 10
Read only

Former Member
0 Likes
15,659

Hi

Hope it will help you,.

<REMOVED BY MODERATOR>

BAPI_ACC_GL_POSTING_CHECK


CALL FUNCTION 'BAPI_ACC_GL_POSTING_CHECK'
EXPORTING
documentheader = w_documentheader
TABLES
accountgl = it_accountgl
currencyamount = it_currencyamount
return = it_return.
 
Populate the corresponding tables with the data you have.
For the Date do convert it.
PERFORM convert_date USING it_header-bldat
CHANGING w_documentheader-doc_date.
 
w_documentheader-comp_code = 'z998'
w_documentheader-doc_type = 'SA'
"and fill the respective tables this way .

<b>

BAPI_ACC_GL_POSTING_POST

</b>


call function 'BAPI_ACC_GL_POSTING_POST'
exporting
documentheader = doc_header
IMPORTING
OBJ_TYPE = l_objtype
* OBJ_KEY =
* OBJ_SYS =
tables
accountgl = t_accountgl
currencyamount = t_curramt
return = t_return
* EXTENSION1 =
.

Edited by: Alvaro Tejada Galindo on Feb 25, 2008 9:32 AM

Read only

vsubbakrishna
Participant
0 Likes
15,659

Hi,

use 'CALCULATE_TAX_FROM_NET_AMOUNT' to calculate the taxes.

Subba

Read only

JozsefSzikszai
Active Contributor
0 Likes
15,660

hi Florian,

it won't make, you have to calculate tax on your own before the BAPI call and fill the ACCOUNTTAX parameter (tables) accordingly. For each line, which represents a line for VAT, you need a line in table ACCOUNTTAX.

hope this helps

ec

Read only

0 Likes
15,659

OMG thanks a lot, who could have guessed that i have to take action myself

now it works.

Read only

0 Likes
15,659

hi

how did you take care of the tax.

I want the same and in 2 different ways, one is system calculating tax and the other is manually sending the tax amount

I also want the calculate tax checkbox checked on the screen

Read only

0 Likes
15,659

Hi Florian,

we also facing the same problem.with the above solution, we tried by passing to table accounttax.getting message documnet posted with key.but i couldn't find the entry in table with that key.are the tables bkpf & bseg where it stores in case of account tax also?

cau send me the code which you have tried for the succes post with tax item and so flag was set.

Its so urgent for us.Please help us.

Thanks in advance.

salini

Read only

0 Likes
15,659

PERFORM build_documentheader
     USING        ls_data
     CHANGING ls_documentheader.

PERFORM build_documentpositions
    TABLES   lt_currencyamount
                   lt_accountgl
                   lt_accounttax
     USING    ls_data.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
            EXPORTING
              documentheader = ls_documentheader
            TABLES
              accountgl      = lt_accountgl
              currencyamount = lt_currencyamount
              accounttax     = lt_accounttax
              return         = lt_return.

NOW the code for the routines:

FORM build_documentheader
  USING    ls_data           LIKE LINE OF gt_data
  CHANGING ls_documentheader TYPE bapiache09.


  ls_documentheader-bus_act     = 'RFBU'.
  ls_documentheader-username    = sy-uname.
  ls_documentheader-pstng_date  = ls_cpudt.
  ls_documentheader-header_txt  = 'Vertreterprovision'.
  ls_documentheader-comp_code   = ls_data-vkorg.
  ls_documentheader-doc_date    = sy-datum.
  ls_documentheader-doc_type    = 'DG'.


ENDFORM.

FORM build_documentpositions
  TABLES   lt_currencyamount    TYPE tt_currencyamount
           lt_accountgl         TYPE tt_acountlg
           lt_accounttax        TYPE tt_accounttax
  USING    ls_data              LIKE LINE OF gt_data.

  DATA:    ls_accountgl         LIKE LINE OF lt_accountgl,
           ls_currencyamount    LIKE LINE OF lt_currencyamount,
           ls_accounttax        LIKE LINE OF lt_accounttax,
           ls_vbrp              TYPE vbrp.

  DATA:    lv_debitor           TYPE kunnr,
           lv_akont             TYPE knb1-akont,
           lv_swap_vbeln        TYPE char20,
           lv_swap_posnr        TYPE char20,
           lv_swap_vbelv        TYPE char20,
           lv_swap_posnv        TYPE char20,
           lv_swap_vtrnr        TYPE char20,
           lv_lkz               TYPE adrc-country,
           lv_land              TYPE t005t-landx,
           lv_tax_code          TYPE c LENGTH 2,
           lv_tax_rate          TYPE fwste.


  CLEAR: lt_currencyamount, lt_accountgl.

  SELECT SINGLE aubel aupos vbelv posnv prctr  "ermittle Auftrag zur Faktura
  FROM   vbrp
  INTO   CORRESPONDING FIELDS OF ls_vbrp
  WHERE  vbeln = ls_data-vbeln
  AND    posnr = ls_data-posnr.


  SELECT SINGLE akont
  FROM   knb1
  INTO   lv_akont
  WHERE  kunnr = ls_data-vtrnr
  AND    bukrs = ls_data-bukrs.


*
* 04.02.2008 FIS/pb
* Korrektur : Land steht schon in der KNA1
*

  SELECT SINGLE land1
  FROM   kna1
  INTO   lv_lkz
  WHERE  kunnr = ls_data-vtrnr.

*  break fis-kemmer.

  IF ls_data-vtrnr EQ '0000900021' OR ls_data-vtrnr EQ '0000900008'.
    lv_tax_code = '46'.
    ls_accounttax-itemno_acc = '03'.
    ls_accounttax-tax_code   = lv_tax_code.
    ls_accounttax-gl_account   = '0000263110'.
    ls_accounttax-direct_tax = 'X'.
    ls_accounttax-cond_key    = 'MWVS'.
    ls_accounttax-acct_key    = 'VST'.
    APPEND ls_accounttax TO lt_accounttax.
    CLEAR  ls_accounttax.
    ls_currencyamount-amt_base = ls_data-prov.
  ELSE.
    CASE lv_lkz.
      WHEN 'DE'.
        lv_tax_code = 'V1'.
      WHEN OTHERS.
        lv_tax_code = 'U7'.
    ENDCASE.
  ENDIF.

  ls_accountgl-itemno_acc = '01'.
  ls_accountgl-gl_account = lv_akont.
  ls_accountgl-tax_code   = lv_tax_code.
  ls_accountgl-customer   = ls_data-vtrnr.
  ls_accountgl-acct_type  = 'D'.

  WRITE ls_data-vbeln TO lv_swap_vbeln LEFT-JUSTIFIED NO-ZERO.
  WRITE ls_data-posnr TO lv_swap_posnr LEFT-JUSTIFIED NO-ZERO.
  WRITE ls_data-vtrnr TO lv_swap_vtrnr LEFT-JUSTIFIED NO-ZERO.
  WRITE ls_vbrp-vbelv TO lv_swap_vbelv LEFT-JUSTIFIED NO-ZERO.
  WRITE ls_vbrp-posnv TO lv_swap_posnv LEFT-JUSTIFIED NO-ZERO.

  CONDENSE: lv_swap_vbeln, lv_swap_posnr, lv_swap_vtrnr, lv_swap_vbelv, lv_swap_posnv.

  CONCATENATE lv_swap_vbeln ';'
              lv_swap_posnr ';'
              lv_swap_vtrnr ';'
              lv_swap_vbelv ';'
              lv_swap_posnv ';'
              ls_data-name1
  INTO ls_accountgl-item_text.

  APPEND ls_accountgl TO lt_accountgl.
  CLEAR  ls_accountgl.

  ls_currencyamount-itemno_acc = '01'.
  ls_currencyamount-curr_type  = '00'.
  ls_currencyamount-currency   = ls_data-waers.
  ls_currencyamount-amt_doccur = ls_data-prov * -1.

  APPEND ls_currencyamount TO lt_currencyamount.
  CLEAR ls_currencyamount.

  ls_accountgl-itemno_acc = '02'.
  ls_accountgl-gl_account = p_konto.
  ls_accountgl-tax_code   = lv_tax_code.
  CONCATENATE ls_data-vbeln ls_data-posnr INTO ls_accountgl-item_text.
  ls_accountgl-profit_ctr = ls_vbrp-prctr.
  ls_accountgl-sales_ord  = ls_vbrp-vbelv.
  ls_accountgl-s_ord_item = ls_vbrp-posnv.

  APPEND ls_accountgl TO lt_accountgl.
  CLEAR  ls_accountgl.

  CALL FUNCTION 'RECP_FI_TAX_CALCULATE'
    EXPORTING
      ic_bukrs    = '1000'
      ic_mwskz    = lv_tax_code
      ic_waers    = 'EUR'
    IMPORTING
      ep_tax_rate = lv_tax_rate
    EXCEPTIONS
      not_found   = 1
      OTHERS      = 2.

  IF sy-subrc <> 0.

  ENDIF.

  ls_currencyamount-itemno_acc = '02'.
  ls_currencyamount-curr_type  = '00'.
  ls_currencyamount-currency   = ls_data-waers.
  ls_currencyamount-amt_doccur = ls_data-prov - ( ls_data-prov / 100 * lv_tax_rate ).

  APPEND ls_currencyamount TO lt_currencyamount.
  CLEAR ls_currencyamount.

  IF ls_data-vtrnr EQ '0000900021' OR ls_data-vtrnr EQ '0000900008'.
    ls_currencyamount-itemno_acc = '03'.
    ls_currencyamount-curr_type  = '00'.
    ls_currencyamount-currency   = ls_data-waers.
    ls_currencyamount-amt_base   = ls_data-prov .
    ls_currencyamount-amt_doccur = ls_data-prov / 100 * lv_tax_rate.

    APPEND ls_currencyamount TO lt_currencyamount.
    CLEAR  ls_currencyamount.
  ENDIF.
ENDFORM. 
Read only

0 Likes
15,659

Hi ,

we also facing the same problem. we tried by passing to table accounttax.getting message documnet posted with key.but icouldn't find the entry in table with that key.are the tables bkpf & bseg where it stores in case of account tax also?

cau send me the code which you have tried for the succes post with tax item and so flag was set.

Its so urgent for us.Please help us.

Thanks in advance.

salini

Read only

0 Likes
15,659

Thanks for your reply.can you check the following code and.its returning me the doc no but no doc posted in bkpf & bseg tables.

Thanks in advance

wa_documentheader-username = im_header-zz_req_by.

wa_documentheader-header_txt = im_header-bktxt.

wa_documentheader-comp_code = im_header-zz_charg_bukrs.

wa_documentheader-doc_date = sy-datum.

wa_documentheader-pstng_date = sy-datum.

wa_documentheader-doc_type = im_header-blart.

wa_documentheader-bus_act = 'RFBU'.

wa_documentheader-ref_doc_no = 'testing'.

  • fill GL (line 1)

tb_accountgl-itemno_acc = 1.

tb_accountgl-comp_code = im_header-zz_charg_bukrs.

tb_accountgl-gl_account = '0000800000'.

tb_accountgl-item_text = '#630020$5109669400\5109673020'.

tb_accountgl-costcenter = '1101810007'.

tb_accountgl-tax_code = 'P1'.

APPEND tb_accountgl.

tb_currencyamount-itemno_acc = 1.

tb_currencyamount-curr_type = '00'.

tb_currencyamount-currency = 'AUD'.

tb_currencyamount-amt_doccur = '150.00'.

APPEND tb_currencyamount.

tb_accountgl-itemno_acc = 2.

tb_accountgl-comp_code = im_header-zz_charg_bukrs.

tb_accountgl-gl_account = '0000121710'.

TB_ACCOUNTGL-ITEM_TEXT = '#630020$5109669400\5109673020'.

APPEND tb_accountgl.

tb_currencyamount-itemno_acc = 2.

tb_currencyamount-curr_type = '00'.

tb_currencyamount-currency = 'AUD'.

tb_currencyamount-amt_doccur = '-125.00'.

APPEND tb_currencyamount.

tb_accounttax-itemno_acc = 3.

tb_accounttax-gl_account = '0000121710'.

tb_accounttax-tax_code = 'P1'.

tb_accounttax-TAX_RATE = '20'.

APPEND tb_accounttax.

tb_currencyamount-itemno_acc = 3.

tb_currencyamount-curr_type = '00'.

tb_currencyamount-currency = 'AUD'.

tb_currencyamount-amt_doccur = '-25.00'.

tb_currencyamount-tax_amt = '-25.00'.

tb_currencyamount-amt_base = '-125.00'.

APPEND tb_currencyamount.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = wa_documentheader

customercpd = wa_customercpd

IMPORTING

obj_type = wf_obj_type

obj_key = wf_obj_key

obj_sys = wf_obj_sys

TABLES

accountgl = tb_accountgl

accountreceivable = tb_accountreceivable

accountpayable = tb_accountpayable

accounttax = tb_accounttax

currencyamount = tb_currencyamount

criteria = tb_criteria

valuefield = tb_valuefield

extension1 = tb_extension1

return = tb_return

paymentcard = tb_paymentcard

contractitem = tb_contractitem

extension2 = tb_extension2

realestate = tb_realestate.

READ TABLE tb_return INDEX 1.

  • Sucessfull posting

IF tb_return-type = 'S'.

wa_fi_docno = tb_return-message_v2.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

IMPORTING

return = tb_return.

Endif.

Read only

Erol_CAGLAR
Participant
15,658

Hi ,

it is important ACCOUNTTAX table. if your taxcode is provide taxamount with out zero. .you can use below code. in lt_tax has different item(position) number than currency amount.

position number is important here. split item one two items. position 5 is tax.

This gl_account is coming from calculate_tax method..

you must only give tax_code if really calculated .

DATA : ls_dochead TYPE bapiache09,
lt_curr TYPE STANDARD TABLE OF bapiaccr09,
ls_curr TYPE bapiaccr09,
lt_acgl TYPE STANDARD TABLE OF bapiacgl09,
ls_acgl TYPE bapiacgl09,
ls_zaccit TYPE zaccextension2,
lt_ext2 TYPE STANDARD TABLE OF bapiparex,
ls_ext2 TYPE bapiparex,
lt_tax TYPE STANDARD TABLE OF bapiactx09,
ls_tax TYPE bapiactx09.
DATA : lv_line TYPE i.
"ls_dochead-obj_type = 'BKPF'.
ls_dochead-username = sy-uname.
ls_dochead-header_txt = af_sgtxt.
ls_dochead-comp_code = af_bukrs.
ls_dochead-fisc_year = af_budat(4).
ls_dochead-fis_period = af_budat+4(2).
ls_dochead-doc_date = af_budat.
ls_dochead-pstng_date = af_bldat.
ls_dochead-trans_date = af_bldat.
ls_dochead-doc_type = 'SA'.
ls_dochead-ref_doc_no = af_xblnr.
lv_line = lines( at_data ).


LOOP AT at_data INTO DATA(ls_data).
ls_acgl-itemno_acc = sy-tabix .

ls_acgl-gl_account = |{ ls_data-hkont ALPHA = IN }|.
ls_acgl-item_text = ls_data-sgtxt.

ls_acgl-ref_key_1 = ls_data-ref_key_1.

ls_acgl-doc_type = 'SA'.
ls_acgl-comp_code = af_bukrs.
ls_acgl-func_area_long = ls_data-func_area.
ls_acgl-fis_period = af_budat+4(2).
ls_acgl-fisc_year = af_budat(4).
ls_acgl-pstng_date = ls_dochead-pstng_date.
ls_acgl-value_date = ls_dochead-pstng_date.
ls_acgl-costcenter = |{ ls_data-kostl ALPHA = IN }|..
ls_acgl-profit_ctr = ls_data-prctr.
ls_acgl-orderid = |{ ls_data-orderid ALPHA = IN }|.
ls_acgl-sales_ord = |{ ls_data-sales_ord ALPHA = IN }|.
ls_acgl-s_ord_item = |{ ls_data-s_ord_item ALPHA = IN }|.
ls_acgl-wbs_element = ls_data-wbs_element.
ls_acgl-tax_code = ls_data-tax_code.
ls_acgl-taxjurcode = ls_data-taxjurcode.
ls_acgl-segment = ls_data-segment.




ls_curr-itemno_acc = ls_acgl-itemno_acc.
ls_curr-currency = af_waers.

CASE ls_data-shkzg.

WHEN 'H'.
ls_curr-amt_doccur = ls_data-amt_doccur * -1.

WHEN 'S'.
DATA : lv_wrbtr TYPE wrbtr .
lv_wrbtr = ls_data-amt_doccur .
DATA(ls_ctax) = calculate_tax(
EXPORTING
i_wrbtr = lv_wrbtr
i_mwskz = ls_data-tax_code " Tax on sales/purchases code
).
IF ls_ctax-kawrt NE lv_wrbtr.
ls_curr-amt_doccur = ls_ctax-kawrt.
ls_curr-amt_base = ls_data-amt_doccur.
ls_tax-itemno_acc = ls_acgl-itemno_acc + lv_line.
ls_tax-gl_account = ls_ctax-hkont.
ls_tax-tax_code = ls_data-tax_code.

ELSE.
ls_curr-amt_doccur = ls_data-amt_doccur .
ENDIF.

ENDCASE.

IF ls_data-gac NE space.
ls_zaccit-posnr = ls_acgl-itemno_acc .
ls_zaccit-zzgac = ls_data-gac.
ls_ext2-structure = 'ZACCEXTENSION2'.
ls_ext2-valuepart1 = ls_zaccit.
APPEND ls_ext2 TO lt_ext2.

ENDIF.

APPEND ls_acgl TO lt_acgl.
APPEND ls_curr TO lt_curr.

IF ls_tax-itemno_acc IS NOT INITIAL.
APPEND ls_tax TO lt_tax.
ls_curr-amt_doccur = ls_ctax-wmwst.
ls_curr-itemno_acc = ls_acgl-itemno_acc + lv_line .
APPEND ls_curr TO lt_curr.
ENDIF.


CLEAR : ls_tax , ls_curr , ls_ext2, ls_acgl.
ENDLOOP.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = ls_dochead
* CUSTOMERCPD =
* CONTRACTHEADER =
tables
ACCOUNTGL = lt_acgl
* ACCOUNTRECEIVABLE =
* ACCOUNTPAYABLE =
ACCOUNTTAX = lt_tax
CURRENCYAMOUNT = lt_curr
* CRITERIA =
* VALUEFIELD =
* EXTENSION1 =
return = et_messages
* PAYMENTCARD =
* CONTRACTITEM =
EXTENSION2 = lt_ext2
* REALESTATE =

* ACCOUNTWT =

.

*value( I_WRBTR ) TYPE WRBTR Amount in Document Currency

*value( I_MWSKZ ) TYPE MWSKZ Tax on sales/purchases code

*value( E_TAX ) TYPE RTAX1U15 Tax Rate and Tax Amount for a Tax Code

method CALCULATE_TAX.


DATA : LT_MWDAT TYPE STANDARD TABLE OF RTAX1U15.

CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
EXPORTING
i_bukrs = af_bukrs
i_mwskz = I_MWSKZ
* I_TXJCD = ' '
i_waers = af_waers
i_wrbtr = I_WRBTR


TABLES
T_MWDAT = LT_MWDAT
EXCEPTIONS
BUKRS_NOT_FOUND = 1
COUNTRY_NOT_FOUND = 2
MWSKZ_NOT_DEFINED = 3
MWSKZ_NOT_VALID = 4
ACCOUNT_NOT_FOUND = 5
DIFFERENT_DISCOUNT_BASE = 6
DIFFERENT_TAX_BASE = 7
TXJCD_NOT_VALID = 8
NOT_FOUND = 9
KTOSL_NOT_FOUND = 10
KALSM_NOT_FOUND = 11
PARAMETER_ERROR = 12
KNUMH_NOT_FOUND = 13
KSCHL_NOT_FOUND = 14
UNKNOWN_ERROR = 15
OTHERS = 16
.
IF sy-subrc = 0.
READ TABLE LT_MWDAT INTO E_TAX INDEX 1.
ENDIF.

endmethod.


Best wishes

Erol ÇAĞLAR