cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI_GOODSMVT_CREATE doesn't post material document inside loop inspite of COMMIT

Former Member
0 Kudos

Hi All,

Help needed!

I've been facing this strange problem for sometime. I'm using BAPI_GOODSMVT_CREATE to post a stock transfer from plant to plant during creation of Sales Order. Now, a line item in Sales Order might have unrestricted stock in multiple batches( txn. MMBE). So, I will have to call the BAPI multiple times to post multiple batches. Eventually, I'm calling this BAPI inside a loop. Now, the real problem is, it posts the material document on the first iteration of the loop. It doesn't post on subsequent loops. So, my goods movement is done from only one batch. I added a BAPI_TRANSACTION_COMMIT after the call, still it doesn't post after the first iteration. This happens in random sales orders. Not everytime.

Thank You!

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member

Did you look at the return parameter of the BAPI_GOODSMVT_CREATE? When calling the BAPI inside a loop, you could encounter issue that the material/plant locks created by previous call may not have release yet. You could try putting a wait of 3 sec after commit statement to prevent this. Or could try commit only outside the loop.

Former Member
0 Kudos

Thanks for the response Sireesh. I thought of doing this. But, do you think adding a 3 second WAIT might have an impact on the performance? Also, I did try this earlier in another program, as a 5 second pause and it only works when i debug the program. It doesn't when the program is run on the fly or if it is part of a transaction. The moment I save the Sales Order, I'm able to see the record in the table the next second.

Thanks,

Harish M

Jelena
Active Contributor
0 Kudos

You might want to read the answer again - the first suggestion was to look at the return table of the BAPI. Are you doing that and when the document does not get posted don't you see any messages in the table?

Before taking an action you need to establish the root cause first. Otherwise you could be solving a non-existent problem.

Also post the actual code when asking such questions.

Former Member
0 Kudos

Dear Sirish/Jelena,

I agree with your points. I do have a check at the return table level after the BAPI is called. I push a BAPI_TRANSACTION_COMMIT only if the BAPIRET is initial and the return parameter of GOODSMVT_HEADRET has a value in field MAT_DOC.

Thanks,

Harish M

Former Member
0 Kudos

Harish,

Please check and report on the return parameter of the BAPI. Since this is not happening in debug, you might want to use Message or write statement.

Based on how you are describing, if this is working in Debug and not otherwise, it could most likely be a Lock issue at the material/plant level. Just for testing purpose, you could introduce a 5 sec wait after commit. It will definitely effect the performance.

Former Member
0 Kudos

Dear Sireesh,

Thanks for the input. I will do and try it for sure. But, as this happens in random scenarios i might need a while to test this properly.

Thanks again!

Regards,

Harish M