Hi Ketrine
Hard to tell without understanding more details, but I am using different tables than you, i.e. not using the accounting data table - instead using the item data. The invoice must balance, so check to see if there are taxes or discounts or something else causing the balance error.
Attaching an example, in case it helps. Note it was built and run on ECC, although it may work on S4. The success message isn't helpful, but I'm downloading the invoice document number and fiscal year on the right.

Best Regards,
Sigrid
------------------------------
Sigrid Kok
*Precisely Software Inc.
------------------------------
Original Message:
Sent: 08-07-2025 12:14
From: Ketrine Giha
Subject: MIRO - BAPI_INCOMINGINVOICE_CREATE
Hi Everyone, we are trying to use this BAPI for create subsequent debit and subsequent credit but we are facing issue "Balance is not zero" Can someone provide me help with this?
------------------------------
Ketrine Giha
Consultant
PepsiCo (Business Solutions Group)
Winston Salem
Original Message:
Sent: 02-15-2021 18:30
From: Sigrid Kok
Subject: MIRO - BAPI_INCOMINGINVOICE_CREATE
Hi Katarzyna
It's hard to tell without seeing the script and data.
I can tell you, however, that many of the tables in that BAPI for line item related data all use the document item number, but it's repeated in each table. You can map the all to the same column so that it's consistent and you only need to enter it once.

HTH
Sigrid
------------------------------
Sigrid Kok
PSE | Winshuttle NA
Original Message:
Sent: 02-10-2021 06:58
From: Katarzyna Szymczewska
Subject: MIRO - BAPI_INCOMINGINVOICE_CREATE
Hello everyone,
I would like to ask you for support with clearing of obsolete GR/IR using MIRO transaction.
I was looking for the best approach for clearing and decided to use BAPI to create script based on module BAPI_INCOMINGINVOICE_CREATE. This topic was discussed on the forum and I have found very useful script and instruction, but I'm still struggling some problems during the run.
As a base I have used script shared by Sigrid and extended it by data from GLACCOUNTING area. Unfortunately it gives me error message "Enter a reference to a valid goods receipt (line 000001)".
I found out this may be caused by missing fields:
ITEMDATA – REF_DOC
ITEMDATA – REF_DOC_YEAR
ITEMDATA – REF_DOC_IT
I have added and filled required fields, but something is still causing the problem. Maybe I'm still missing something, created loop is wrong or some conditions are required to enable posting of the clearing document.
I will appreciate any comments and advise on this topic.


Kind regards,
Katarzyna
------------------------------
Katarzyna Szymczewska | Accounting and Reporting Senior Data Analyst
Owens Illinois | 123
------------------------------