basic.open
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
User Comments
What do you think?
Share your experience or ask a question by using the form below.
Login to leave your comments.
