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: 

How to calculate withholding tax in FB60 uploading using bapi?

Former Member
0 Kudos

Hi Experts,

Im very new to the world of SAP and ABAP Programming. Just joined a job and have a very tough task given on the very first day.

There is a Uploading done for transaction FB60 using BAPI .

Bapi used is BAPI_ACC_DOCUMENT_POST and     BAPI_TRANSACTION_COMMIT .

Its working perfectly fine but now they have asked me to make changes in it so that the withholding tax is also calculated and deducted.

Im providing the current program please guide me how and what changes i hv to make?

Sinse im very new to ABAP itself and the task given to me is very tough so please i would would warm welcome all support and help i get.

Regards,

Harish Khandelwal

15 REPLIES 15

former_member184569
Active Contributor
0 Kudos

Hi Harish,

Try like this

Step 1. :

Pass the withholding tax information to the BAPI,

The withholding tax information can be retreived from table T059Z. Get the withholding tax code from table lfbw.


LOOP AT IT_DATA INTO WA_DATA.

SELECT * FROM lfbw

            INTO TABLE it_lfbw

            WHERE lifnr EQ wa_data-lifnr.

LOOP AT it_lfbw INTO wa_lfbw.

SELECT SINGLE * FROM t059z WHERE land1 = text-004

                             AND witht = wa_lfbw-wt_witht

                              and withcd= wa_lfbw-wt_withcd.

____________________________________________________________________

Option 1 - Use the table parameter EXTENSION1 to pass the details.

  wt_item_th = wt_item_th + 1.

  wa_extension-field1 = 'WHT'.                         "Identifier

  wa_extension-field2+0(6) = wt_item_th .        "ACCWT-WT_KEY

  wa_extension-field2+6(2) = t059z-witht.        "ACCWT-WITHT

  wa_extension-field2+8(2) = t059z-wt_withcd.    "ACCWT-WT_WITHCD

  wa_extension-field3 = wa_data-witht.          "Withholding tax base amount from input file.

  APPEND wa_extension TO it_extension.

ENDLOOP.

____________________________________________________________________

Option 2 : Another option is, you could try direcly filling the wt_key, witht, wt_withcd in the

ACCOUNTWT table in the BAPI. If this works there is no need to implement step 3.

wt_item_th = wt_item_th + 1.

wa_ACCOUNTWT-ITEMNO_ACC = wt_item_th .        "ACCWT-WT_KEY

wa_ACCOUNTWT-WT_TYPE  = t059z-witht.        "ACCWT-WITHT

wa_ACCOUNTWT-WT_CODE = t059z-wt_withcd.    "ACCWT-WT_WITHCD

wa_ACCOUNTWT-BAS_AMT_LC = wa_data-witht.  "Withholding tax base amount from input file.

append wa_ACCOUNTWT to IT_ACCOUNTWT.

______________________________________________________________________________

Step 2


This WHT information is passed in the BAPI.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

    EXPORTING

      DOCUMENTHEADER = DOCHEADER

    IMPORTING

      OBJ_TYPE       = OBJ_TYPE

      OBJ_KEY        = OBJ_KEY

      OBJ_SYS        = OBJ_SYS

    TABLES

      ACCOUNTGL      = ACCOUNTGL

      ACCOUNTPAYABLE = ACCOUNTPAY

      ACCOUNTTAX     = ACCOUNTTAX

      CURRENCYAMOUNT = CURRAMOUNT    

      ACCOUNTWT      = IT_ACCOUNTWT                      " For Withholding Tax (Option 2)

      EXTENSION1     = IT_EXTENSION                      " Withholding tax details (option 1)

      RETURN         = RETURN1.

Step 3 (Only for option 1)

Inside the user exit, populate table t_accwt. Use the Business transaction event BTE to implement this.

LOOP AT extension WHERE field1 EQ 'WHT'.

  MOVE extension-field2+0(6) TO t_accwt-wt_key.

  MOVE extension-field2+6(2) TO t_accwt-witht.

  MOVE extension-field2+8(2) TO t_accwt-wt_withcd.

  MOVE extension-field3 TO t_accwt-wt_qsshb.

*  MOVE extension-field3 TO t_accwt-wt_qbuihb.

  APPEND t_accwt.

ENDLOOP.

Check this document toimplement this BTE.

http://wiki.scn.sap.com/wiki/display/ABAP/Business+Transaction+Event+-+RWBAPI01+-+For+Accounting+Doc...

You could also see these related threads.

http://scn.sap.com/thread/1565269

https://scn.sap.com/message/4607117

https://scn.sap.com/thread/1900727

0 Kudos

Hi Susmitha mam,

First of all thanks a million for replying and providing me the above solutuion.

I have made changes to my code as per you have suggested me. I have chossen option 2(i.e filling ACCOUNTWT table)

Following are the changes done by me:-

**************************************************************************************************************

    REFRESH IT_LFBW.

    SELECT * FROM LFBW

            INTO TABLE IT_LFBW

            WHERE LIFNR EQ WA_DATA-LIFNR

            AND BUKRS EQ WA_DATA-BUKRS.

     IF SY-SUBRC = 0.

        LOOP AT IT_LFBW INTO WA_LFBW.



            SELECT SINGLE * FROM T059Z INTO WA_T059Z

              WHERE LAND1 = 'IN'

              AND WITHT = WA_LFBW-WITHT

              AND WT_WITHCD = WA_LFBW-WT_WITHCD.



          ITEMNO = ITEMNO + 1.

          GS_ACCOUNTWT-ITEMNO_ACC = ITEMNO.        "ACCWT-WT_KEY

          GS_ACCOUNTWT-WT_TYPE  = WA_T059Z-WITHT.          "ACCWT-WITHT

          GS_ACCOUNTWT-WT_CODE = WA_T059Z-WT_WITHCD.    "ACCWT-WT_WITHCD

          GS_ACCOUNTWT-BAS_AMT_LC = WA_DATA-WRBTR.      "Withholding tax base amount from input file.

          APPEND GS_ACCOUNTWT TO GT_ACCOUNTWT.

          ENDLOOP.

      ENDIF.

    ENDLOOP.

**************************************************************************************************************

Susmitha mam still its not calculating Witholding tax. I used the Document number generated after upload in checked it in FB03 but tax information is not calculated and updated.

Also mam i have a confussion about

GS_ACCOUNTWT-BAS_AMT_LC = WA_DATA-WRBTR.      "Withholding tax base amount from input file.

I have passed the base amount from excel file which we upload.

For futher reffrence im providing the Dummy excel file which is given to me for Upoading/Testing.

Thanking in Advance,

Regards,

Harish K.

0 Kudos

Hi Harish,

Can you try the first option? I have seen the second option fail many times. But first option seems to be the more reliable one.

Also yes, you pass the base amount in the excel file.

Actually whether its the net amount or gross amount depends on your configuration settings. Whatever is the taxable amount, that should be given here.

0 Kudos

Hi Susmitha mam,

     I tried to make more changes to Accountwt table and its related query and was anyhow tring to avoid BTE but its not working. So now i have to go with BTE option will implement it today and let you know if its working.If any problem arises i'll ask for ur help again.

Thanks and Regards,

Harish K.

0 Kudos

Hello Susmitha mam,

Now im trying by BTE and refering the link whic you provided.

http://wiki.scn.sap.com/wiki/display/ABAP/Business+Transaction+Event+-+RWBAPI01+-+For+Accounting+Doc...

but inside the link Scenario is for "Customer related" and my requirment is "Vendor related".

Mam jut wanted to know is it the same procedure and same BTE used for vendor data uploading also?

All Abap guru's please reply if you have any information related to my problem.

Thanks and Regards,

Harish K.

0 Kudos

Hi Harish,

That is not a problem.

This is just to access inside BAPI_ACC_DOCUMENT_POST .

The link is just to help you create the BTE.

Before calling the BAPI, you need to fill the extension table in the BAPI with the coding like the one I had given above

  wt_item_th = wt_item_th + 1.

  wa_extension-field1 = 'WHT'.                         "Identifier

  wa_extension-field2+0(6) = wt_item_th .        "ACCWT-WT_KEY

  wa_extension-field2+6(2) = t059z-witht.        "ACCWT-WITHT

  wa_extension-field2+8(2) = t059z-wt_withcd.    "ACCWT-WT_WITHCD

  wa_extension-field3 = wa_data-witht.          "Withholding tax base amount from input file.

  APPEND wa_extension TO it_extension.

Then once, you create the BTE, using the steps provided in the document,

ie.

Step 1: Create a New function group using transaction code SE80
Step 2: Copy the standard function module of BTE "SAMPLE_INTERFACE_RWBAPI01" to a Z Function module, say "ZSAMPLE_INTERFACE_RWBAPI01"
Step 3: Add Following Code into the new function module and activate

  FUNCTION zsample_interface_rwbapi01.

*"--------------------------------------------------------------------

""Local Interface:

*"  TABLES

*"      IT_ACCIT STRUCTURE  ACCIT

*"      IT_ACCCR STRUCTURE  ACCCR

*"      RETURN STRUCTURE  BAPIRET2

*"      EXTENSION STRUCTURE  BAPIACEXTC

*"      IT_ACCWT STRUCTURE  ACCIT_WT

*"  CHANGING

*"     VALUE(DOCUMENT_HEADER) LIKE  ACCHD STRUCTURE  ACCHD

*"--------------------------------------------------------------------

*The coding you put here would be different, according to our requirement.


LOOP AT extension WHERE field1 EQ 'WHT'.

  MOVE extension-field2+0(6) TO t_accwt-wt_key.

  MOVE extension-field2+6(2) TO t_accwt-witht.

  MOVE extension-field2+8(2) TO t_accwt-wt_withcd.

  MOVE extension-field3 TO t_accwt-wt_qsshb.

*  MOVE extension-field3 TO t_accwt-wt_qbuihb.

  APPEND t_accwt.

ENDLOOP.


ENDFUNCTION.

Steps 4 - Follow the steps in configuration.. Not much of change in that.

Finally save.. and test..

Hope it would work fine.

0 Kudos

Dear Susmitha mam,

  •      I created the BTE.
  •      As per your guildlines i made changes in  FUNCTION zsample_interface_rwbapi01.
  •      And finally passed the EXTENSION1 table to BAPI .

  

   But still im not able to get success. Now please suggest me what should i do?

   Should i go for BDC implementation?

   if yes then please walk me through the steps for BDC.

Thanks,

Harish K.

0 Kudos

DId you do the configuration steps of BTE in FIBF of linking the BTE with the function module?

On debugging, did you get the values in the BTE?

0 Kudos

Yes Mam i configured the BTE properly and it being called and the values passed to it as being refelected there. Im attaching thr screen shot you can have a look at it.

For this particular vemdor its W/Tax code is 00 and W/tax type is also 00.

also im attaching the scrren shot from the FB03 (display document) when i select the line item and see the "Withholding tax data" i get all tax fields blank.

Im working on this issue from quite a while need to solve it asap now.

Please help.

thanks and regards,

harish.K

0 Kudos

Please check if the with-holding tax settings are configured in your system.

Check the table T059Z.

0 Kudos

Yes mam it is configured in T059Z table.

0 Kudos

Hi Harish,

In the above example, QSATZ is the withholding tax rate.

For the w/h tax code and w/h tax type, QSATZ = 0.

So what is calculated is correct, the Withholding tax = 0.

Try for some other code, where qsatz is not 0 to test further.

Also check if the table WITH_ITEM is updated on posting.

0 Kudos

Hi Susmitha mam,

     Sorry for the late reply i was working on some other task. Now im back on this withholding tax issue.

By far i have tried by Accountwt structure no success and information is not getting updated also in document.

then i tried with extension1 and used btw by this method withholding information was getting passed and reflected in document but the tax was getting calculated 0.

So you suggested me to check the tax code and its tax rate and as you said it was zero so tax was getting calculated zero.

so i changed the tax code for the vendor. Any tax code which didnt had QSATZ = 0.

still the tax is being recorded zero.

so some one suggested me to use Function module FI_WITHHOLDING_TAX_CALCULATION to calculate tax in my program and than pass the calculated amount manually using Accountwt structure.thus using Accountwt again but Now tax is being calculated using this FM (inside my program)but its not being reflected in document(FB03)

     Susmitha mam pls guide me futher now what should i do.???

Former Member
0 Kudos

Hi Susmitha mam,

     Sorry for the late reply i was working on some other task. Now im back on this withholding tax issue.

By far i have tried by Accountwt structure no success and information is not getting updated also in document.

then i tried with extension1 and used btw by this method withholding information was getting passed and reflected in document but the tax was getting calculated 0.

So you suggested me to check the tax code and its tax rate and as you said it was zero so tax was getting calculated zero.

so i changed the tax code for the vendor. Any tax code which didnt had QSATZ = 0.

still the tax is being recorded zero.

so some one suggested me to use Function module FI_WITHHOLDING_TAX_CALCULATION to calculate tax in my program and than pass the calculated amount manually using Accountwt structure.thus using Accountwt again but Now tax is being calculated using this FM (inside my program)but its not being reflected in document(FB03)

     Susmitha mam pls guide me futher now what should i do.???

gradicopoulos
Participant
0 Kudos

Dear Harish,

Do you find a solution in this particular problem.

I am trying to find a solution through bapi, badi , user exit to influence the withholding tax.

Thanks

George Radicopoulos