readv Statement

The readv statement reads an item from the optionally-specified file variable and assigns the value contained in the attribute number referenced in the attribute expression to the specified variable.

Syntax

readv{u} var from {file.var,} ID.exp, ac.exp {locked statement.block} {then|else statement.block}

Description

If file.var is not specified, the default file variable is used.

The else clause is taken when the item is not on file. The then clause is taken when the item is read successfully.

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.

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

If the readvu 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 writev statement. Items can be updated without being unlocked by using the writevu statements.

NOTE

  • The readv statement reads the entire item into temporary workspace, extracts the targeted attribute, places it into the variable, and resets temporary space. The rest of the item is ignored. A series of readv statements against different attributes in the same item force the system to continually reread the same item.

  • readv should be used only in cases where 1 or 2 attributes are needed from a larger item without the rest of the item. Using readv exclusively causes the program to run significantly slower.

Example(s)

Items in the inventory file have a list of composite parts in attribute 10. In this example, only attribute 10 is read, and each sub-part displays on a separate line.

readv partlist from inventory,part.number,10 then

cnt = dcount(partlist,char(253))

for l = 1 to cnt

print partlist<1,l>

next l

end

This example reads the first attribute from the nextnum item in the control.file, and locks the entire item. The lock is cleared by the writev statement.

readvu next.number from control.file,"nextnum",1 then

print ’got the next number’

writev next.number on control.file,"nextnum",1

end

See Also

Attribute Count Expression, begin work Statement, Default File Variables, File Variable, ID Expression, locked Clause, read Statement, release Statement, Statement Blocks, Statements and Functions, system() Function, then/else Statement Blocks, unlock-item Command, writev Statement, writevu Statement