ON NONEXT

How to:

The ON NONEXT command defines the action to take if the prior NEXT command fails (if it is unable to retrieve all of the specified records). There can be intervening commands between the NEXT and ON NONEXT commands, and they can be in separate functions.

For example, when the following NEXT command is executed

FOR 10 NEXT Emp_ID INTO Stkemp;

only eight employees are left in the data source, so only eight records are retrieved, raising the ON NONEXT condition.

It is recommended that you query the FocFetch system variable in place of issuing the ON NONEXT command. FocFetch accomplishes the same thing more efficiently. For more information, see FocFetch.

Syntax: How to Use the ON NONEXT Command

The syntax of the ON NONEXT command is

ON NONEXT command

where:

command

Is the action that is taken when NEXT fails.

You can specify any Maintain Data command except for CASE, DECLARE, DESCRIBE, END, MAINTAIN, MODULE, and another ON command.

Example: Using ON NONEXT

The first example displays a message stating that the NEXT was unsuccessful:

NEXT Emp_ID;
ON NONEXT TYPE "There are no more employees";

If all of the employees have been processed, the program is exited:

NEXT Emp_ID;
ON NONEXT GOTO EXIT;

The following example shows several commands being executed after a NEXT fails:

ON NONEXT BEGIN
   TYPE "There are no more employees in the data source";
   PERFORM Wrapup;
   ENDBEGIN