2023 Mar 07 3:38 AM
Hi All,
Good day, I need opinion on this DO X Times logic.
Recently we facing many implementation using this syntax. Reason was , SAP database not updating immediately even after TRANSACTION COMMIT with WAIT.
For example, after called BAPI_PRODORD_CHANGE to change the Production Order Document and called BAPI_TRANSACTION_COMMIT with parameter = WAIT.
Unfortunately Total Order Quantity (AFKO-gamng) still not immediately updated. So developer need to
Do 10 Times,
CLEAR lv_gamng.
SELECT SINGLE
gamng
FROM afko
INTO @lv_gamng
WHERE aufnr = @vl_orderno.
IF l_gamng = iv_order-qty_assigned.
EXIT.
ENDIF.
ENDDO.
I would like to double check, any other alternative solution instead of using DO X Time ?
Many thanks.
Best Regards,
CTK
2023 Mar 07 8:11 AM
Hello kuanchin
Usually BAPI_TRANSACTION_COMMIT with WAIT = X does the trick of synchronous update. But that is not the case with BAPI_PRODORD_CHANGE. As per the BAPI documentation:
Update Control
The method independently triggers the update to the database. You do not need to execute a COMMIT WORK again after the method has been called.
So you do not need to call BAPI_TRANSACTION_COMMIT after BAPI_PRODORD_CHANGE. In fact that call is superfluous and does not do anything.
Instead you can try executing SET UPDATE TASK LOCAL before executing BAPI_PRODORD_CHANGE. As per SAP Help to local update:
Update in the current work process. It is executed in a separate internal session of the current ABAP session and not in a dedicated update session.
Best regards
Dominik Tylczynski
2023 Mar 07 8:31 AM
Hi Dominik,
Good day, thanks for your valuable sharing.
Sorry I forgotten to refer BAPI documentation and thanks for this hints.
Will inform the developer for the same.
Best Regards,
CTK
2023 Mar 07 8:58 AM
Please edit your question, select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!
2023 Mar 07 9:03 AM
Hi,
Good day, thanks for your hints.
DO 10 Times,
CLEAR lv_gamng.
SELECT SINGLE gamng
FROM afko
INTO @lv_gamng
WHERE aufnr = @vl_orderno.
IF l_gamng = iv_order-qty_assigned.
EXIT.
ENDIF.
ENDDO.
2023 Mar 07 2:16 PM
As this BAPI handles the commit itself, you can't rely on a WAIT option.
If you don't want to use the SET UPDATE TASK LOCAL, you could try to lock the Production Order Number (ENQUEUE_ESORDER with wait option) in a DO/ENDDO loop, release and exit loop when locked else iterate.
2023 Mar 08 1:10 AM
Hi,
Good day, would like to double check, if the ENQUEUE_ESORDER locked successful, is it mean the Total Order Quantity (AFKO-gamng) was updated already ?
Many thanks.
Best Regards,
CTK
2023 Mar 08 12:52 PM
In case of doubt, or poor performance of the database server/buffer management, you can keep the loop on the 'select from table' after the loop on the order lock. (it is better to be safe than sorry. ) This case should be very rarely necessary.