|
Rick Andrews <richard.andrews@CMS.HHS.GOV> wrote:
> I found this code on SAS-L to prevent a file from being opened if it
> already being used. I'm trying to do this to prevent an evil "FILE IN
USE"
> message, which kicks the program into syntax check mode.
>
> This code does not seem to work for me on the mainframe. Any ideas?
>
> Muchas gracias!
>
> filename prodfile "&PRODFILE";
> data _null_;
> inuse = fopen('prodfile');
> call symput('INUSE',inuse);
> if inuse = 0 then do;
> put '*** Attention: the file below was in use ***';
> put "&PRODFILE";
> put '*** Attention: the file above was in use ***';
> end;
> run;
> %IF &INUSE NE 0 %THEN %DO;
A couple things come to mind. For one thing, if you use FOPEN()
in z/OS, you have to use FCLOSE() at the end of the DATA step, or else
the file stays open. SAS doesn't automatically close the files after
processing. I think OpenVMS has the same constraint.
A more subtle issue could be the fact that this test is not
atomic (in the comp sci sense of the word). It is feasible
that your test will find the file available, but then before
you can open it for processing, some other program could come
in and snag it, thus giving you the same old "FILE IN USE"
message you have come to know and love. If this could happen,
then perhaps you want to do all your processing in one single
data step, using FOPEN() to test the file, while at the same time
opening it for reading later in the data step using FREAD()
and then processing of the File Data Buffer, before ending the data
step with the requisite FCLOSE().
HTH,
David
--
David Cassell, CSC
Cassell.David@epa.gov
Senior computing specialist
mathematical statistician
|