SELECT, SELECTE Statements

SELECT builds a list of item-ids from a file, an index or a dynamic array. The resulting list is assigned either to a variable or to the active select list, and can be read sequentially with the READNEXT and, in some cases, READPREV statements.

The SELECTE statement is similar, but copies the active select list to a variable. If SELECTE is used, it must be executed before any other SELECT or READNEXT statements.

Syntax

SELECT {file-var} {TO [list-number || fileSelectVar]} {SETTING setting-var}

SELECT file-var,index-name TO [list-number || indexSelectVar] {SETTING setting-var}

SELECT dyn-array {TO [list-number || listVar]} {SETTING setting-var}

SELECTE {TO listVar}

Syntax elements

file-var The name of a variable containing a file reference (assigned via an OPEN statement). If file-var is not specified, the internal default file variable is used; that is, the file used is that most recently opened without a file variable.

list-number Must be 0. Specifies that the generated list should be assigned to the active select list.

fileSelectVar The name of a variable to which the list will be assigned.

The READPREV statement cannot be used with a list created from a file.

index-name The name of an index associated with the file specified in file-var.

indexSelectVar The name of a variable that will be returned containing a pointer to the index.

dyn-array The name of a dynamic array from which the list is created. Each attribute, value and subvalue in the array becomes an item in the list.

listVar The name of a variable to which the list will be assigned.

The READPREV statement cannot be used with a list created from a dynamic array. However, such a list can be used in the PASSLIST clause of PERFORM.

setting-var The name of a variable to which, if file-var is used, a code is assigned if a file I/O error occurs (see File I/O and IPC Error Codes). In all other cases it is assigned the number of items in the list created.

Comments

A list created from a file selects item-ids one group at a time as they are read by the READNEXT statement, rather than all at once as in English. Therefore, if you change an item's id, it could be selected again. For this reason, if you are adding items or changing item-ids — or other users could be — you should perform an English SELECT command prior to executing the program and use SELECTE (or PERFORM a SELECT from within the DataBasic program).

Any file, index or array can be selected any number of times and used independently; you can have several select pointers or variables in use at the same time.

If the TO clause is omitted the file, dynamic array or active list is selected to the internal default list variable. The TO clause must be included when selecting from an index.

The active select list would normally be generated externally by a list-generating command executed at TCL.

Examples

   OPEN 'BP' ELSE STOP
SELECT
10 READNEXT ID ELSE STOP
PRINT ID
GOTO 10

Selects BP as the default file variable and assigns each item-id in BP (in hash order) to ID. Loops back to statement 10 until all the item-ids found in the file BP are printed.

OPEN 'CUST' TO CUSTF ELSE STOP 201
.
.
.
SELECT CUSTF TO CUSTLIST
READNEXT ID FROM CUSTLIST THEN FOUND = 1 ELSE FOUND = 0

Selects the CUST file and assigns it to CUSTLIST. Assigns the first item-id from the CUST file (in hash order) to ID.

SELECTE TO EXTERNAL
READNEXT ID FROM EXTERNAL ELSE
PRINT 'NO ':ID; GO 10
END

Assigns the external select list to EXTERNAL. Assigns the first item-id from external to ID.

X = 'B':AM:'C':AM:'D':AM:'E1':VM:'E2':VM:'E3'
ATTR4 = X<4>
SELECT ATTR4 TO VMLIST
READNEXT ID FROM VMLIST THEN
READ ITEM FROM CUSTF,ID ELSE ITEM=''
END ELSE ITEM=''

Assigns the list 'E1', 'E2', 'E3' to VMLIST. Assigns the string 'E1' to ID.

See also

SELECT statement (MultiValue Compatibility).