Application Development 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: 

I want to add witholding tax Code in BAPI_ACC_DOCUMENT_POST for tcode F-48

manish1702
Explorer
0 Kudos

I want to add Witholding tax code in BAPI_ACC_DOCUMENT_POST for standard tcode F-48.

Requirement : Witholding tax should be calculated on G/L Account Total Amount (Including tax) not on Vendor.

For example.

If total Amount is Rs 11,800 then witholding tax amount should be 11,800 * 2.00% = 236

then when we enter Document Number in FB03 Tcode

then Entry should look like

G/L Amount -11564

Vendor Base Amount 10000

Tax Amount1 9% 900

Tax Amount2 9% 900

Witholding Tax Amount -236

then how to write it in Program. Thank You in Advance

4 REPLIES 4

raymond_giuseppi
Active Contributor

Did you already read the reference how-to note (with samples) 2083799 - Composite SAP Note: Postings with Accounting BAPIs and check for required notes wih keywords such as "BAPI_ACC_DOCUMENT_POST" "Witholding"

0 Kudos

Thank You for your reply,

The answer given by you is correct if I am using Bapi for tcode FB60 or FB50.

But My query is for F-48,

In this TCODE G/L account is Credit

and Vendor Account is Debit.

Example

screen-1.png

The above picture shows the data created from standard tcode f-48 (Correct One)

and Data created from BAPI_ACC_DOCUMENT_POST in below image

screen-2.png

the TDS amount gets Calculated on Vendor Base Amount i.e Rs 200 * 2% = Rs 4

but the Rs 4 should get deduct from G/L account Total Amount i.e 236 - 4 = Rs 232 Should Come.

So how to write the logic for it.

Guide Us.

0 Kudos

You didn't define the vendor item as related to a vendor down payment (ACCOUNTPAYABLE-SP_GL_IND initial?)

0 Kudos

I defined Special G/L Indicator but still i am not able to get that result which i have shared that screen with you.

es_documentheader-obj_type = 'BKPFF'.
CONCATENATE sy-datum sy-uzeit INTO es_documentheader-obj_key .
es_documentheader-bus_act = 'RFBU'.
es_documentheader-username = sy-uname."User "Current User Name
es_documentheader-header_txt = 'Test'. "lt_data-bktxt. "Header text
es_documentheader-comp_code = '5000'. "lt_data-bukrs. "Company Code
es_documentheader-doc_date = sy-datum. "lt_data-bldat. "Document Date
es_documentheader-pstng_date = sy-datum. " lt_data-budat. "Posting Date
es_documentheader-doc_type = 'KZ'. "lt_data-blart. "Document Type'AA'.
es_documentheader-fisc_year = '2018'. "lt_data-gjahr. "Fiscal Year
es_documentheader-ref_doc_no = 'Test123'. "lt_data-xblnr. "Reference Document No.
es_documentheader-doc_status = '4'. "Checked and complete for Posting

lt_data-bukrs = '5000'.
lt_data-mwskz = '15' .
lt_data-waers = 'INR' .
lt_data-rewwr = 236.

**************************************************
CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
EXPORTING
i_bukrs = lt_data-bukrs
i_mwskz = lt_data-mwskz
i_waers = lt_data-waers
i_wrbtr = lt_data-rewwr
IMPORTING
e_fwnav = e_fwnav
e_fwnvv = e_fwnvv
e_fwste = e_fwste
e_fwast = e_fwast
TABLES
t_mwdat = t_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.
* Implement suitable error handling here
ELSE.
READ TABLE t_mwdat INTO wa_mwdat INDEX 1.
ENDIF.
**************************************************
*LOOP at t_mwdat INTO wa_mwdat.
count = count + 1.
*************Populate GL Account***************
CLEAR : is_accountgl.
lv_item_no = lv_item_no + 1.
is_accountgl-itemno_acc = lv_item_no.
is_accountgl-gl_account = '0002515701'. "lt_data-hkont. "G/L Account
is_accountgl-item_text = 'TEST1'. "lt_data-bktxt1. "Header text
is_accountgl-acct_type = 'S'.
is_accountgl-alloc_nmbr = '12345'. "lt_data-zuonr1. "Item Assignment Number
is_accountgl-comp_code = '5000'. "lt_data-bukrs. "Company Code
APPEND is_accountgl TO it_accountgl.

REFRESH : lt_lfbw[].

SELECT lifnr bukrs witht wt_withcd
FROM lfbw
INTO TABLE lt_lfbw
WHERE lifnr = 'MUM001' "wa_vendoritem-vendor_no
AND bukrs = '5000'. "wa_vendoritem-comp_code
* AND wt_subjct = 'X'.

IF lt_lfbw[] IS NOT INITIAL.
LOOP AT lt_lfbw INTO ls_lfbw.
wa_accountwt-itemno_acc = is_accountgl-itemno_acc.
wa_accountwt-wt_type = ls_lfbw-witht.
wa_accountwt-wt_code = ls_lfbw-wt_withcd.
APPEND wa_accountwt TO it_accountwt.
CLEAR : ls_lfbw.
ENDLOOP.
ENDIF.


CLEAR is_currencyamount.
is_currencyamount-itemno_acc = is_accountgl-itemno_acc. "lv_item_no.
is_currencyamount-curr_type = '00'.
is_currencyamount-currency = 'INR'. "lt_data-waers. "Currency Key
is_currencyamount-amt_doccur = '-236'."wa_mwdat-kawrt. "Amount in Local Currency
APPEND is_currencyamount TO it_currencyamount.
CLEAR is_currencyamount.
CLEAR is_accountgl.

*ENDLOOP.

*********Populate Tax Code Details



****Populate Vendor Data
lv_item_no = lv_item_no + 1.
wa_vendoritem-itemno_acc = lv_item_no.
wa_vendoritem-vendor_no = 'MUM001'. "lt_data-lifnr. "Vendor Code
wa_vendoritem-comp_code = '5000'. "lt_data-bukrs. "Company Code
wa_vendoritem-bline_date = sy-datum. "lt_data-zfbdt1. "Baseline Date
wa_vendoritem-item_text = 'TEST'. " lt_data-bktxt. "Header text
wa_vendoritem-businessplace = '5000'. "lt_data-bupla. "Business Place
wa_vendoritem-sectioncode = '5000'. "lt_data-secco. "Section Code
wa_vendoritem-tax_code = '15'. "lt_data-mwskz. "Tax Code
wa_vendoritem-sp_gl_ind = 'A'.
APPEND wa_vendoritem TO it_vendoritem.

CLEAR is_currencyamount.
is_currencyamount-itemno_acc = wa_vendoritem-itemno_acc.
is_currencyamount-curr_type = '00'.
is_currencyamount-currency = 'INR'. "lt_data-waers. "Currency Key
is_currencyamount-amt_doccur = '200'. "wa_mwdat-kawrt.
is_currencyamount-amt_base = '200'. "wa_mwdat-kawrt.
APPEND is_currencyamount TO it_currencyamount.




LOOP AT t_mwdat INTO wa_mwdat.
CLEAR : gv_hkont.
SELECT SINGLE konts FROM j_1it030k
INTO gv_hkont
WHERE ktopl = '9000'
AND ktosl = wa_mwdat-ktosl
AND mwskz = '15'
AND bupla = '5000'.

lv_item_no = lv_item_no + 1.
is_accounttax-itemno_acc = lv_item_no.
is_accounttax-gl_account = gv_hkont. "wa_mwdat-hkont. "G/L Account of Tax
is_accounttax-cond_key = wa_mwdat-kschl. "Condition Type 'JISG'.
is_accounttax-acct_key = wa_mwdat-ktosl. "Transaction Key 'JIS'.
is_accounttax-tax_code = '15'. "lv_tax_code. " Tax Code'15'.
is_accounttax-tax_rate = wa_mwdat-msatz. "Tax Rate'9'.
is_accounttax-itemno_tax = wa_vendoritem-itemno_acc. "count.
APPEND is_accounttax TO it_accounttax3.


is_currencyamount-itemno_acc = lv_item_no.
is_currencyamount-curr_type = '00'.
is_currencyamount-currency = 'INR'. "lt_data-waers."'EUR'
is_currencyamount-amt_doccur = wa_mwdat-wmwst.
is_currencyamount-amt_base = wa_mwdat-kawrt.
is_currencyamount-currency_iso = 'INR'. "lt_data-waers."'INR'.
APPEND is_currencyamount TO it_currencyamount.
CLEAR is_currencyamount.
ENDLOOP.


EXPORT it_accounttax3 TO MEMORY ID 'IT_ACCOUNTTAX2'. "Export to FM "FI_TAX_GET_TAX_ACCOUNTS"

*** Passing filled BAPI tables
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = es_documentheader
TABLES
accountgl = it_accountgl
accountpayable = it_vendoritem
accounttax = it_accounttax3
currencyamount = it_currencyamount
return = it_return
accountwt = it_accountwt.

FREE MEMORY ID 'IT_ACCOUNTTAX2'.
CLEAR: is_return.
READ TABLE it_return WITH KEY type = 'S' INTO is_return.
*** Commit Work******
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CLEAR is_return.
ELSE.

ENDIF.

Please Guide me where I am lacking in building appropriate logic