Generally speaking, CL is not a database language. Put the ad hoc SQL in a source member and execute it with the CL command RUNSQLSTM. For more dynamic SQL inside a CL program, use RUNSQL.
If I recall, this application is creating some archive files and this is the final step. When you create the archive files, it would be easy to also create the 'duplicates' file. I'd consider that as a better route, because you can more easily create a report or spreadsheet or web page or some other record of the customers you are about to purge.