WRITE Statement

The WRITE statement causes data to be transferred from various program variables to a file.

Note: The syntax of the WRITE statement and the syntax of the READ statement are nearly identical. Differences in the syntax are discussed separately under each statement. See the READ Statement earlier in this section for a more detailed breakdown of those syntactic elements of the WRITE statement that are not discussed here.

<write statement>

── WRITE ── ( ─┬─<write file part>─┬─────────────────────────┬─ ) ─────►
               │                   └─<format and list part>──┤
               └─<core-to-core part>──<format and list part>─┘
►─┬───────────────────────────────────┬────────────────────────────────┤
  └─<action labels or finished event>─┘

<write file part>

──┬─<file part>───────────────────────────────────────────────┬────────┤
  └─<task designator>── . ──<file-valued task attribute name>─┘

The action of the WRITE statement depends on the form of the <write file part> element or <core-to-core part> element and on the form of the <format and list part> element.

The write file part or core-to-core part indicates where the data is to be written.

The WRITE statement can be used as a Boolean function. You cannot use a WRITE statement inside another file I/O statement. When the write operation fails, the value TRUE is returned. When the write operation succeeds, the value FALSE is returned. Specifically, the WRITE statement returns a value identical to that returned by the file attribute STATE. For more information, refer to the discussion of the STATE attribute in the File Attributes Programming Reference Manual.

For BNA Host Services, error results for WRITE statements are reported one WRITE statement after the WRITE statement that reuses the buffer that originally had the error. That is, the error is reported one buffer later than normal. Normally, error results are reported exactly at the WRITE statement that reuses the buffer having the error.

WRITE statements that do not contain format designators or editing specifications provide a faster output operation than those that specify that data is to be edited.