If you are using DFSORT to check for the line, then look into the option that returns a different return code for an empty output file. It's an option you can put in during the actual sort step. It's like "NULLRC" or something like that. It would save you a step.

Also, something to think about: What if all the active generations are empty? Is that OK? Or do you want to do the same thing with that situation?

If you can just wait a couple of hours in case Kolusu wants to illuminate the DFSORT trick, then maybe we can split it (again) leaving the DFSORT stuff here and shipping off the rest?

IDCAMS is the way to do it. DFSORT cannot be used in this case as the System rejects right away as "dataset not found"(base name specified as sortin) if the GDG does not have any generations. With IDCAMS listcat you are coding the GDGbase name in the sysin and the system doesn't validate the existence.