|
OpenVMS DCL Dictionary
WRITE
Writes the specified data as one record to an open file specified by a
logical name.
All qualifiers must precede all data item expressions.
Format
WRITE logical-name expression[,...]
Parameters
logical-name
Specifies the logical name assigned to the output file. Use the logical
name assigned by the OPEN command. In interactive mode, specify the
process-permanent files identified by the logical names SYS$INPUT,
SYS$OUTPUT, SYS$ERROR, and SYS$COMMAND. (The OPEN command assigns a
logical name to a file and places the name in the process logical name
table.)
expression[,...]
Specifies data to be written as a single record to the output file. You
can specify data items using character string expressions, which may be
symbol names, character strings in quotation marks (" "),
literal numeric values, or a lexical function. For more information on
string expressions, refer to the OpenVMS User's Manual.
You can specify a list of expressions separated by commas (,); the
command interpreter concatenates the items into one record and writes
the record to the output file.
The maximum size of any record that can be written is less than 1024
bytes, and the value of any symbol that is specified as part of a
record cannot exceed 255 characters; however, if you specify the
/SYMBOL qualifier, the maximum record size is 2048 bytes and the value
of a symbol can exceed 255 characters.
Description
The WRITE command can write records to sequential, relative, or indexed
files that have been opened for writing. When the WRITE command writes
a record, it always positions the record pointer after the record just
written.
To write to a file, the file must be opened by using either the /WRITE
or the /APPEND qualifier with the OPEN command; however, the
process-permanent files identified by the logical names SYS$INPUT,
SYS$OUTPUT, SYS$ERROR, and SYS$COMMAND do not have to be opened
explicitly to be written to.
If you do not specify the /SYMBOL qualifier, DCL places the command and
the complete string expression (expanded if it was specified as one or
more symbols) in a 1024-byte buffer. If you specify the /SYMBOL
qualifier, DCL interprets the symbol or symbols and places the expanded
string in a separate 2048-byte buffer, and then performs the write
operation. For this reason, use the /SYMBOL qualifier where the record
contains approximately 1000 bytes or more.
Qualifiers
/ERROR=label
Transfers control on an I/O error to the location specified by
label (in a command procedure). If no error routine is
specified and an error occurs during the writing of the file, the
current ON condition action is taken. The /ERROR qualifier overrides
any ON condition action specified. If an error occurs and control
passes successfully to the target label, the reserved global symbol
$STATUS retains the error code.
/SYMBOL
Causes the expression to be interpreted and its expanded value placed
in a 2048-byte (instead of a 1024-byte) buffer before the write
operation is performed. If you specify multiple expressions, their
values are concatenated and placed in the 2048-byte buffer. Use the
/SYMBOL qualifier to write a very large record.
Each expression specified must be a symbol. You cannot specify
character string expressions (that is, strings in quotation marks) with
the /SYMBOL qualifier.
If you do not use the /SYMBOL qualifier, the entire command, including
the expression or expressions, is placed in a 1024-byte buffer.
/UPDATE
Replaces the last record read with the record specified with the
expression parameter. You must be able to read and write to a file to
use the /UPDATE qualifier. Use the WRITE/UPDATE command only after a
READ command. The WRITE/UPDATE command modifies the last record you
have read.
With sequential files, you must replace a record with another record of
the same size when you use the WRITE/UPDATE command.
Examples
#1 |
$ WRITE SYS$OUTPUT "Beginning second phase of tests"
|
The WRITE command writes a single line of text to the current output
device.
#2 |
$ OPEN/APPEND OUTPUT_FILE TRNTO::DKA1:[PGM]PLAN.DAT
$ WRITE OUTPUT_FILE "BEGINNING PHASE 3"
|
In this example, the OPEN/APPEND command opens the file PLAN.DAT at the
remote node TRNTO and positions the pointer at the end of the file. The
WRITE command writes a record to the end of the file PLAN.DAT.
#3 |
$ OPEN/WRITE OUTPUT_FILE TESTFILE.DAT
$ INQUIRE ID "Assign Test-id Number"
$ WRITE/ERROR=WRITE_ERROR OUTPUT_FILE "Test-id is ",ID
$ WRITE/ERROR=WRITE_ERROR OUTPUT_FILE ""
$ !
$ WRITE_LOOP:
.
.
.
$ GOTO WRITE_LOOP
$ END_LOOP:
$ !
$ CLOSE OUTPUT_FILE
$ PRINT TESTFILE.DAT
$ EXIT
$ !
$ WRITE_ERROR:
$ WRITE SYS$OUTPUT "There was a WRITE error."
$ CLOSE OUTPUT_FILE
$ EXIT
|
In this example, the OPEN command opens the file TESTFILE.DAT; the
INQUIRE command requests an identification number to be assigned to a
particular run of the procedure. The number entered is equated to the
symbol ID. The WRITE commands write a text line concatenated with the
symbol name ID and a blank line.
The lines between the label WRITE_LOOP and END_LOOP process information
and write additional data to the file. When the processing is finished,
control is transferred to the label END_LOOP. The CLOSE and PRINT
commands at this label close the output file and queue a copy of the
file to the system printer.
The label WRITE_ERROR is used as the target of the /ERROR qualifier to
the WRITE command; if an error occurs when a record is being written,
control is transferred to the label WRITE_ERROR.
#4 |
$ OPEN/APPEND MYFILE [LAMPERT]TESTING.DAT
$ WRITE/SYMBOL MYFILE A,B,C
|
This example assumes that the symbols A, B, and C have already been
defined. The OPEN/APPEND command opens the file [LAMPERT]TESTING.DAT
and positions the pointer at the end of the file. The WRITE/SYMBOL
command concatenates the values of the symbols A, B, and C and writes
this data to a new record at the end of the file.
Appendix A Obsolete Commands
Table A-1 lists the obsolete DCL commands and the current services
that replace them.
Table A-1 Obsolete Commands
Obsolete Command |
Replaced by |
SET ACL
|
SET SECURITY/ACL
|
SET PROTECTION
|
SET SECURITY/PROTECTION
|
SET PROTECTION/DEVICE
|
SET SECURITY/PROTECTION/CLASS=DEVICE
|
SET UIC
|
Not replaced.
|
SHOW ACL
|
SHOW SECURITY
|
UNLOCK
|
SET FILE/UNLOCK
|
|