Resolution:
Recode your program to ensure that the REWRITE statement in error is preceded by a read NEXT.