Learn how to manage media capacity on a per-file basis.
Assume an optical volume is initialized to a 95% threshold and an application writes files until the volume threshold is reached. When the threshold is reached, the application will receive message CPF1F61, No free space available on media. At this point, the volume threshold can be increased to 97% (or anything else up to 100%) by using the CHGOPTVOL command. You can then attempt to close the file.
If the size of the file is known prior to the time the open request is made, and there will not be other jobs writing to that volume during the time your file is open, this is an excellent method to check media capacity before creating a file.
Another method is to have the application retrieve the space available on the volume. You can do this by using the Display Optical (DSPOPT) command through output file support. The output file can then be read to retrieve the number of bytes assumed to be available on the media.