Skip to Content
Technical Articles
Author's profile photo Jonathan Eemans

Change financial document using function module FI_DOCUMENT_CHANGE


Financial accounting documents are updated online via transactions FB02 (change document) / FB09 (change line item) or Fiori apps such as Manage Journal Entries. Certain business cases require the documents to be changed via interface (from file or other source). When changing accounting documents via interface and not directly online in your SAP environment, the function module FI_DOCUMENT_CHANGE can be used. In this blog post I share a test program to change a financial document using function module FI_DOCUMENT_CHANGE.


Test program to change FI document using function module FI_DOCUMENT_CHANGE

*& Report ZTEST
*& Test program: Update FI document
report ztest.

* Constants document to be changed - TO BE CHANGED
  lc_bukrs type bukrs      value 'BEN0',
  lc_belnr type belnr_d    value '0560000096',
  lc_gjahr type gjahr      value '2017',
  lc_buzei type buzei      value '001'.

* Constants
  lc_k     type koart      value 'K',              " Vendor Account Type
  lc_gname type eqegraname value 'BKPF',           " Elementary Lock of Lock Entry (Table Name)
  lc_zuonr type char05     value 'ZUONR'.          " Field name for assignment at line item

* Variables
data: lv_garg  type eqegraarg.                     " Argument String of Lock Entry

* Structures
data: ls_accchg     type accchg.                   " Changing FI Document Work Area

* Tables
  lt_accchg type standard table of accchg,         " Changing FI Document
  lt_enq    type standard table of seqg3.          " Lock entry details

*     Filling the fields to be changed
ls_accchg-fdname = lc_zuonr.
ls_accchg-newval = 'TEST UPDATE'.              " New value assignment field - TO BE CHANGED
append ls_accchg to lt_accchg.

if lt_accchg is not initial.
*     Check if there is lock on document before proceeding
  call function 'ENQUEUE_READ'
      gclient               = sy-mandt
      gname                 = lc_gname             " BKPF
      garg                  = lv_garg
      enq                   = lt_enq
      communication_failure = 1
      system_failure        = 2
      others                = 3.

  if sy-subrc eq 0 and lt_enq is initial.

*     Call the FM to update the FI document
    call function 'FI_DOCUMENT_CHANGE'
        i_bukrs              = lc_bukrs
        i_belnr              = lc_belnr
        i_gjahr              = lc_gjahr
        i_buzei              = lc_buzei
        t_accchg             = lt_accchg
        no_reference         = 1
        no_document          = 2
        many_documents       = 3
        wrong_input          = 4
        overwrite_creditcard = 5
        others               = 6.

    if sy-subrc = 0.
*       Commit the changes
      call function 'BAPI_TRANSACTION_COMMIT'
          wait = 'X'.



Function module FI_DOCUMENT_CHANGE can be used to update financial accounting documents in your SAP environment.


Useful reference

Knowledge base article 2713775:

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      Thanks for sharing! It's funny how SAP sets the FM to "not released" but then writes a KBA on it. 🙂

      Note: you don't need to use [ ] here for internal tables. That would apply if you declared a table with header line but, thankfully, it's not the case.

      Author's profile photo Jonathan Eemans
      Jonathan Eemans
      Blog Post Author

      Thanks for your feedback.
      I've removed the [ ] in the code.

      Author's profile photo Tjarliman Rusadi
      Tjarliman Rusadi

      This is great documentation.

      I just notice that when I was using this FM to update an accounting document, the changes was not log into the Document Change Log, unlike if we were change the document via FB02.

      Is there anyway we can update the Document Change Log when we use this FM to update an FI Doc?



      Author's profile photo Jonathan Eemans
      Jonathan Eemans
      Blog Post Author

      When committing your changes, the change log should be updated correctly.

      Best regards,

      Author's profile photo Warren Nash
      Warren Nash

      Question:  This FM is not updating the BSID table for header information changes (XBLNR), any reason why?  Is there a background job to refresh the index from BKPF/BSEG?

      Author's profile photo Achal Mukaty
      Achal Mukaty

      Is there any FM to update Billing document ?

      Author's profile photo Achal Mukaty
      Achal Mukaty

      I don't find a work area like changing FI document here for changing billing document.

      Author's profile photo Thomas Madsen Nielsen
      Thomas Madsen Nielsen

      I just found this post and even if it is 2 years old, it is just exactly what I need. Thank you 🙂

      I have one question though.

      As this example is updating the header reference field ZUONR, why is the item number (BUZEI) parameter set to 001?

      Best regards

      Thomas Madsen Nielsen