I support Jim's suggestion.
I feel that deleted records should never be used in any processing, i.e. DELETED should be set to ON in the main program and should not be changed anywhere in the program. (One has to be careful in Private datasession as the default for DELETED is OFF). If it is required to use the deleted records, those may be RECALLed, but not processed with SET DELETED OFF.
Another settings that may casuse problem is SET EXACT. I have seen that changing this settings in program may cause unexpected results. My preferred setting for both EXACT and DELETED is ON.