Sequential Files

The ADVANCING and END-OF-PAGE phrases control the vertical positioning of each line on a printed page. If the printed page is held on an intermediate device (a disk, for example), the format may appear different than the expected output when it is edited or browsed.
Note: The ADVANCING PAGE and END-OF-PAGE phrases must not both be specified in a single WRITE statement.

When an attempt is made to write beyond the externally defined boundaries of the file, the processing of the WRITE statement is unsuccessful and an EXCEPTION/ERROR condition exists. The contents of record-name are unaffected. Processing then follows the rules for error handling as described under USE Statement Programming Notes.

For sequential files on device type TAPEFILE or DISKETTE, when end-of-volume is recognized for a multivolume OUTPUT file, the WRITE statement processes the following operations in order:
  1. The standard ending volume label procedure is run.
  2. A volume switch occurs.
  3. The standard beginning volume label procedure is run.

No indication that an end-of-volume has occurred is returned to the program.

Read syntax diagramSkip visual syntax diagram
WRITE Statement - Format 1 - Sequential Files

>>-WRITE--record-name-1--+--------------------+----------------->
                         '-FROM--identifier-1-'   

>--+------------------------------------------------------------+-->
   '-+-BEFORE-+--+-----------+--+-+-identifier-2-+--+-------+-+-'   
     '-AFTER--'  '-ADVANCING-'  | '-integer-1----'  +-LINE--+ |     
                                |                   '-LINES-' |     
                                +-mnemonic-name-1-------------+     
                                '-PAGE------------------------'     

>--+------------------------------------+----------------------->
   |          (1)                       |   
   '-NULL-MAP------+----+--identifier-9-'   
                   '-IS-'                   

>--+-------------------------------------------------+---------->
   '-+----+--+-END-OF-PAGE-+--imperative-statement-1-'   
     '-AT-'  '-EOP---------'                             

>--+------------------------------------------------------+----->
   '-NOT--+----+--+-END-OF-PAGE-+--imperative-statement-2-'   
          '-AT-'  '-EOP---------'                             

>--+-----------+-----------------------------------------------><
   '-END-WRITE-'   

Notes:
  1. IBM® Extension.
record-name-1
Must be defined in a Data Division FD entry. Record-name-1 may be qualified. It must not be associated with a sort or merge file.

You must ensure that the size of an OCCURS DEPENDING ON (ODO) array has been set to a valid numeric value before doing a WRITE of a record containing the ODO array.

IBM Extension

IBM Extension Record-name-1 can be a floating-point data item. End of IBM Extension

End of IBM Extension
IBM Extension

IBM Extension Record-name-1 can define a DBCS data item. Identifier-1 must be a DBCS data-item if record-name-1 is a DBCS data item. End of IBM Extension

End of IBM Extension
FROM
When FROM is specified, the result is the same as:
MOVE identifier-1 TO record-name-1
WRITE record-name-1

The move is performed according to the rules of the MOVE statement, without the CORRESPONDING phrase.

After the WRITE statement is executed, the information is still available in identifier-1, even though it may not be in record-name-1. (See INTO/FROM Identifier Phrase.)

identifier-1
Must be an alphanumeric or numeric-edited data item. Data is transferred from this field to the receiving fields.

Identifier-1 can be the name of an alphanumeric or DBCS function identifier.

IBM Extension

IBM Extension Identifier-1 can be a floating-point or date-time data item. End of IBM Extension

End of IBM Extension
identifier-2
Must be an integer data item.

The maximum record size for the file is established at the time the file is created, and cannot subsequently be changed.

Record-name-1 and identifier-1 must not refer to the same storage area.

After the WRITE statement is executed, the record is no longer available in record-name-1, unless:
  • The associated file is named in a SAME RECORD AREA clause (in which case, the record is also available as a record of the other files named in the SAME RECORD AREA clause), or
  • The WRITE statement is unsuccessful because of a boundary violation.

In either of these two cases, the record is still available in record-name-1.

The file position indicator is not affected by execution of the WRITE statement.

The number of character positions required to store the record in a file may or may not be the same as the number of character positions defined by the logical description of that record in the COBOL program. (See PICTURE Clause Editing and USAGE Clause.)

If the FILE STATUS clause is specified in the File-Control entry, the associated status key is updated when the WRITE statement is executed, whether or not execution is successful.

The WRITE statement cannot be executed for a sequential file opened in I-O mode.

Related Information: