Take a look at PC_PRINT_FILE routine in the docs under Library routines.
The first parameter that you pass in is a variable containing the filename to print.
This could be the same variable that you use to hold the file-name in the SELECT.
If you are assigning your file to an environment variable which is set outside of the program then you would have to read the contents of that environment variable in order to set the name.
something like the following:
select test-file assign to external MYENV
...
01 pn-name.
03 pn-name-len pic x(2) comp-5
03 pn-name pic x(256).
open output test-file
display "MYENV" upon environment-name
accept pn-name from environment-value
*>find the length of the file name
perform varying pn-name-len from length of pn-name by -1 until pn-name-len < 1
if pn-name(pn-name-len:1) not = " "
exit perform
end-if
end-perform
call "PC_PRINT_FILE using pn-name...