readnext statement

The readnext statement retrieves the next item-ID from an active list and assigns it to a specified variable.

Syntax

 readnext ID.var{,value.count}{from select.var} [then|else statement.block]

Parameter(s)

value.count Indicates the position of the multivalue within an attribute.

This is a by-product of an exploded sort, executed prior to the execution of the program. This allows multivalues to be retrieved in exploded sort sequence. If the list is not exploded, the value count value is always 1.

select.var   If select.var is not specified, the default primary or secondary select variable is used. The secondary specification uses the active secondary list.

Description

A list must be active before the readnext statement occurs. The list can be generated within the program or the list can be passed into the program from an external process, such as TCL or a Proc, that invokes a list-producing command immediately before running this program.

The else condition is executed when there are no more items in the list.

Tip: Another select clears the primary and secondary lists.

The select and readnext statements both consume an external list if one is available. As a result, system(11) always returns 0 after one of these commands.

For example:

 execute "select bp sampling 5"
 print system(11)
 select
 print system(11)

This prints 5, then 0. The external list is consumed by a BASIC variable, and is then only available from FlashBASIC or BASIC.

When using an external list, it is necessary to readnext all items in that list until the readnext statement actually fails. At this point, the list is reset and it searches again for a new external list.

Example(s)

Example 1

The readnext statement retrieves the next itemID from an active list, but does not implicitly address the file. The file to be accessed must be opened before an attempt to use the itemID in a read statement can be made.

 open ’customer’ to customer.file else stop 201,’customer’
 execute ’sselect customer with balance.due by name’
 loop
    readnext itemID else stop
    read item from customer.file,itemID then
       print ’the name is ’:item<1>
    end
 repeat

Example 2

This example displays each itemID.

 execute "select md (s"
 loop readnext ID else stop
 print ID
 repeat