Recently, I had to use an RPG program to write records from one file to another. The file I was writing to didn't allow duplicate records, but the file I was reading from did. I wrote my program, coding the error indicator on the WRITE op code to handle the duplicate record errors. My program failed because it wrote too many messages to the joblog.
I've learned a better way. Instead of using the WRITE with the error indicator, CHAIN to the file first. You may think it's a toss up as to which is the better method to use to see if the record exists, but I can tell you from experience it isn't. Numbers indicate a 33 percent performance improvement when using CHAIN. And you won't get a 3,000 page joblog.
MC Press Online