CLEAR.DATA

CLEAR.DATA, CLEARDATA

Top  Previous  Next

 

The CLEAR.DATA command (synonym CLEARDATA) clears the data queue created by the DATA command or the QMBasic DATA statement.

 

 

Format

 

CLEAR.DATA

 

 

The data queue is cleared automatically on return to the command prompt. The CLEAR.DATA command allows the queue to be cleared within a paragraph, for example, when recovering from premature termination of a program that uses the data queue.

 

@SYSTEM.RETURN.CODE is not affected by this command.

 

 

Example

 

PA

RUN ARCHIVE.PREVIOUS.YEAR

DATA Y

SELECT ORDERS WITH DATE BEFORE "1 JAN <<@YEAR>>"

DELETE ORDERS

 

The above paragraph might be used to archive old order data at the start of a new business year and then delete the old records from the ORDERS file. The archive program asks the user if a report is to be printed and the DATA statement is used to provide the answer to this question from within the paragraph. Because it is using a select list, the DELETE command will prompt the user for confirmation before deleting the selected records.

 

If the archive program fails before asking whether a report is required, the "Y" in the data queue will not be read by this program and will still be in the queue when the DELETE command is executed. It will therefore be used erroneously to answer the delete confirmation prompt.

 

This situation can be avoided by inserting a CLEAR.DATA statement before the SELECT. In general, it is good practice to insert a CLEAR.DATA after any command that uses DATA and could terminate without reading the queued data. This action is not automatic because the data queue is frequently used to pass data from one program to another.

 

 

See also:

CLEAR.INPUT, CLEARDATA QMBasic statement