SCAN

From Lianjapedia
Jump to: navigation, search

Purpose

Scans over records in a table and executes a command block for each selected record.

Syntax

SCAN

[IN <workarea>|<alias>]

[<scope>]

[FOR <condition>]

[WHILE <condition>]

[EXIT]

[LOOP]

ENDSCAN

See Also

CONTINUE, DO WHILE, EXIT, IF, LOCATE, LOOP

Description

The SCAN...ENDSCAN command executes a command block repeatedly FOR a specified selection of records WHILE an optionally specified condition is true, or until an EXIT is encountered. The optional LOOP keyword forces control to the beginning of the SCAN.

The SCAN...ENDSCAN command can be used to reduce the programming involved in a LOCATE...DO WHILE...CONTINUE construct.

IN <workarea>|<alias>

If the workarea number, letter or alias name is specified, the SCAN is carried out in that workarea. Note, the IN clause must be the first clause. From v6.0.

<scope>

The default SCOPE is all records unless a FOR or WHILE condition is specified.

FOR <condition>

If the FOR clause is specified, then only those records which satisfy the <condition> are deleted. The default SCOPE is ALL.

WHILE <condition>

The WHILE clause can be used to restrict the number of records checked against a particular <condition>, therefore optimizing the scan. The default SCOPE is REST.

EXIT

The looping will continue until either ENDSCAN is reached or an EXIT command is encountered.

LOOP

If a LOOP command is encountered, then control returns to the start of the loop.

Example

use customers
seek "HMT"
scan rest while code = "HMT"
    echo "name=" + name + "address=" + address
endscan