Page tree
Skip to end of metadata
Go to start of metadata

Business Transaction Event - RWBAPI01 - For Accounting Document Interface

Link to Content's target Space :

Applies to:

SAP 4.7x and above.


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


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

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
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,
** 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
     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
     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.
** display the output
 LOOP AT it_return INTO wa_return.
   WRITE :/ wa_return-type,



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

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
FUNCTION zsample_interface_rwbapi01.
 ""Local Interface:
  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.



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.


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

Useful Information

Short quick summary to catch the reader's attention and of course the search engine

BTE, RWBAPI01, BAPI_ACC_DOCUMENT_POST, Business Transaction Events, FICO, FI


  1. Dear Vinod,

    Thanks for this useful information.

    I tried the same but the BTE Function Module is not getting triggered while call the BAPI_ACC_DOCUMENT_POST.

    Need help on that.


  2. Very Good Document.

  3. Its useful document 

  4. @Deepak Batra,

    Are you able to resolve this issue.  BTE Function Module is not getting triggered while call the BAPI_ACC_DOCUMENT_POST.

    I am also facing the same issue.



  5. Hello,

    In order to trigger this BTE, you need to pass a non-empty internal table extension1[] to the BAPI, as the BAPI code is doing a check if this table is empty, before calling the BTE.


  6. Hi, Thanks for your reply. Still not able to trigger BTE. passed  Extension1 also now. Below is my BAPI call. Extension 1 as empty table.

    *-- Posting journal entries
            documentheader    is_doc_header
            customercpd       is_doc_onetimeact
            obj_type          ev_obj_type
            obj_key           ev_obj_key
            obj_sys           ev_obj_sys
            accountgl         lt_acc_gl
            accountreceivable lt_ar_cust
            accountpayable    lt_ap_vend
            accounttax        lt_tax
            currencyamount    lt_curr_amt
            criteria          lt_criteria
            valuefield        lt_valfld
            extension1        lt_extension1
            extension2        lt_extend
            return            et_return.