I'd like to be able to use CPYTOSTMF to copy a file created by a
query but I get an error message
The second-level text of that message tells you exactly why the copy
fails. It does not support externally described database files.
Perhaps one of the other CPYxxx commands would suit your purposes
better? Maybe CPYTOIMPF or perhaps one of the many free tools to
convert a database file into a stream file.