sign in
 
   
 
 
 
   
  COBOL TUTORIAL FOR BCA STUDENTS OF M G UNIVERSITY  
  UNIT 4: PROCEDURE DIVISION . . .  
   
     
 

WRITE VERB

 
 

The WRITE verb releases a record onto an output file. The syntax of the WRITE statement can be different depending on the output device and medium used. The verb as described here can be used only to print results on a continuous stationery through a line printer.

The form of the WRITE statement in such a case is:

 
   
 

The first point to be noted is that in the case of the READ statement the file name is to be specified, whereas in the case of the WRITE statement it is required to mention the record name an not the file name. The ADVANCING phrase is used to control the vertical positioning of each record at the time of printing on the stationery placed on the printer. When the BEFORE phrase is used, the record is printed before the stationary is advanced, whereas the AFTER phrase may be used when the intention is to advance the stationary first and then to print the record. If integer-1 or identifier-1 is mentioned, the stationary is advanced by the number of lines equal to the value of integers-1 or to the current value of identifier-1.

If the mnemonic-name is specified, the printer will be advanced to the carriage control channel declared for the mnemonic-name in the SPECIAL-NAMES paragraph. This option is provided so that the hardware names which may be peculiar to a particular computer need not appear in the PROCEDURE DIVISION.

If the FROM option is used, the operation is identical to that of MOVE identifier-1 TO record-name followed by a WRITE record-name without the FROM clause. It is illegal to use the same storage area for both record-name and identifier-1.

It should be noted that after WRITE is executed the record is no longer available.

Example:


 
 

WRITE TRANS-RECORD AFTER ADVANCING 3 LINES.

 
 

This WRITE statement indicated that TRANS-RECORD is a record name of a file that has been assigned to PRINTER. The current position of the stationery will be advanced by 3 lines, i.e., there will be 2 blank lines and the present record will be written on the third line.

 
  WRITE TRANS-RECORD BEFORE ADVANCING 3 LINES.  
 

The record will be written first and then the page will be advanced by 3 lines.