Hi All,
i am posting a document using BAPI_ACC_DOCUMENT_POST...
Please find the below code:
Populate BAPI item structures
----
FORM fill_bapi_item .
*Local data declarations
DATA : lv_taxded TYPE bset-fwste,
lv_taxtot TYPE bset-fwste,
lv_amt TYPE wrbtr,
lv_ref2 TYPE xref2,
ls_mwdat TYPE rtax1u15,
lt_mwdat TYPE TABLE OF rtax1u15.
Tax juris code for vendor
IF gs_item1-koart = gc_v. " vendor
gv_tjxcd = gs_item1-txjcd.
ENDIF.
gv_item = gv_item + 1.
Concatenate the legacy number, store and division and pass it
to field XREF2 of the BAPI
CLEAR lv_ref2.
CONCATENATE gs_item1-legacy gs_item1-divsn gs_item1-store
INTO lv_ref2.
Fill the GL account structure if the account type is G
otherwise fill the Vendor structure.
IF gs_item-koart = gc_g
OR gs_item-koart = space. " For offset clearing account
gs_accountgl-itemno_acc = gv_item.
gs_accountgl-gl_account = gs_item1-newko.
gs_accountgl-de_cre_ind = gs_item1-shkzg.
gs_accountgl-item_text = gs_item1-sgtxt.
gs_accountgl-comp_code = gs_item1-newbk .
gs_accountgl-tax_code = gs_item1-mwskz.
gs_accountgl-taxjurcode = gv_tjxcd.
gs_accountgl-alloc_nmbr = gs_item1-zuonr.
gs_accountgl-ref_key_1 = gs_item1-xref1.
gs_accountgl-ref_key_2 = lv_ref2. " legacy accountstoredivision
gs_accountgl-profit_ctr = gs_item1-prctr.
gs_accountgl-costcenter = gs_item1-kostl.
APPEND gs_accountgl TO gt_accountgl.
CLEAR gs_accountgl.
CLEAR : lv_taxded, lv_taxtot , lv_amt , ls_mwdat.
REFRESH : lt_mwdat.
Fetch the tax amount based on the gross amount, tax code and juris code
CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
EXPORTING
i_bukrs = gs_header1-bukrs
i_mwskz = gs_item1-mwskz
i_txjcd = gv_tjxcd
i_waers = gs_header1-waers
i_wrbtr = gs_item1-wrbtr
IMPORTING
e_fwste = lv_taxtot
e_fwast = lv_taxded
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 NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
Calculate the amounts.
lv_amt = gs_item-wrbtr - lv_taxded. " Tax deductable.
Get the GL Account, Condition,etc. for TAX amount
READ TABLE lt_mwdat INTO ls_mwdat INDEX 1.
IF sy-subrc EQ 0.
Do Nothing
ENDIF.
Fill the currency structures for GL Account
gs_curr-itemno_acc = gv_item.
gs_curr-amt_doccur = lv_amt. " Net amount after tax
gs_curr-currency = gs_header1-waers. " Currency is at header
APPEND gs_curr TO gt_curr.
CLEAR : gs_curr.
Fill the tax structure for GL Account.
gv_item = gv_item + 1.
gs_tax-itemno_acc = gv_item.
gs_tax-gl_account = ls_mwdat-hkont.
gs_tax-cond_key = ls_mwdat-kschl.
gs_tax-acct_key = ls_mwdat-ktosl.
gs_tax-tax_code = gs_item1-mwskz.
gs_tax-taxjurcode = ls_mwdat-txjcd.
gs_tax-taxjurcode_deep = ls_mwdat-txjcd_deep.
gs_tax-taxjurcode_level = ls_mwdat-txjlv.
APPEND gs_tax TO gt_tax.
CLEAR gt_tax.
Fill the TAX amount in the currency structure.
gs_curr-itemno_acc = gv_item.
gs_curr-amt_base = lv_taxded. " Tax
gs_curr-currency = gs_header1-waers. " Currency is at header
APPEND gs_curr TO gt_curr.
CLEAR : gs_curr.
ENDIF.
Vendor
ELSEIF gs_item-koart = gc_v.
gs_vendor-itemno_acc = gv_item.
gs_vendor-gl_account = gs_item1-newko.
gs_vendor-item_text = gs_item1-sgtxt.
gs_vendor-comp_code = gs_item1-newbk.
gs_vendor-tax_code = gs_item1-mwskz.
gs_vendor-taxjurcode = gv_tjxcd.
gs_vendor-alloc_nmbr = gs_item1-zuonr.
gs_vendor-ref_key_1 = gs_item1-xref1.
gs_vendor-ref_key_2 = lv_ref2. " legacy accountstoredivision
gs_vendor-profit_ctr = gs_item1-prctr.
APPEND gs_vendor TO gt_vendor.
CLEAR gs_vendor.
Fill the currency structures for vendor(No Tax calculation here)
gs_curr-itemno_acc = gv_item.
gs_curr-amt_doccur = gs_item1-wrbtr.
gs_curr-currency = gs_header1-waers. " Currency is at header
APPEND gs_curr TO gt_curr.
CLEAR : gs_curr.
ENDIF.
ENDFORM. " FILL_BAPI_ITEM
But if i post using FB01 and give the tax amount and gross amount, there are 6 items for tax getting created....(sum of 6 items = tax amoutn passed)...
But when i create using BAPI, one taxx item is created but with total tax amount...
How to achieve the same way as in FB01(6 items or so)..
Thanks
Shiva