Business Transaction Event - RWBAPI01 - For Accounting
Document Interface
Attachments:2
Added by Vinod Kumar, last edited by Keshav.T on Jul 11, 2012 (view change)
Business Transaction Event - RWBAPI01 - For Accounting Document Interface
Link to Content's target Space :
http://wiki.sdn.sap.com/wiki/display/ABAP/BTE+-+Business+Transaction+Event
Applies to:
SAP 4.7x and above.
Summary
While Creating the Accounting document through BAPI - BAPI_ACC_DOCUMENT_POST posting keys are
determined automatically based on the configuration. Since this BAPI doesn't have any structure field to pass the posting
key, posting keys are picked up automatically based on the document type passed in BAPI header structure.
This document narrates how to change the default posting key while creating the Accounting document using the above
BAPI. This document also explains the steps involved in implementing a Business Transaction Event.
Author(s): Vinod Kumar T
Company: NIIT Technologies Limited
Created on: 20.07.2010
Author(s) Bio
Vinod Kumar is an ABAP Consultant working with NIIT Technologies Limited.
Posting of Accounting Document Using BAPI - BAPI_ACC_Document Post
Scenario
Create the accounting document for Customer advance payment against Net-banking transaction. Document is to be
created with the accounting document type (DZ-Customer Payment). Based on the Configuration, Customer line item is
posted against the posting key 01(Invoice-Debit) and GL Account line item is posted against the posting key 50(GL-
Credit).
Since the FI documents of customer payment and Advance payment is to be separated, Customer line item of above
entries are to be posted with posting key 04 (Other Receivables - Debit) and GL Account line item to be posted with
posting key 50 (GL - Credit)
Additional Structure for BAPI
For passing the additional data related to posting keys, Structure EXTENSION1 is to be filled with the required data.
Business Transaction Event used for changing the Posting key will be executed only when the record(s) are available in
this structure. See the Call to BTE in line number 59 of BAPI.
Code for Creating Account document using BAPI
REPORT zacctesting.
** Internal table and Work area declarations
DATA : wa_documentheader TYPE bapiache09,
it_accountgl TYPE STANDARD TABLE OF bapiacgl09,
wa_accountgl TYPE bapiacgl09,
it_accountreceivable TYPE STANDARD TABLE OF bapiacar09,
wa_accountreceivable TYPE bapiacar09,
it_currencyamount TYPE STANDARD TABLE OF bapiaccr09,
wa_currencyamount TYPE bapiaccr09,
it_return TYPE STANDARD TABLE OF bapiret2,
wa_return TYPE bapiret2,
it_extension1 TYPE STANDARD TABLE OF bapiacextc,
wa_extension1 TYPE bapiacextc.
DATA : doc_amt_cr TYPE bapiwrbtr VALUE '-50.00',
doc_amt_dr TYPE bapiwrbtr VALUE '50.00'.
DATA: lv_type TYPE bapiache09-obj_type,
lv_key TYPE bapiache09-obj_key,
lv_sys TYPE bapiache09-obj_sys.
** clear internal table
REFRESH :it_accountgl,
it_accountreceivable,
it_currencyamount,
it_return,
it_extension1.
** Fill header data.
CLEAR : wa_documentheader.
MOVE sy-uname TO wa_documentheader-username. "Username"
MOVE 'Test' TO wa_documentheader-header_txt."Header Text"
MOVE '0103' TO wa_documentheader-comp_code. "Company Code"
MOVE sy-datum TO wa_documentheader-doc_date. "Doc Date"
MOVE sy-datum TO wa_documentheader-pstng_date."Posting Date"
MOVE 'DZ' TO wa_documentheader-doc_type. "Doc Type"
MOVE 'Test' TO wa_documentheader-ref_doc_no."Reference"
MOVE 'RFBU' TO wa_documentheader-bus_act.
MOVE 'BKPFF' TO wa_documentheader-obj_type. "Comment for >= ECC5.0
MOVE '$' TO wa_documentheader-obj_key. "Comment for >= ECC5.0
MOVE sy-mandt TO wa_documentheader-obj_sys. "Comment for >= ECC5.0
**Fill GL Account Line item.
CLEAR : wa_accountgl, wa_currencyamount.
MOVE '0000000001' TO wa_accountgl-itemno_acc. "Line Item No"
MOVE '0014000041' TO wa_accountgl-gl_account. "G/L Account"
MOVE 'ItemTest' TO wa_accountgl-item_text. "Item Text"
MOVE '0103' TO wa_accountgl-comp_code. "Company Code"
MOVE '0000900390' TO wa_accountgl-profit_ctr. "Profit Center"
MOVE 'Assign1' TO wa_accountgl-alloc_nmbr. "Assignment"
APPEND wa_accountgl TO it_accountgl.
MOVE '0000000001' TO wa_currencyamount-itemno_acc. "Line Item No"
MOVE '00' TO wa_currencyamount-curr_type. "Currency Type"
MOVE 'INR' TO wa_currencyamount-currency. "Currency"
MOVE doc_amt_cr TO wa_currencyamount-amt_doccur. "Amount"
APPEND wa_currencyamount TO it_currencyamount.
** Fill Customer Line item
CLEAR :wa_accountreceivable, wa_currencyamount.
MOVE '0000000002' TO wa_accountreceivable-itemno_acc. "Item No"
MOVE '0001000076' TO wa_accountreceivable-customer. "Customer"
MOVE 'ItemTest' TO wa_accountreceivable-item_text. "Item Text"
MOVE '0103' TO wa_accountreceivable-comp_code. "Company Code"
MOVE 'Assign2' TO wa_accountreceivable-alloc_nmbr. "Assignment.
APPEND wa_accountreceivable TO it_accountreceivable.
MOVE '0000000002' TO wa_currencyamount-itemno_acc. "Line Item No"
MOVE '00' TO wa_currencyamount-curr_type. "Currency Type"
MOVE 'INR' TO wa_currencyamount-currency. "Currency"
MOVE doc_amt_dr TO wa_currencyamount-amt_doccur. "Amount"
APPEND wa_currencyamount TO it_currencyamount.
**Fill Extension1 Structure used by BTE
**Posting key is to be changed for only for Customer line item (0000000002)
**Records in this internal table will be checked in BTE
CLEAR : wa_extension1.
MOVE '000000000204' TO wa_extension1-field1.
APPEND wa_extension1 TO it_extension1.
** Call Bapi
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = wa_documentheader
IMPORTING "Comment for >=ECC5.0
obj_type = lv_type "Comment for >=ECC5.0
obj_key = lv_key "Comment for >=ECC5.0
obj_sys = lv_sys "Comment for >=ECC5.0
TABLES
accountgl = it_accountgl
accountreceivable = it_accountreceivable
currencyamount = it_currencyamount
extension1 = it_extension1
return = it_return.
** Check for errors.
CLEAR : wa_return.
READ TABLE it_return INTO wa_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
** display the output
LOOP AT it_return INTO wa_return.
WRITE :/ wa_return-type,
wa_return-id,
wa_return-number,
wa_return-message.
ENDLOOP.
Implementing Business Transaction Event - RWBAPI01
Code for BTE Function Module
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
*"--------------------------------------------------------------------
DATA : wa_extension TYPE bapiacextc.
CLEAR: wa_extension.
LOOP AT extension INTO wa_extension.
READ TABLE it_accit WITH KEY posnr = wa_extension-field1(10).
IF sy-subrc EQ 0.
it_accit-bschl = wa_extension-field1+10(2).
MODIFY it_accit INDEX sy-tabix.
ENDIF.
ENDLOOP.
ENDFUNCTION.
Configuration
Step 1: Go To Transaction code FIBF
Step 2: Add Customer Product. Use Menu Option : Settings -> Products -> ...of a
Customer
Step 3: Save the Product.
Step 4: Create a Link between BTE and Product created in Step2. Use the menu option : Settings -> Process Modules ->
... of a customer
Step 5: Save the Link.
Summary
When the BAPI is executed, Code written in the BTE - function module will be executed and the posting key of related
line item will be changed before posting the documents.
Related Content
https://forums.sme.sap.com/message.jspa?messageID=8284886
http://forums.sdn.sap.com/message.jspa?messageID=9288661
http://forums.sdn.sap.com/thread.jspa?threadID=999473