The WRITE statement passes specified fields to an extract file for further processing.

WRITE signifies the end of a processing step unless it is issued as part of an IF clause. For details, see the section END STEP Statement on page 200. The primary purpose of the WRITE statement is to create an extract file for a sort. This is why it is written to the file associated with a FILEDEF for SORTIN. A WRITE statement must be followed by a SORT statement before another WRITE statement is permitted.

A WRITE statement sends a description of the output record format to the diagnostic output.

WRITE fieldname ... [TO ddname]
  • fieldname
    Specifies the name of a field value to write to the output file. You may specify up to 60 fields in each WRITE statement.
  • ddname
    Specified a name (defined by a FILEDEF command) where the output records are written. If you do not issue a FILEDEF command for ddname, the output is written to a file named FILE ddname A. The default file name is FILE SORTIN A.

Example

This statement writes fields A, B, and C to WRITEFILE:

WRITE FIELDA FIELDB FIELDC TO WRITEFILE.