# matreadu statement

The matreadu form of the matread statement tests if an item is already locked and locks the item
if it is not. The item lock set by matreadu prevents
the item from being read using the matreadu statement
or updated by other processes while the lock is set.

## Syntax

```

 matreadu array.var from {file.var,} ID.exp{locked statement.block}
 {then|else statement.block}
```

## Description

Warning: Using a matreadu from a program that is called
 from dictionary item is not recommended.

This statement can optionally be written matread or read.
 If mat is omitted, a matrix read can be determined by the definition
 of the variable, *array.var*. If no dim statement
 appears, it is automatically treated as a dynamic array.

 The locked clause occurs before the then and/or
 else clauses and specifies the statements to execute if the item
 is locked when the read is attempted. The locked clause can be used
 in conjunction with a then or else clause, but not
 both.

- If the matreadu form is specified and no locked clause is present, the program pauses (and beeps continuously) at the locked item until it is available.

- If a locked clause is specified, the statements in the locked clause are executed if the item is already locked by another process or the current process at a different level.

- system(0) contains the port number that has the item locked. For backwards compatibility, system(0) in the locked clause also returns the port number that has the item locked.

The item lock
is only released by a release, delete, or matwrite statement.

Note:

- If the number of attributes read in the item is less than the dimensioned array size, the trailing array elements are assigned a null string value.

- If more attributes are present in the item read than elements in the previously dimensioned array, then the last array element contains the extra attributes, with each attribute delimited by an attribute mark. Everything functions properly while the last array element remains unreferenced.

- Repeated executions of matreadu statements does not implicitly unlock item locks. In this case, using the release statement is recommended.

## Example(s)

```

 dim customer.item(20)
 matreadu customer.item from cust.fv,item-ID locked
 crt item-ID:’ is locked by port ’:system(0)
 end then
 crt ’got it’
 end else
 crt ’not on file’
 end
```

## See also

- [dimension statement](https://d3codex.com/pickbasic-flashbasic/dimension-statement/)
- [mat statement](https://d3codex.com/pickbasic-flashbasic/mat-statement/)
- [matbuild statement](https://d3codex.com/pickbasic-flashbasic/matbuild-statement/)
- [matparse statement](https://d3codex.com/pickbasic-flashbasic/matparse-statement/)
- [matread statement](https://d3codex.com/pickbasic-flashbasic/matread-statement/)
- [matwrite statement](https://d3codex.com/pickbasic-flashbasic/matwrite-statement/)
- [matwriteu statement](https://d3codex.com/pickbasic-flashbasic/matwriteu-statement/)

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