Top  Previous  Next


The SELECT statement creates a select list containing all record keys from a file.





SELECT var {TO} {ON ERROR statement(s)}

SELECTN var {TO} {ON ERROR statement(s)}

SELECTV var {TO list.var} {ON ERROR statement(s)}




varis the file variable associated with an open file or a field mark delimited dynamic array of items to form the list.


list.nois the select list number of the list to be created. If omitted, select list zero is used.


list.varis the select list variable to receive the list. Select list variables can be processed by the READNEXT statement as an alternative to using numbered select lists. If the TO clause is omitted, a default select list variable is used.


statement(s)are statement(s) to be executed if a fatal error occurs.



The SELECT and SELECTN statements construct a list of record keys in the file open as var and store this as an active select list replacing any previously active list. If there are no records in the file, an empty list is created.


|The SELECTV statement constructs the list in the same way but stores it in a select list variable which can be processed by a subsequent use of READNEXT. If the TO clause is omitted, the default select list (numbered list 0) is used.


For compatibility with other database products, the action of the SELECT statement can be changed to produce a select list variable in the same was as SELECTV. This is achieved by setting the SELECTV option of the $MODE compiler directive.


Also for compatibility with other products, use of the PICK.SELECT option of the $MODE compiler directive causes SELECTV (and SELECT when $MODE SELECTV is in effect) to behave such that, if the default select list (list 0) is active when the statement is executed, the default list is transferred into list.var, ignoring var completely. For example



would transfer the list generated by the executed SELECT into variable STOCK.LIST, ignoring FVAR. The SELECTE statement provides a neater way to do this.


See Select Lists for a discussion of how QMBasic optimises select performance.


It is important that a program that does not completely process a select list should clear the remainder of the list because, while the list is active, split and merge operations are suspended on the data file. Thus, leaving a list active may cause the file performance to degrade if updates are made. Note that the file will automatically reconfigure for optimum performance once the select operation has terminated. When using numbered select lists, the partially processed list can be cleared using CLEARSELECT. For select list variables generated with SELECTV, the program should overwrite the list variable with, for example, a null string.


The @SELECTED variable is set to the number of records selected for a directory file or the number of records in the first non-empty group for a dynamic file.


The optional ON ERROR clause is executed in the event of a fatal error. This covers such situations as disk hardware errors and faults in the internal structure of the file. The STATUS() function will return a value relating to the cause of the error. If no ON ERROR clause is present, a fatal error will result in an abort.


Except where the ON ERROR clause is taken, the STATUS() function will return zero.



Use of a Dynamic Array instead of a File Variable


For compatibility with Pick style environments, QM also supports a variation on these statements where the var is a dynamic array in which each field becomes an entry in the target select list.







This statement creates a list of the records on the file with file variable STAFF and saves it as active select list 7.