Write

Write allows you to insert a new line in a database table.

Syntax

 WriteWrite [CLASS]

Examples

 # Extract of a AINSERT "hand written" method on a class : let's create a header and linesTrbegin HEADER [HEAD], LINES [LINE]SetInstance [HEAD] with thisWrite [HEAD]If fstat=0For I=1 to maxtab(this.LINES)If this.LINES(I)<>NullSetInstance [LINE] with this.LINES(I)Write [LINE]Break (fstat<>0)EndifNext IEndifIf fstat=0CommitElseRollbackEndif

Description

Write allows you to insert a line in the database.

fstat indicates the result of the operation:

ValueDescription
0The write operation succeeded.
1The table is locked.
3An attempt to create a duplicate key value was done.

A Write instruction does not modify the current record. If the current record must be the written one, it is necessary to perform a read operation.

Comments

The behavior can be different depending on the database:

It is not possible to use an abbreviation associated with a join by Link to write a line.

The creation of a line must be done in a transaction.

The written line is locked until the transaction ends.

When several lines must be written on a given table, it is best to use the Writeb instruction that performs faster.

If the table is locked by Lock [ABBREV], the other users cannot insert lines and will get a fstat value equal to 1.

Associated errors

Error codeDescription
7Class does not exist (no table opened with the corresponding abbreviation).
27A write attempt was done on a [Link](../4gl/link.md) abbreviation.
44No more space to create lines.
65No more space to create lines.
75Database error.

See also

File, Readlock, Trbegin, Commit, Rollback, Update, Rewrite, Delete, RewriteByKey, DeleteByKey, Writeb, fstat.