# root statement

The root statement provides an interface
to the B-tree indexes for subsequent references with the key statement.

## Syntax

```
root file.ref, a.code to root.var{then|else statement.block}
```

## Parameter(s)

| file.ref | File reference as a string expression. |
| --- | --- |
| a.code | String expression containing the a (algebraic) processing code located in the file-defining item that identifies the index to use. The index must have previously been created with create-index. |
| root.var | Used by subsequent key statements. |

## Description

This is similar to the open statement, in that a root statement
is an open of an index, and must precede a key statement
just as an open statement must precede a read statement. Any number of indexes can be opened at
once, provided that each has a unique root variable.

Numeric
indexes will open regardless of the current case sensitivity settings.
For non-numeric indexes, the case sensitivity of the index must match
the current case setting, which can be set at TCL with the case command, and over-ridden in a BASIC program with the casing statement.

The optional then clause is executed if the specified index is found. The else clause is executed if it is not found.

The key statement, in conjunction with the initializing root statement, provides the ability to sequentially cruise
on any defined index for a particular file.

The root statement must precede the key statement.

Note: The root statement leaves the parent file
of an index in an open state (that is, file in use). A close statement using the *root.var* variable must be
executed to close the parent file if a delete-file command is to be issued prior to exiting the program.

## Example(s)

```
fname = "customer"
root fname,"a1" to cust.root else
 print "file is missing"
 goto 999
end
```

## See also

- [a (algebraic) processing code](https://d3codex.com/processingcodes/a-algebraic-processing-code/)
- [B-tree](https://d3codex.com/definitions/b-tree/)
- [clear-index command](https://d3codex.com/tcl/clear-index-command/)
- [create-index command](https://d3codex.com/tcl/create-index-command/)
- [File reference](https://d3codex.com/definitions/file-reference/)
- [key statement](https://d3codex.com/pickbasic-flashbasic/key-statement/)
- [statement blocks](https://d3codex.com/pickbasic-flashbasic/statement-blocks/)
- [Statements and functions](https://d3codex.com/pickbasic-flashbasic/statements-and-functions/)
- [then/else statement blocks](https://d3codex.com/pickbasic-flashbasic/then-else-statement-blocks/)

---
Source: https://d3codex.com/pickbasic-flashbasic/root-statement/ - part of the D3Codex reference.
