‎2012 May 04 7:31 PM
Hello Experts,
I am using bapi 'BAPI_ACC_DOCUMENT_POST' to post document for FB60.
Almost all works fine, except two fields get passed by FB60, but are not set when using the BAPI:
1. bseg-txbhw -> Original Tax Base Amount in Local Currency
2. bseg-txbfw -> Original Tax Base Amount in Document Currency
These fields exist in BSEG, but not in any of the BAPI parameters or table structures.
I thought about using BADI ACC_DOCUMENT for its EXTENSION2 parameter, but I'm concerned because ACCIT table doesn't contain those two fields.
So my questions are around how to work with the BADI in order to push those two values when the invoice is posted. I've been working with this BADI all week. It's my first one, so I think I need some help.
1) BAPI_ACC_DOCUMENT_POST, when traced, shows a 'call badi' routine with 'ACC_DOCUMENT' as it's value. So am I correct in assuming that I shouldn't try to create 'ZACC_DOCUMENT'?
2). When I debug BAPI_ACC_DOCUMENT_POST I see that it calls Enhancement Spot BADI_ACC_DOCUMENT, and subsequently CL_EX_ACC_DOCUMENT.
a.) how do I get it to call ZBADI_ACC_DOCUMENT or ZCL_EX_ACC_DOCUMENT? Do I even need to create ZBADI_ACC_DOCUMENT, or can I simply add ZCL_EX_ACC_DOCUMENT as a new implementation?
3). Do I need to append ACCIT, or can I create a ZACCIT with the two field definitions?
4.) Will I need to append the fields to BAPIACGL09?
Thanks so much in advance,
Mike
‎2012 May 08 8:26 AM
Hi Mike,
If the field is missing in the interfase, please see note 487722 (using EXTENSION1 for accounting BAPI's). Although you are talking about fields related with taxes for BAPI in accounting. Please see notes 367175, 1431727 and 556311.
I hope this helps you
Regards
Eduardo
‎2012 May 05 8:13 AM
Check the following sample code and after that check your parameter declaration details:
DATA:
obj_type LIKE bapiache02-obj_type,
obj_key LIKE bapiache02-obj_key,
obj_sys LIKE bapiache02-obj_sys,
documentheader LIKE bapiache09,
return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
accountgl LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
currencyamount LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
extension1 LIKE bapiacextc OCCURS 0 WITH HEADER LINE,
t_edidd LIKE edidd OCCURS 0 WITH HEADER LINE,
bapi_retn_info LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: error_flag.
DATA: gs_wait TYPE bapita-wait,
wa_comm_return TYPE bapiret2.
DATA : zsched_line LIKE bapiacgl09-itemno_acc.
break developer.
LOOP AT itab.
IF itab-shkzg = 'H'.
CONCATENATE itab-mblnr itab-mjahr INTO documentheader-header_txt.
documentheader-username = sy-uname.
documentheader-comp_code = '1000'.
documentheader-doc_date = itab-bldat.
documentheader-pstng_date = itab-budat.
documentheader-doc_type = 'SA'.
documentheader-ref_doc_no = itab-xblnr.
***line item 1
accountgl-itemno_acc = '2'.
accountgl-gl_account = 'YOUR GL NO'.
accountgl-comp_code = '1000'.
accountgl-pstng_date = itab-budat.
accountgl-doc_type = 'SA'.
accountgl-profit_ctr = itab-prctr.
accountgl-alloc_nmbr = itab-zuonr.
accountgl-po_number = itab-ebeln.
accountgl-po_item = itab-ebelp.
APPEND accountgl.
currencyamount-itemno_acc = '2'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = itab-grval.
APPEND currencyamount.
***line itme 2
accountgl-itemno_acc = '1'.
accountgl-gl_account = 'YOUR GL NO'.
accountgl-comp_code = '1000'.
accountgl-pstng_date = itab-budat.
accountgl-doc_type = 'SA'.
accountgl-profit_ctr = itab-prctr.
accountgl-alloc_nmbr = itab-zuonr.
* accountgl-po_number = itab-ebeln.
accountgl-po_item = itab-ebelp.
* accountgL-DE_CRE_IND = 'H'.
APPEND accountgl.
currencyamount-itemno_acc = '1'.
currencyamount-currency = 'USD'.
itab-grval = itab-grval * -1.
currencyamount-amt_doccur = itab-grval.
APPEND currencyamount.
ELSE.
documentheader-username = sy-uname.
CONCATENATE itab-mblnr itab-mjahr INTO documentheader-header_txt.
documentheader-comp_code = '1000'.
documentheader-doc_date = itab-bldat.
documentheader-pstng_date = itab-budat.
documentheader-doc_type = 'SA'.
documentheader-ref_doc_no = itab-xblnr.
* documentheader-BUS_ACT = 'F-02'.
***line item 1
accountgl-itemno_acc = '1'.
accountgl-gl_account = 'YOUR GL NO'.
*--.
accountgl-comp_code = '1000'.
accountgl-pstng_date = itab-budat.
accountgl-doc_type = 'SA'.
accountgl-profit_ctr = itab-prctr.
accountgl-alloc_nmbr = itab-zuonr.
* accountgL-DE_CRE_IND = 'S'.
APPEND accountgl.
currencyamount-itemno_acc = '1'.
currencyamount-currency = 'USD'.
currencyamount-amt_doccur = itab-grval.
APPEND currencyamount.
***line itme 2
accountgl-itemno_acc = '2'.
accountgl-gl_account = 'YOUR GL NO'.
accountgl-comp_code = '1000'.
accountgl-pstng_date = itab-budat.
accountgl-doc_type = 'SA'.
accountgl-profit_ctr = itab-prctr.
accountgl-alloc_nmbr = itab-zuonr.
accountgl-po_number = itab-ebeln.
accountgl-po_item = itab-ebelp.
* accountgL-DE_CRE_IND = 'H'.
APPEND accountgl.
currencyamount-itemno_acc = '2'.
currencyamount-currency = 'USD'.
itab-grval = itab-grval * -1.
currencyamount-amt_doccur = itab-grval.
APPEND currencyamount.
ENDIF.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = documentheader
TABLES
accountgl = accountgl
currencyamount = currencyamount
return = return
extension1 = extension1
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE e999(re) WITH 'Problem occured'.
ELSE.
.
LOOP AT return.
IF NOT return IS INITIAL.
CLEAR bapi_retn_info.
MOVE-CORRESPONDING return TO bapi_retn_info.
IF return-type = 'A' OR return-type = 'E'.
error_flag = 'X'.
ENDIF.
APPEND bapi_retn_info.
ENDIF.
ENDLOOP.
IF error_flag = 'X'.
MESSAGE e999(re) WITH 'Problem occured'.
ROLLBACK WORK.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = gs_wait
IMPORTING
return = wa_comm_return.
WRITE :/ return-message+0(30),return-message+36(10).
ENDIF.
ENDIF.
REFRESH: currencyamount,accountgl,return,extension1.
CLEAR: currencyamount,accountgl,documentheader,return,extension1.
ENDLOOP.
‎2012 May 06 3:42 AM
Krupa, thanks for the reply.
I see references to PO number and IDOC info. I should have been more clear - there is no PO or IDOC involved. We are creating a 'KR' doc type, not 'SA' This is an incoming invoice from a vendor with no PO involved. The BAPI is being called externally.
We are using ACCOUNTGL for debit to our business user, ACCOUNTSPAYABLE for credit to Vendor account, and ACCOUNTTAX for taxes derived from a call to CALCULATE_TAX_FROM_NET_AMOUNT.
Our current technique posts successfully, and the resultant BSEG information matches that which we get from FB60 *except for TXBHW and TXBFW" fields. We're simply trying to understand the use of EXTENSION2 table in BADI ACC_DOCUMENT in order to pass these field values.
‎2012 May 06 11:42 AM
Hi, have you tried with the parameter C_ACCTX of the method CHANGE? This parameter has two fields HWBAS & FWBAS. I think you should try with these fields.
Use the below logic as reference.
DATA: wa_extension TYPE bapiparex,
ext_value(960) TYPE c,
wa_accit TYPE accit,
l_ref TYPE REF TO data.
FIELD-SYMBOLS: <l_struc> TYPE ANY,
<l_field> TYPE ANY.
SORT c_extension2 BY structure.
LOOP AT c_extension2 INTO wa_extension.
AT NEW structure.
CREATE DATA l_ref TYPE (wa_extension-structure).
ASSIGN l_ref->* TO <l_struc>.
ENDAT.
CONCATENATE wa_extension-valuepart1 wa_extension-valuepart2
wa_extension-valuepart3 wa_extension-valuepart4
INTO ext_value.
MOVE ext_value TO <l_struc>.
ASSIGN COMPONENT 'POSNR' OF STRUCTURE <l_struc> TO <l_field>.
READ TABLE c_accit WITH KEY posnr = <l_field>
INTO wa_accit.
IF sy-subrc IS INITIAL.
IF wa_accit-blart EQ 'SA'.
MOVE-CORRESPONDING <l_struc> TO wa_accit.
MODIFY c_accit FROM wa_accit INDEX sy-tabix.
ENDIF.
ENDIF.
ENDLOOP.
Regards,
Vijaymadhur.
‎2012 May 06 10:49 PM
Thank you. That sounds very promising, Vijaymadhur.
Since I am new to this I have questions about how to invoke the modified CHANGE function: 1) do I assign those values using my own implementation, like ZCL_EX_ACC_DOCUMENT? 2) If so, how do I hook that in so that when my BAPI runs, that particular implementation is called?
Regards,
Mike
‎2012 May 07 7:23 AM
Hi Mike, please find answers below.
1) Yes, You should create your own implementation with your own class to assign those values.
2) As this BADI is filter dependent by AWTYP (Reference Transaction), You should provide the reference transaction, for ex: 'BKPF', while creating the implementation. The implementation will be triggered based on the AWTYP being passed to the BAPI.
Hope this helps.
Regards,
Vijaymadhur.
‎2012 May 07 7:11 PM
Thank you, vijaymadhur. Now I can see my implementation being called when debugging my program. I used 'BKPFF' for the trigger, by the way.
Now the last thing is to figure out how to transfer values for TXBHW and TXBFW to BSEG.
Ealier you mentioned HWBAS & FWBAS. While they are similar, they are the 'Tax Base Amount in Local Currency' and 'Tax Base Amount in Document Currency' fields.
TXBHW and TXBFW, on the other hand, are described as 'Original Tax Base Amount in Local Currency' and 'Original Tax Base Amount in Document Currency'.
You are correct that parameter C_ACCTX contains HWBAS and FWBAS, but I don't see TXBHW and TXBFW. For this reason I need a transfer mechanism and data structure(s).
‎2012 May 08 7:03 AM
Hi Mike, try to pass the values to HWBAS & FWBAS and check whether the fields TXBHW & TXBFW of BSEG are updated automatically or not.
‎2012 May 08 10:11 PM
Passing to those fields did not change the values in TXBHW or TXBFW.
‎2012 May 09 7:03 AM
Hi, Try implementing the BTE mentioned below.
00001030: 00001030 POST DOCUMENT: Posting of standard data
Check the below link for reference.
http://www.erpgenie.com/sap-technical/abap/business-transaction-events-bte
I think it should resolve your issue.
Regards,
Vijaymadhur.
‎2012 May 11 12:11 AM
Ok, it is working now.
I needed to append the TXBHW and TXBFW fields to ACCIT using a technique described in SAP NetWeaver documentation here: http://bit.ly/KqGnJC
Once I appended the field definitions to ACCIT, I modified my BAdi implementation class to pass them along. Now, whenever I post using BAPI_ACC_DOCUMENT_POST the TXBHW and TXBFW fields are updated.
‎2013 Jan 07 4:05 PM
Hi Mike,
Can you send me more detail of how did you append those fields to ACCIT?
I also need to update some fields of BSEC table that are not in this structure, and I'm not able to do it by this BTE.
Thanks in advance.
Best regards,
Sónia Gonçalves
‎2012 May 08 8:26 AM
Hi Mike,
If the field is missing in the interfase, please see note 487722 (using EXTENSION1 for accounting BAPI's). Although you are talking about fields related with taxes for BAPI in accounting. Please see notes 367175, 1431727 and 556311.
I hope this helps you
Regards
Eduardo
‎2013 Jan 08 10:27 PM
Whenever you work in FI-AC interface in SAP specifically BAPI_ACC_DOCUMENT_POST and need to transfer additional data you have to enhance BAPI via extensions. Once you fill those structures with desired data , you can read and update table BSEG or BSEGC based on your requirement.
You can check note 591892 ,487722 and below mentioned link for BTE.
Hope this solves your problem.