READNEXTTUPLE
Syntax
READNEXTTUPLE dyn.array.var FROM file.name.expr {THEN statements [END] | ELSE statements [END]}
Description
The UniBasic READNEXTTUPLE command assigns the next entire record to a variable.
The record ID is obtained from an active select list that was created by a UniData
SQL SELECT statement during the current work session.
READNEXTTUPLE creates a dynamic array delimited by attribute marks (@AM). The
attribute marks are entered by the UniData SQL SELECT statement.
Tip: Do not use the UniData SQL UNNEST command in the SQL statement that creates
the ID list. UniData might not return the entire record with attribute marks, value
marks, and/or subvalue marks if you use UNNEST.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
dyn.array.var Specifies the dynamic array to contain the record.
FROM file.name.expr Specifies the file from which to read the next record
file.name.expr, must have been created during the current
session by an EXECUTESQL statement with a TO clause in
the UniBasic program. A UniData SQL statement executed
at the ECL prompt before the program was run.
THEN statements END THEN executes if the read is successful. END is required to
terminate multiline THEN statements.
ELSE statements END ELSE executes if the read is not successful, the record does
not exist, or the last record has been read. END is required
to terminate multiline ELSE statements.
READNEXTTUPLE Parameters
Example
In the following example, the program segment executes a UniData SQL statement and stores
the output in an internal result file called SQL_INPUT. The READNEXTTUPLE statement then
reads the records stored in SQL_INPUT until the last record item is read. The process
converts the attribute marks to spaces and prints each record read.
OUT.COMMAND = "SELECT NAME, ADDRESS, CITY"
OUT.COMMAND := " FROM CLIENTS TO SQL_INPUT; "
EXECUTESQL OUT.COMMAND
DONE = 0
BPIOCP
LOOP
READNEXTTUPLE CLIENT.REC FROM "SQL_INPUT" ELSE
DONE = 1
END
UNTIL DONE DO
CONVERT @AM TO " " IN CLIENT.REC
CONVERT @VM TO","IN CLIENT.REC
PRINT CLIENT.REC
REPEAT