basic.read

Statement/BASIC Program, Releases: AP and R83

Reads item into dimensioned or dynamic array.

Syntax

read{u} dynamic.array from {file.variable,} id.expression {locked statement{s}} {then | else statement.block}

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 Advanced Pick (AP) 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.

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.

See Also

Command Name Type Description
basic.then/else.construct Definition provide program flow change based upon a boolean condition.
basic.matread Statement Reads item into dimensioned array.
basic.readu Statement see 'read' or 'matread'.
basic.write Statement Writes dynamic array to file.
statement.block Definition one or more statements that follow a Pick/BASIC decision-path related token such as, but not limited to, 'then', 'else', 'locked' and 'onerr'.
basic.default.files Definition used by any file-access Pick/BASIC statement when a specific file variable is not specified.
basic.statements Definition Definition of statements and functions.
basic.array.references Definition Referencing arrays.
basic.replace Function Replaces element in string expression.
array Definition tables of values of any data type.
basic.array.references Definition Referencing arrays.
basic.id.expression Definition An expression which derives an item-id.
basic.open Statement Opens file for input and output.
basic.file.variable Definition Defines file location from previous 'open' statement.
basic.array.dynamic Definition A string variable delimited by reserved metacharacters.
basic.locked Definition Takes 'locked' path when group/item lock encountered.
basic.array.variable Definition References a dimensioned array.
basic.extract Function Extracts element from array.
basic.delete.function Function Deletes element from array.
basic.file Statement Opens file and dimensions array.

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.