Operating System - OpenVMS
1752590 Members
3128 Online
108788 Solutions
New Discussion юеВ

Record operation not allowed by (FAC)

 
James A. Hilley
New Member

Record operation not allowed by (FAC)

This is becoming a nagging problem.

I am simply writing a string to a dat file (code excerpt)

$ OPEN/WRITE INFILE SIMPLE.DAT
$ WRITE INFILE STRING_VAR
$ CLOSE INFILE

This problem comes and goes; my permanent solution is:

$ OPEN/WRITE INFILE SIMPLE.DAT
$ CLOSE INFILE

$ OPEN/WRITE INFILE SIMPLE.DAT
$ WRITE INFILE STRING_VAR
$ CLOSE INFILE

What is causing this problem? There is nothing complex about my code. Is it a timing issue between the OPEN and WRITE?
6 REPLIES 6
Hoff
Honored Contributor

Re: Record operation not allowed by (FAC)

Always issue a CLOSE /NOLOG INFILE prior to an OPEN [/switches] INFILE [file] command.
Robert Gezelter
Honored Contributor

Re: Record operation not allowed by (FAC)

James,

As an amplification of Hoff's comment, it is not uncommon for a file to be left open, either because of a coding error or a command procedure that was aborted by CNTRL-Y.

This can be seen by doing a SHOW LOGICAL/PROCESS, the files will show up in the process logical name table.

The CLOSE can be done, or a more complex check using the F$TRNLNM lexical function can check for the presence of the logical name in the process logical name table (LNM$PROCESS).

- Bob Gezelter, http://www.rlgsc.com
James A. Hilley
New Member

Re: Record operation not allowed by (FAC)

Is this only a problem with a WRITE? Do I need to CLOSE/NOLOG INFILE before all OPENS, whether they be READ or WRITE?

NOTE: I am just now revisiting DCL after a 15-year absence.
Hoff
Honored Contributor

Re: Record operation not allowed by (FAC)

Using CLOSE /NOLOG prior to any OPEN is defensive DCL.

When programming with OPEN, the OPEN opens a file if not open, or uses an existing and opened file if previously opened and not closed and picks up where you left off.

Thus the result is that one OPEN case leaves you where you expect in the file, and the other doesn't.

CLOSE /NOLOG ensures that your code always follows through the expected I/O path.

Any OPEN. Read or write.
John Gillings
Honored Contributor

Re: Record operation not allowed by (FAC)

I prefer:

$ IF F$TRNLNM("INFILE").NES."" THEN CLOSE INFILE

at the end of a procedure (including the ^Y exit path) to make sure the file is always closed on exit. You could do the same prior to the OPEN if you're paranoid.

For debugging, try:

$ WRITE SYS$OUTPUT "INFILE=",F$TRNLNM("INFILE")

prior to the OPEN.
A crucible of informative mistakes
Volker Halle
Honored Contributor

Re: Record operation not allowed by (FAC)

James,

you will get the %RMS-F-FAC message on the WRITE INFILE STRING_VAR command, if the file INFILE is already open AND it has only been opened for READ (which is the default for OPEN INFILE SIMPLE.DAT) before.

So somewhere in your DCL procedure or in another DCL prcedure run in your process before, you seem to be opening INFILE for READ and forgot to close it.

Volker.