# transaction statement

The transaction statement enables or
disables participation in a transaction.

## Syntax

```
transaction [on|off|exp]
```

## Parameter(s)

| on | Enables participation in a transaction. |
| --- | --- |
| off | Disables participation in a transaction. |
| exp | Transaction is turned on if the expression evaluates to nonzero (true) and turned off if it evaluates to 0 (false). |

## Description

CAUTION: This function
should not be used directly in the context of a user-written FlashBASIC
or BASIC program as it allows violating the theoretical structure
of a transaction.

This functionality is intended for languages
built on top of FlashBASIC or BASIC (like some SQL engines or 4GLs)
that need to use temporary files for internal reasons without affecting
a user-level transaction.

The term `on` or `off` is required if an expression is used with this function.

## Example(s)

```
transaction start
transaction cache off
transaction off else msg="8 off"; goto fail
write "1" on "1"
read xx from "1" else msg="8 read"; goto fail
x=1
transaction onoff x else msg="8 onoff"; goto fail
write 1 on 2
read xx from 2 then msg="8 read2"; goto fail
transaction commit
read xx from 2 else msg="8 read3"; goto fail
delete 1
delete 2
```

## See also

- [begin work statement](https://d3codex.com/pickbasic-flashbasic/begin-work-statement/)
- [_CP_trans](https://d3codex.com/cfunctions/cp-trans/)

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