Hi Vijay. Thanks again for your comments.
You're right, I'm a developer too
.
I understand your point but the weirdest thing about this issue is that if I run this functions step by step in Debug mode, then I'm able to generate all the sales document and deliveries correctly. I already validated the data added with the people involved in this process and the data saved after executing this functions are correct, but when I run the function without breakpoints, I receive the lock error that I described before.
After some research I found that maybe the issue is related to the time required for commit the changes to the database and unlock the record. But I don't know how to "pause" the application until the BAPI finishes his database commit and unlocks the record before continuing to the next function (the WS_DELIVERY_UPDATE).
At this point and with the parameters you suggested the delivery order is generating correctly, as well as the sales document.
Am I missing something that I dont take into account?
Thanks for your comments Vijay and warm regards.
Lorenzo Martín Olmos