SELECT Statement

The SELECT statement selects all items from a file, or the first value of all attributes in a dynamic array variable. The data selected is placed in an internal select-list, to be accessed by a subsequent READNEXT statement.

Format

SELECT var | filevar [TO select-var]

Parameter(s)

var

Dynamic array to be selected. The select-list contains only the first value of each multivalued attribute in the variable.

filevar

File variable, previously assigned by an OPEN statement. The select-list contains all item-IDs in the system file opened to filevar.

select-var

Assigns the name select-var to the select-list. If select-var is not specified, the default select-list variable is used.

Description

The SELECT statement forms an internal list of all item-IDs from the specified file. The file must have been opened by an OPEN statement before it may be selected. The list created by the SELECT statement can then be accessed by a subsequent READNEXT statement.

Alternatively, the SELECT statement may be used to form a select-list of the first value of each attribute in a dynamic array.

For a select-list of item-IDs, the SELECT statement may be used to create an internal select-list, or the TCL select-list generators (SELECT, SSELECT, QSELECT, etc.) may be called with the EXECUTE statement to create an external select-list. The SELECT statement performs the same function as the TCL SELECT command without any selection expressions, and in that respect is less flexible than using the EXECUTE statement to access TCL; however, external select-lists must use the default select-list variable.

Example

In the following application we create an alphabetical list of each item-ID in the file CUSTOMERS. The file is selected to the select variable LIST with the SELECT statement. Each item is then read from LIST with the READNEXT statement. 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