basic.open

Statement/BASIC Program, Releases: AP and R83

Opens file for input and output.

Syntax

open {'{dict}',}file.reference {to file.variable} {then | else statement.block}

Description

opens a specified filename and associates the file with the optional file.variable.

If 'dict' is specified (or implied as an expression), the dictionary level of the specified filename is opened and assigned to the file.variable. The optional 'dict' may be expressed as part of the file name as 'dict file.name'.

If no file.variable is specified, the file is opened and assigned to the 'default' file.variable.

If the file is opened successfully, the 'then' clause, if present, is executed. If the file is not opened successfully, the 'else' clause, if present, is executed. If the file can not be opened and no 'then/else' clause is specified, the program terminates with error message 201.

See the 'then/else construct' for an explanation on the use of 'then' and 'else' clause.

Example

open 'customer' to customer.file else stop 201,'customer file
cannot be opened'

Opens the data area of the 'customer' file to the file.variable
'customer.file'. If the 'customer' file does not exist, it
stops and prints error message 201.

open 'dict','invoice' to invoice.dict then
print 'ok'
end else
stop 201,'dict invoice cannot be opened'
end

Opens the dictionary of the 'invoice' file. If successful, it prints
'ok'. If not, it stops and prints error message 201, passing the
string 'dict invoice'. This results in the display:
'[201] 'dict invoices' is not a file name'.

open 'invoice.control'
readv next.invoice.id from 'invoice.counter',1

This form, available only in AP implementations, demonstrates how the
'to', 'then' and 'else' are all optional in an
'open' statement. Note the file.variable was left off of the read
command.

See Also

Command Name Type Description
basic.statements Definition Definition of statements and functions.
tcl.clear-file Verb: Access Clears dict or data section of specified file.
basic.read Statement Reads item into dimensioned or dynamic array.
basic.file.variable Definition Defines file location from previous 'open' statement.
basic.clearfile Statement Clears specified file.variable.
basic.if Statement Initiates logical expression.
basic.then/else.construct Definition provide program flow change based upon a boolean condition.
basic.close Statement Closes file.
basic.then Statement In-line initiator.
basic.default.files Definition used by any file-access Pick/BASIC statement when a specific file variable is not specified.
basic.abort Statement Terminates program and PROC{s}.
basic.readnext Statement Retrieves the next item-id from an active list.
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.stop Statement Terminates program.
ue.21a3 User Exit Opens a file, or reads the next attribute from a file.
basic.error Statement Displays error message.
file.control.block Definition Description of file control block.
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.