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

BAPI_ACC_DOCUMENT_POST and tax posting through the BAPI

Former Member
0 Likes
21,544

Hi,

We are using the BAPI_ACC_DOCUMENT_POST to post accounting documents. The BAPI works fine without the tax data but we need the tax data also to get posted for the line items. Please let me know how the ACCOUNTTAX

and CURRENCYAMOUNT table parameters needs to be populated.

A sample code would be of much use.

Currently if we have 3 line items in GL to be posted we fill 3 line items in AccountGL table, one line item in Accounts payable table, 4 line items in the currency table ( 3 for the actual items and 4 th item with summed up quantity of all 3 items) .

Your help is greatly appreciated.

Regards,

Prabaharan.G

1 ACCEPTED SOLUTION
Read only

mnicolai_77
Active Participant
0 Likes
3,580

hi,

i use this function in some program i try to give to u how to set the minimum value in the structure/tables of the bapi.

> DOCUMENTHEADER

> BUS_ACT = 'RFBU' "for FI document

> USERNAME = sy-uname

> HEADER_TXT = your text

> COMP_CODE = Company code

> DOC_DATE = Document date

> PSTNG_DATE = Posting date

> FISC_YEAR(1) = The year of posting date

> FIS_PERIOD(1) = the period of posting date

> DOC_TYPE = document type

if you set a different year or period from the value that you have in the posting date the bapi trigger an error

> ACCOUNT GL

> ITEMNO_ACC = progessive number

> GL_ACCOUNT = G/L Account

> ITEM_TEXT = item text

> DOC_TYPE = document type (the same of the header for all item)

> COMP_CODE = company code (the same of the header for all item)

> BUS_AREA = business area

> TAX_CODE = tax code

if you set a different doc_type or company code for each item the bapi trigger an error

> ACCOUNTTAX

> ITEMNO_ACC = progressive number

> GL_ACCOUNT = G/L Account referred to TAX CODE

> TAX_CODE = TAX CODE

> TAX_RATE = TAX RATE

> ITEMNO_TAX = progressive number which tax item is referred

>CURRENCYAMOUNT

> ITEMNO_ACC = progressive number

> CURRENCY = currency

> CURRENCY_ISO = iso currency that you find in TCURC-ISOCD table

> AMT_DOCCUR = amount with sign the sign +/- identify Debit/Credit Indicator

> - this field only for tax record

> AMT_BASE = is the AMT_DOCCUR of the line which ypu want to calculate the tax with sign

> TAX_AMT = tax amount

usually for calculate the correct value i use these functions 'CALCULATE_TAX_FROM_GROSSAMOUNT' or 'CALCULATE_TAX_FROM_NET_AMOUNT' it depends if i have the net or gross amount.

for example:

DOCUMENTHEADER

> BUS_ACT = 'RFBU'

> USERNAME = sy-uname

> HEADER_TXT = 'my_text'

> COMP_CODE = '0001'

> DOC_DATE = '20080115'

> PSTNG_DATE = '20080115'

> FISC_YEAR(1) = '2008'

> FIS_PERIOD(1) = '01'

> DOC_TYPE = 'SA'

ACCOUNT GL

>Record 1

>ITEMNO_ACC = 0000000001

>GL_ACCOUNT = 0290111010

>ITEM_TEXT = ITEM_TEXT

>DOC_TYPE = SA

>COMP_CODE = 0001

>BUS_AREA = GS1

>Record 2

>ITEMNO_ACC = 0000000002

>GL_ACCOUNT = 0500103900

>ITEM_TEXT = ITEM_TEXT

>DOC_TYPE = SA

>COMP_CODE = 0001

>TAX_CODE = V2

ACCOUNTTAX

> Record 3

>ITEMNO_ACC = 0000000003

>GL_ACCOUNT = 0221103001

>TAX_CODE = V2

>TAX_RATE = 20.000

>ITEMNO_TAX = 0000000002

CURRENCYAMOUNT

>Record 1

>ITEMNO_ACC = 0000000001

>CURRENCY = EUR

>CURRENCY_ISO = EUR

>AMT_DOCCUR = 150.00

>AMT_BASE = 0.00

>TAX_AMT = 0.00

>Record 2

>ITEMNO_ACC = 0000000002

>CURRENCY = EUR

>CURRENCY_ISO = EUR

>AMT_DOCCUR = -125.00

>AMT_BASE = 0.00

>TAX_AMT = 0.00

>Record 3

>ITEMNO_ACC = 0000000003

>CURRENCY = EUR

>CURRENCY_ISO = EUR

>AMT_DOCCUR = -25.00

>AMT_BASE = -125.00

>TAX_AMT = -25.00

hope that is useful.

Bye

Marco

7 REPLIES 7
Read only

mnicolai_77
Active Participant
0 Likes
3,581

hi,

i use this function in some program i try to give to u how to set the minimum value in the structure/tables of the bapi.

> DOCUMENTHEADER

> BUS_ACT = 'RFBU' "for FI document

> USERNAME = sy-uname

> HEADER_TXT = your text

> COMP_CODE = Company code

> DOC_DATE = Document date

> PSTNG_DATE = Posting date

> FISC_YEAR(1) = The year of posting date

> FIS_PERIOD(1) = the period of posting date

> DOC_TYPE = document type

if you set a different year or period from the value that you have in the posting date the bapi trigger an error

> ACCOUNT GL

> ITEMNO_ACC = progessive number

> GL_ACCOUNT = G/L Account

> ITEM_TEXT = item text

> DOC_TYPE = document type (the same of the header for all item)

> COMP_CODE = company code (the same of the header for all item)

> BUS_AREA = business area

> TAX_CODE = tax code

if you set a different doc_type or company code for each item the bapi trigger an error

> ACCOUNTTAX

> ITEMNO_ACC = progressive number

> GL_ACCOUNT = G/L Account referred to TAX CODE

> TAX_CODE = TAX CODE

> TAX_RATE = TAX RATE

> ITEMNO_TAX = progressive number which tax item is referred

>CURRENCYAMOUNT

> ITEMNO_ACC = progressive number

> CURRENCY = currency

> CURRENCY_ISO = iso currency that you find in TCURC-ISOCD table

> AMT_DOCCUR = amount with sign the sign +/- identify Debit/Credit Indicator

> - this field only for tax record

> AMT_BASE = is the AMT_DOCCUR of the line which ypu want to calculate the tax with sign

> TAX_AMT = tax amount

usually for calculate the correct value i use these functions 'CALCULATE_TAX_FROM_GROSSAMOUNT' or 'CALCULATE_TAX_FROM_NET_AMOUNT' it depends if i have the net or gross amount.

for example:

DOCUMENTHEADER

> BUS_ACT = 'RFBU'

> USERNAME = sy-uname

> HEADER_TXT = 'my_text'

> COMP_CODE = '0001'

> DOC_DATE = '20080115'

> PSTNG_DATE = '20080115'

> FISC_YEAR(1) = '2008'

> FIS_PERIOD(1) = '01'

> DOC_TYPE = 'SA'

ACCOUNT GL

>Record 1

>ITEMNO_ACC = 0000000001

>GL_ACCOUNT = 0290111010

>ITEM_TEXT = ITEM_TEXT

>DOC_TYPE = SA

>COMP_CODE = 0001

>BUS_AREA = GS1

>Record 2

>ITEMNO_ACC = 0000000002

>GL_ACCOUNT = 0500103900

>ITEM_TEXT = ITEM_TEXT

>DOC_TYPE = SA

>COMP_CODE = 0001

>TAX_CODE = V2

ACCOUNTTAX

> Record 3

>ITEMNO_ACC = 0000000003

>GL_ACCOUNT = 0221103001

>TAX_CODE = V2

>TAX_RATE = 20.000

>ITEMNO_TAX = 0000000002

CURRENCYAMOUNT

>Record 1

>ITEMNO_ACC = 0000000001

>CURRENCY = EUR

>CURRENCY_ISO = EUR

>AMT_DOCCUR = 150.00

>AMT_BASE = 0.00

>TAX_AMT = 0.00

>Record 2

>ITEMNO_ACC = 0000000002

>CURRENCY = EUR

>CURRENCY_ISO = EUR

>AMT_DOCCUR = -125.00

>AMT_BASE = 0.00

>TAX_AMT = 0.00

>Record 3

>ITEMNO_ACC = 0000000003

>CURRENCY = EUR

>CURRENCY_ISO = EUR

>AMT_DOCCUR = -25.00

>AMT_BASE = -125.00

>TAX_AMT = -25.00

hope that is useful.

Bye

Marco

Read only

0 Likes
3,580

Hi ,

we also facing the problem in checking the calculate tax check box .tried out with sample code given, by passing table accounttax.getting message documnet posted with key.but 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
3,580

Thanks for your reply.

i have tried in the following way.no error .gives me the documnet no.but no record in table.can u help me out in this and

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

Former Member
0 Likes
3,580

Here is an example code on how to use this puppy:


DATA: it_acc_gl LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
it_acc_ap LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,
it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
it_curr_amt LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
it_doc_header LIKE bapiache09 OCCURS 0 WITH HEADER LINE,
it_acc_tax LIKE bapiactx09 OCCURS 0 WITH HEADER LINE,
obj_type LIKE bapiache09-obj_type,
obj_key LIKE bapiache09-obj_key,
obj_sys LIKE bapiache09-obj_sys,
pstng_date LIKE it_doc_header-pstng_date,
doc_date LIKE it_doc_header-doc_date,
loop_cnt TYPE i VALUE 0,
gv_vendor(10) TYPE c,
gv_gl_acc(10) TYPE c.

LOOP AT bdc_source.
* First line of table is heading so don't do anything
IF bdc_layout IS INITIAL.
MOVE bdc_source TO bdc_layout.
TRANSLATE bdc_layout TO UPPER CASE.
CONTINUE.
ENDIF.
bdc_out = bdc_source.
CLEAR: obj_type, obj_sys, obj_key, pstng_date, doc_date, gv_vendor, gv_gl_acc.
* Setup the dates in correct format
CONCATENATE bdc_source-col_c+6(4) bdc_source-col_c(2) bdc_source-col_c+3(2) INTO pstng_date.
CONCATENATE bdc_source-col_b+6(4) bdc_source-col_b(2) bdc_source-col_b+3(2) INTO doc_date.
* Padding zeros, very important otherwise bunch of stuff is missing
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = bdc_source-col_e
IMPORTING
output = gv_vendor.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = bdc_source-col_j
IMPORTING
output = gv_gl_acc.
* Header
REFRESH it_doc_header.
it_doc_header-bus_act = 'RFBU'.
it_doc_header-username = sy-uname.
it_doc_header-header_txt = bdc_source-col_h. " Invoice Text
it_doc_header-comp_code = bdc_source-col_a. " Company Code
it_doc_header-doc_date = doc_date. " Invoice Date
it_doc_header-pstng_date = pstng_date. " Posting Date
it_doc_header-doc_type = 'KR'. " Return Order...?
it_doc_header-ref_doc_no = bdc_source-col_d. " Invoice Number
APPEND it_doc_header.
* GL Account
REFRESH it_acc_gl.
it_acc_gl-itemno_acc = '1'.
it_acc_gl-gl_account = gv_gl_acc. " GL Account
it_acc_gl-item_text = bdc_source-col_o. " Line Item Text
it_acc_gl-doc_type = 'KR'. " Return Order...?
it_acc_gl-comp_code = bdc_source-col_a. " Company Code
it_acc_gl-pstng_date = pstng_date. " Posting Date
it_acc_gl-vendor_no = gv_vendor. " Vendor Number
it_acc_gl-costcenter = bdc_source-col_k. " Cost Center
it_acc_gl-wbs_element = bdc_source-col_q. " WBS Element
"it_acc_gl-tax_code = bdc_source-col_m. " Tax Code
it_acc_gl-network = bdc_source-col_p. " Internal Order
conv_s_amt = bdc_source-col_f. " Invoice Amount
REPLACE ALL OCCURRENCES OF ',' IN conv_s_amt WITH ''.
IF conv_s_amt < 0.
it_acc_gl-de_cre_ind = 'H'. " H-Credit
conv_s_amt = - conv_s_amt.
ELSE.
it_acc_gl-de_cre_ind = 'S'. " S-Debit
ENDIF.
CONDENSE conv_s_amt.
APPEND it_acc_gl.
* AP Account
REFRESH it_acc_ap.
it_acc_ap-itemno_acc = '2'. " Invoice Number
it_acc_ap-vendor_no = gv_vendor. " Vendor Number
it_acc_ap-comp_code = bdc_source-col_a. " Company Code
it_acc_ap-item_text = bdc_source-col_o. " Line Item Text
APPEND it_acc_ap.
* Currancy
REFRESH it_curr_amt.
it_curr_amt-itemno_acc = '1'. " Invoice Number
it_curr_amt-curr_type = '00'.
it_curr_amt-currency = bdc_source-col_g. " Currancy
it_curr_amt-amt_doccur = conv_s_amt. " Line Item Amount
APPEND it_curr_amt.
it_curr_amt-itemno_acc = '2'. " Invoice Number
it_curr_amt-curr_type = '00'.
it_curr_amt-currency = bdc_source-col_g. " Currancy
it_curr_amt-amt_doccur = conv_s_amt * -1. " Line Item Amount
APPEND it_curr_amt.
REFRESH it_return.
* Do the post to GL Account and AP
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = it_doc_header
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
accountgl = it_acc_gl
currencyamount = it_curr_amt
accountpayable = it_acc_ap
return = it_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
* Check for any errors
loop_cnt = 0.
LOOP AT it_return.
IF it_return-type = 'E'.
bdc_out-code = 'E'.
error_count = error_count + 1.
ELSE.
bdc_out-code = 'S'.
ENDIF.
loop_cnt = loop_cnt + 1.
IF loop_cnt = 1.
bdc_out-mesg1 = it_return-message.
ELSE.
IF loop_cnt = 2.
bdc_out-mesg2 = it_return-message.
ENDIF.
ENDIF.
ENDLOOP.
APPEND bdc_out.
cur_line = cur_line + 1.
ENDLOOP.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Mar 5, 2008 10:22 AM

Read only

Former Member
0 Likes
3,580

Hi Nicolai,

Your post helped a lot, but I am using CALCULATE_TAX_FROM_GROSSAMOUNT to calculate the tax line items for individual GL items, I am passing tax code, company code, tax jurisdiction code, currency key and gross amount into the function module but the table parameter returned does not return values for document currency and tax amount, only the base amount value is returned. Can you let me know how the tax calculation is done using the above function module.

Regards,

Prabaharan.G

Read only

Former Member
0 Likes
3,580

Hi,

We used the BDC recording to perform this, since we did not have a defenite solution for this. Kindly update if you are able to post tax items too. Sorry I could'nt help you.

Regards,

Prabaharan.G

Read only

0 Likes
3,580

Hi,

Replying to old post, just in case someone ends up here to find solution to post tax lines.

The BAPI dont add the calculated tax lines to the document lines, there is an enhancement exit which can be enhanced to place the code from the standard tax routine to add the computed tax lines by the system, you can refer to my document.

https://scn.sap.com/docs/DOC-43262

Hemendra