READNEXT Statement

Reads the next item-id from a select list, list variable or index.

Syntax

READNEXT itemid-var{,vmc-var{,svmc-var}}{FROM [listNumber|| fileSelectVar || listVar]}{SETTING setting-var}{[THEN statement(s) | ELSE statement(s)]}

READNEXT itemid-var{,vmc-var{,svmc-var}} FROM [list-number || indexSelectVar]{RETURNING key-var}{SETTING setting-var}{[THEN statement(s) | ELSE statement(s)]}

Syntax Elements

itemid-var is the name of the variable to which the string value of each next item-id is assigned.

vmc-var is the name of a variable that is assigned the value count indicating the position of the multivalue within an attribute when an exploding sort has been processed using a BY-EXP or BY-EXP-DSND clause during the creation of the list or index.

svmc-var is the name of a variable that is assigned the value count indicating the position of the subvalue within an attribute when an exploding sort has been processed using a BY-EXP-SUB or BY-EXP-SUB-DSND clause during the creation of the list or index.

listNumber Must be 0. Specifies the active select list.

fileSelectVar is the name of the variable containing a list from which the item-id is read.

listVar is the name of a list variable from which the item-id is read.

indexSelectVar is the name of the variable assigned to the index with a SELECT statement.

key-var is the name of a variable that receives the key value associated with the item-id in itemid-var. The key value comprises the values, within the associated item, of the attributes specified as sort criteria when the index was defined, separated by attribute marks.

If a list number is specified in the FROM clause and a RETURNING clause is included, key-var will return null.

setting-var is the name of the variable to which the file I/O error code or zero is assigned, if the SETTING clause is used. The file I/O error codes are described in File I/O and IPC Error Codes.

statement(s) is one or more DataBasic statements:

Comments

If the FROM clause is omitted, the item-id is read from the last SELECT, SELECTE or GETLIST statement executed without a TO clause. If none of these statements have been executed, the item-id comes from the active select list (normally generated by a list generating command executed at TCL).

Operation

The variable vmc-var is assigned the value count indicating the position of the multivalue within the attribute specified after the BY-EXP or BY-EXP-DSND connective. This value can be used in a dynamic array extraction after the item has been read (via a READ statement) to obtain multivalues in exploded sort order.

Note

READNEXT retrieves only item-ids. To retrieve other values from an item, a READ statement that uses the returned item-id must be executed following the READNEXT.

See also the topic Using Indexes.

Examples

READNEXT ID ELSE STOP

Assigns value of next item-id from the default select variable to ID. If the list is exhausted, or if no SELECT, SELECTE or GET-LIST statement has been executed, and there is no external select list, the program terminates.

READNEXT VAR1 ELSE PRINT "CANNOT READ"; GO 10

Reads next item-id and assigns its string value to VAR1. If the list of item-ids has been exhausted, or if no selections have been performed (either in the program, at TCL or in a Proc), the message CANNOT READ  is displayed and control transfers to statement 10.

FOR X=1 TO 10
READNEXT B(X) ELSE STOP
NEXT X

Reads the next ten item-ids and assigns the values to matrix elements B(1) through B(10).

FOR I=1 TO 999
READNEXT ITEM.ID, VALUE ELSE STOP
READ ITEM FROM INV,ITEM.ID ELSE NULL
PRINT ITEM<I, VALUE>
NEXT I

Reads and prints multivalues in exploded sort order.

LOOP WHILE READNEXT ID FROM SV SETTING ERROR DO
PRINT ID
REPEAT

Prints all the item-ids in the list SV. Any file error code is assigned to variable ERROR. The program terminates when the list is exhausted.

See Also

SELECT statement, READPREV statement, WHILE statement, READNEXT Statement (MultiValue Compatibility).