SELECTINDEX()

Top  Previous  Next

 

The SELECTINDEX statement creates a select list from an  alternate key index entry.

 

 

Format

 

SELECTINDEX index.name {, value} FROM file.var {TO list.no}

 

where

 

index.nameis the name of the alternate key index to be processed.

 

valueis the value to be located in the index.

 

file.varis the file variable associated with an open file.

 

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

 

 

If the value is omitted, the SELECTINDEX statement constructs a select list containing all the values of the index identified by index.name. If the value is included, the SELECTINDEX statement constructs a select list containing keys of records for which the index indentifed by index.name has the given value.

 

Thus, in a file of orders with an index on the customer number field, the first form would return a list of customers referenced by the orders file and the second form would return a list of orders for a specific customer.

 

The STATUS() function returns zero if the SELECTINDEX is successful, non-zero if it fails because the index does not exist. Selecting records for a value that is not present in the index will return an empty list.

 

The @SELECTED variable is set to the number of entries in the returned list.

 

The SELECTINDEX operation leaves the internal index pointer used by the SELECTLEFT and SELECTRIGHT statements positioned at the item that has been located or, if not found, at the position where such an item would go.

 

Use of this statement inside a transaction will not reflect any uncommitted updates to the file.

 

 

Examples

 

SELECTINDEX 'CUST.NO' FROM ORDERS.FILE TO 7

LOOP

  READNEXT CUST.NO FROM 7 ELSE EXIT

  CRT CUST.NO

  SELECTINDEX 'CUST.NO', CUST.NO FROM ORDERS.FILE

  LOOP

     READNEXT ORDER.NO ELSE EXIT

     CRT ORDER.NO
  REPEAT

REPEAT

 

This program builds a select list of all the customers referenced by the orders file as list 7. The inner loop then constructs a list of the order numbers for each customer in turn.

 

 

See also:

SETLEFT, SETRIGHT, SELECTLEFT, SELECTRIGHT