WRITET Statement

The WRITET statement writes the given text as the next record of the attached magnetic tape or floppy disk.

Format

WRITET expr [RETURNING var]

[THEN

   statements

END] [ELSE

   statements

END]

Parameter(s)

expr

An expression evaluating to the text to be written on the tape or floppy disk.

RETURNING var

If a tape or floppy disk error occurs while using the RETURNING clause, the tape or floppy disk error is assigned to the returning variable and program control continues through the ELSE clause.

THEN statements

Executes statements if tape or floppy disk is successfully written.

ELSE statements

Executes statements if tape or floppy disk cannot be written.

Description

The WRITET statement writes a record onto the current position on an attached magnetic tape or floppy disk. If the length of the value of {expr} is greater than the blocking factor of the attached device, then either:

A tape or floppy disk might not be writable because the tape or floppy disk has not been attached or because the record to be written evaluated to the null string. To determine why a tape or floppy disk could not be written, the SYSTEM function is often used in the ELSE portion of a WRITET statement. See SYSTEM Function for more information.

Example

In this application, each file item of a file is written to tape. After SELECTing the item-IDs of the file, the READNEXT statement is used to read each item-ID and each item is then read and written to tape. If the item is not written, the SYSTEM function is used to determine the error message, and an appropriate error message is printed.

SELECT TEMPFILE

END.OF.LIST = 0

LOOP    

   READNEXT ID ELSE  

      END.OF.LIST = 1  

   END   

UNTIL END.OF.LIST DO   

   READ CURR.REC FROM TEMPFILE,ID THEN

      WRITET CURR.REC ELSE    

         ERROR.CODE = SYSTEM(0)    

         BEGIN CASE  

         CASE ERROR.CODE = 1    

            PRINT "ERROR!  TAPE NOT ATTACHED"

            GOSUB EXIT   

         CASE ERROR.CODE = 2    

            PRINT "ERROR!  EOF READ FROM TAPE"

            GOSUB EXIT   

         CASE ERROR.CODE = 3    

            PRINT ID:" : ITEM IS EMPTY"  

         END CASE    

      END   

   END ELSE    

      PRINT "ERROR IN READING RECORD ":ID

      SLEEP 1

END   

REPEAT

See Also

Statement and Function Reference