When you write a reusable code to DB related activities, you should consider checking if the call is made in Update Task or without as they are generally happen in ABAP Update Task. If it is with Update Task, you MUST not do COMMIT or ROLLBACK WORK as it would end in short dump. FM
TH_IN_UPDATE_TASK would help to determine if it is being called in Update Task or not.
Check if called in UPDATE Task
DATA: lv_in_update TYPE i. * CALL FUNCTION 'TH_IN_UPDATE_TASK' IMPORTING in_update_task = lv_in_update. * IF lv_in_update = 1. "called in update task "no need to do COMMIT or ROLLBACK here ELSE. "not called in Update TASK "COMMIT or ROLLBACK would be required ENDIF.
Do you have a Code Snippet which you want to share, Submit Code Snippet here