OPEN

OPEN


ONERR Index Level operators
Syntax OPEN {"{DICT}",}file.reference {TO file.variable} {THEN | ELSE statement.block}
Category BASIC
Type Statement
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.
Options
See Also statements & functions clear-file READ file.variable CLEARFILE IF THEN | ELSE statement.block CLOSE THEN default file variables ABORT READNEXT statement.block STOP u21a3 ERROR file control block FILE
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 (not available on R83) 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.
Warnings In R83 implementations, a "then" or "else" clause must be included.
Compatibility D3 7.0 AP R83
ONERR Index Level operators