Hello David,
I am afraid that this is the standard behavior.
if you post a document via BAPI_ACC_DOCUMENT_POST the number range
for the specific company code/document type is locked (table NRIV).
The lock is released as soon as you COMMIT your transaction
because before a COMMIT the system has to be able to rollback the
number range interval.
A single BAPI call is never a problem, but as soon as you have at
least two parallel processes posting via the BAPI deadlocks can occur
if each process posts more than one FI document within one logical
unit of work.
The safest way to generally avoid this is to generally do
a COMMIT WORK after each single call to BAPI_ACC_DOCUMENT_POST.
If you encounter performance problems doing so it might be helpful
to use "SET UPDATE TASK LOCAL." in your ABAP report so the
DB updates are done locally and not in update task.
By the way if you post inbound IDOCs with report RBDAPP01
it works the same way: Although you can specify a package size
there, within every package each document is COMMITTed independently,
the packages are just processed in parallel.
Other point that you can study is use "pseudo ascending number assignment".
Locks in NRIV are common when buffer is not used in order to guaranty
the sequential numbers. This setting prevents parallel running processes
to access the document number object at the same time and therefore a
deadlock occurs in that case.
I understand that you want to avoid gaps in the document number range.
We have a solution for you to allow buffering and still avoid gaps in
the number range. It's called "pseudo ascending number assignment".
The main point is to make the system focus on the document numbers and
not so much on timestamp. Note 840901 explains it in detail and provides
the steps.
Note 599157 describes parallel buffering as well, and note 840901
explains pseudo ascending document number assignment if this is
needed for legal regulations in some countries. This is also explained
on page 3 of note 1398444.
In BTE 00001170 you have the possibility to only activate/deactivate the
buffering for certain number ranges and company codes. This allows you
to adapt the buffering to your business requirements.
I hope this helps.
Kind Regards,
Raquel