Paqe of GC20-1819-2 As Updated April 27, 1981 by TNL SN25-0828 For 5748-XE1 Usually, CMS opens a file whenever an FSREAD or FSWRITE macro
instruction is issued for the file. When control returns to CMS from a
calling program, all open files are closed by CMS, 50 you do not have to
close files at the end of a program.
For a minidisk in 1K-, 2K-, or 4K-byte block format, a file may be
open for concurrent read and write operations, and an FSCLOSE need not
be issued when switching from reading to writing, or vice versa. For
example:
LA 3,2
READ F3READ FSCB=UPDATE,RECNO=(3) ,ERROR=READERR,FORM=E FSWRITE FSCB=UPDATE,RECNO=(3),ERROR=WRITERR,FORM=E LA 3,1(3)
BREAD UPDATE FSCB 'UPDATE FILE A1',BUFFER=BUF1,BSIZE=80,FORM=E However, if you want to read and write records from the same file on
an 800-byte block format minidisk, you must issue an FSCLOSE macro
instruction to close the file whenever you switch from reading to
writing. For example: READ UPDATE LA 3,2 FSREAD FSCB=UPDATE,RECNO=(3) ,ERROR=READERR FSCLOSE FSCB=UPDATE FSWRITE FSCB=UPDATE,RECNO= (3-), ERROR=WRITERR FSCLOSE FSCB=UPDATE LA 3,1(3)
BREAD FSCB 'UPDATE FILE A1',BUFFER=BUF1,BSIZE=80 In addition to the instances stated above, it is practical to use the FSCLOSE macro periodically in a program which makes extensive changes to
a file. Because the directory is not updated until the file is closed,
the FSCLOSF macro protects you against the possibility of losing
whatever changes were made should you unexpectedly be logqed off the
system before closing the file.
To execute a loop to read, update, and rewrite records, you must read
a record, close the file, write a record, close the file, and so on. Since closing a file repositions the read pointer to the beginning of
the file and the write pointer at the end of the file, you must specify
the relative record number (BECNO) for each read and write operation. In
the above example, register 3 is used to contain the relative record
number. It is initialized to begin reading with the second record in
the file and is increased by one following each write operation. When you use an EXEC to execute a proqram to read or write a file,
the file is not closed by CMS until the EXEC completes execution.
Therefore, if you read or write the same file more than once during the
248 VM/370 eMS User's Guide
Page of GC20-1819-2 As Updated April 27, 1981 by TNL SN25-0828 For 5748-XE1 EXEC procedure, you must use an FSCLOSE macro instruction to close the
file after usinq it in each program, or use the FSOPEN macro instruction
to open it before each use. Otherwise, the read or write pointer is
positioned as it was when the previous proqram completed execution. FI1ES: When you want to begin writing a new file using CMS data management macros, there are two ways to ensure that the file you
want to create does not already exist. One way is to issue the FSSTATE macro instruction to verify the existence of the file.
A second way to ensure that a file does not already exist is to issue
an FSERASE macro instruction to erase the file. If the file does not
exist, register 15 returns with a code of 28. If the file does exist, it
is erased.
Figure 21 illustrates a sample program using CMS data management
macros.
section 13. Programming for the CMS Environment 248.1
Previous Page Next Page