basic.open Statement/BASIC Program

basic.open

Command basic.open Statement/BASIC Program
Applicable release versions: AP, R83
Category BASIC Program (486)
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.
Syntax open {"{dict}",}file.reference {to file.variable} {then | else statement.block}
Options
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.
Purpose
Related basic.statements
tcl.clear-file
basic.read
basic.file.variable
basic.clearfile
basic.if
basic.then/else.construct
basic.close
basic.then
basic.default.files
basic.abort
basic.readnext
statement.block
basic.stop
ue.21a3
basic.error
file.control.block
basic.file