table.BATCH_BEGIN Function

Syntax

V Batch_Begin()

Description

Lock database file for batched changes.

Discussion

The <TBL>.BATCH_BEGIN() method is placed at the start of a special batch operation for a particular table to improve the speed of the operation. All Change and Enter operations in the specified table pointer (<TBL>) that occur between the <TBL>.BATCH_BEGIN()and its corresponding <TBL>.BATCH_END(), are optimized. Alpha Anywhere optimizes data entry operations by either opening the table exclusively or by preventing write access to the file by other users.

Example 

This script updates the Product table, both without and with the batch optimization.

dim tbl as P
dim t1 as N
dim t2 as N
tbl = table.open("c:\A5\a_sports\product.dbf")
t1 = toseconds(time())
    tbl.fetch_first()
    while .NOT. tbl.fetch_eof()
        tbl.change_begin()
        tbl.qty = 0
        tbl.change_end(.T.)
        tbl.fetch_next()
    end while
t2 = toseconds(time())
trace.writeln("Trial 1 - Seconds elapsed:" + str(t2-t1))
t1 = toseconds(time())
tbl.batch_begin()
tbl.fetch_first()
while .NOT. tbl.fetch_eof()
    tbl.change_begin()
    tbl.qty = 1
    tbl.change_end(.T.)
    tbl.fetch_next()
end while
tbl.batch_end()
t2 = toseconds(time())
trace.writeln("Trial 2 - Seconds elapsed:" + str(t2-t1))
tbl.close()

See Also