READNEXT Statement

The READNEXT statement reads the next sequential value in a select-list.

Format

READNEXT var1 [, var2] [FROM select-var] [THEN

   statements1] [ELSE statements2]

Parameter(s)

var1

Reads the next value in the select-list, and assign it to var1.

var2

Assigns the value mark count to var2. This option is applicable only to external select-lists constructed through the TCL SSELECT command.

FROM select-var

Reads values from the named select-list variable select-var. If select-var is not specified, the default select-list variable is used.

THEN statements1

Executes statements1 unless at the end of the list.

ELSE statements2

Executes statements2 if at the end of the list.

Description

The READNEXT statement assigns the next value from an active select-list to the specified variable. If it is a select-list of item-IDs, the variable may then be used in a READ statement to read the file item. (The SELECT statement might also create a select-list of attributes from a dynamic array.)

The select-list can be either an internal select-list or an external select-list. See SELECT Statement for more information on creating select-lists. If a value is successfully read from the select-list, the variable var is assigned to the value, and the THEN statements are executed. When the end of the select-list is reached, var is set to the null string and the ELSE statements are executed.

Example

This application creates an alphabetical list of each item-ID in the file CUSTOMERS. The file is selected to the select variable LIST, and each item-ID is read from LIST with READNEXT. The END.OF.LIST variable is set to true when the READNEXT statement fails to read any more item-IDs, and is used to complete the loop. The actual alphabetizing is accomplished with the LOCATE and INS statements.

EQUATE TRUE TO 1, FALSE TO 0

OPEN "CUSTOMERS" TO CUSTFILE ELSE

   ABORT 201, "CUSTOMERS"

END

SELECT CUSTFILE TO LIST

ALPH.LIST = ""

END.OF.LIST = FALSE

LOOP

   READNEXT ID FROM LIST ELSE

      END.OF.LIST = TRUE

   END

UNTIL END.OF.LIST DO

   LOCATE ID IN ALPH.LIST BY "AL" SETTING POSITION

THEN

      PRINT ID : " DUPLICATE ENTRY!  POSSIBLE FILE CORRUPTION"

      ABORT

   END ELSE

      INS ID BEFORE ALPH.LIST<POSITION>

   END

REPEAT

See Also

Statement and Function Reference