In your RPG program you can place a call to the QUSRSPLA system API to try and retrieve the attributes of the spool file. If nothing is returned in the error data structure for the API then the spool file exists, if an error is returned then the spool file could not be found.
I don’t have an RPG example available for this API, but I do have a CL program example that accepts the spool file name and job details and returns an indicator to identify whether or not the spool file exists.
The source for the CL program can be found at:
It shouldn’t be difficult to convert the method into RPG and create a sub-procedure you can add to your toolbox.
All the best