Skip to Content
0
Former Member
Nov 16, 2012 at 06:25 AM

Commit within loop

2054 Views

Hi,

As per the requirement, in our program a database table need to be updated. Now user wants to run multiple job ( with different store id) parallel with this program. So, I have locked the table based on the key fields and made a commit work within loop. Can anyone suggest, if there is any better solution instead of committing in the loop. Please check below for the code part. Thanks in advance.

LOOP AT pi_data INTO lwa_data.

CALL FUNCTION 'ENQUEUE_EZ_ZSTOCK_HYBRIS'

EXPORTING

mode_zstock_hybris = 'E'

mandt = sy-mandt

article = lwa_data-article

store_id = lwa_data-store_id

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

IF sy-subrc IS INITIAL.

*Modify table

MODIFY zstock_hybris FROM lwa_data.

* Commiting in the loop, as multiple job will be executed parallely.

COMMIT WORK.

* Unlock the table

CALL FUNCTION 'DEQUEUE_EZ_ZSTOCK_HYBRIS'

EXPORTING

mode_zstock_hybris = 'E'

mandt = sy-mandt

article = lwa_data-article

store_id = lwa_data-store_id.

ENDIF.

CLEAR lwa_data.

ENDLOOP.