Debugging a dynamic NATURAL program

Hi

I have an old dynamic batch program (with ampersand variables) that is called by a RUN command and has recently started producing a 1316 error (Index not within array structure).
My initial thought was to add a WRITE to the program to see what is causing the problem but that just causes syntax errors within the code as it obviously messes with the compile at RUN time.
Is there a way to debug this dynamic program?
Here is an excerpt of the code:

The error is in line 1560 so I tried adding an ampersand variable containing the WRITE statement but that didn’t do anything.

COMPRESS FULL ‘WRITE’ ‘“=”’ ‘#LEVEL’ ‘“=”’ #LEVEL-A INTO +WRITE

There is no need for the COMPRESS. Just use a standard WRITE statement in the dynamic program.
WRITE '=' #LEVEL '=' #LEVEL-A
If you insist on generating the WRITE, the COMPRESS must be in the driver, not the dynamic program.