READ

READ


quotes Index Level READNEXT
Syntax READ{U} dynamic.array FROM {file.variable,} id.expression {LOCKED statement{s}} {THEN | ELSE statement.block}
Category BASIC
Type Statement
Description reads an item as a dynamic array and stores the item as a string. Each attribute is automatically an element of the dynamic array variable and may be referenced with the appropriate intrinsic functions.

If the file.variable parameter 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.

See the "then/else construct" for an explanation on the use of "then" and "else" clauses in statements that allow or require them.

The "readu" statement is identical to the "read" statement, except that the item is "locked", preventing access to that item by any other process. Note that in R83 implementations, the entire group in which the item was found is locked.

The "locked" statements are executed if the item exists and is already locked by another process or by the current process at a different level. "system(0)", in the "locked" clause, returns the port number which has the item locked. At the termination of the program, "readu" unlocks the item.  

If a binary item is read, "system(0)" is set to 10. The variable string consists of the hex fid in attribute 1 and the hex frame in attribute 2.

In D3 implementations, this statement may optionally be written "matread" or "read". If "mat" is omitted, a matrix read can be determined by the definition of the variable, "array.variable". If no "dim" statement appears, it is automatically treated as a "dynamic" array.
Options
See Also THEN | ELSE statement.block MATREAD READU WRITE statement.block default file variables statements & functions array references REPLACE array array references < > id.expression OPEN file.variable dynamic array LOCKED array.variable EXTRACT DELETE FILE READV BEGIN WORK
Example open 'customer' to customer.file else stop 201, 'customer'
item = ''
crt 'enter customer id ':
input item.id
read item from customer.file,item.id else stop 202,item.id
print 'the customer name is ':item<1>

This example opens the "customer" file and prompts the operator for the customer's item-id.  If the read is scuccessful, the customer name in attribute 1 is displayed.

file customer
crt 'enter customer id ':
input item.id
read customer from item.id else stop 202,item.id
print 'the customer name is ':customer(name)

This example used the "file" statement to bind the "customer" file to this program. It prompts for the item-id, reads the item and prints the name. The "file" statement allows dictionary-type references to the read data item.
Warnings If an item is read with a "read" statement and later updated with a "write" statement, it is possible that another process could read the same item and update it. The "readu" statement performs a lock so that this type of situation is avoided.
Compatibility D3 7.0 AP R83
quotes Index Level READNEXT