There might be a problem when you need to debug such a program, because you never know, when your code will be called.
Here is the trick:
DATA: lv_counter TYPE i.
* Call neverending loop in your code
WHILE lv_counter = 0.
“this will stop, when you change lv_counter
“to s/thing else in debugger
And run your program.
Go to transaction “SM50” find your running program in a process. Select the process -> click Program/Session -> Program -> Debugging. In debug mode, just change the value of lv_counter to something else and now, you are able to debug your dynamically called program in background.