close

The EGL close statement disconnects a printer; or closes the file or message queue associated with a given record; or, in the case of an SQL record, closes the cursor that was open by an EGL open or get statement.


Syntax diagram for the close statement

name

Name of the I/O object that is associated with the resource being closed; that object is a print form or an indexed, MQ, relative, serial, or SQL record

resultSetIdentifier

For SQL processing only, an ID that ties the close statement to a get or open statement run earlier in the same program. For details, see resultSetID.

Example:

     if (userRequest = "C")
     try
       close fileA;
     onException
        myErrorHandler(12);
     end
     end 

The behavior of a close statement depends on the type of I/O object.

Indexed, serial, or relative record

When you use the name of an indexed, serial, or relative record in a close statement, EGL closes the file associated with that record.

If a file is open and you use the fileAssociation item to change the resource name associated with that file, EGL closes the file automatically before executing the next statement that affects the file. For details, see resourceAssociation.

EGL also closes any file that is open when the program ends.

MQ record

When you use the name of a MQ record in a close statement, EGL ensures that the MQSeries command MQCLOSE is executed for the message queue associated with that record.

Print form

If the I/O object is a print form, the close statement issues a form feed and either disconnects from the printer or (if the print form is spooled to a file) closes the file.

Before you use sysVar.printerAssociation to change the print destination, close the printer or file specified by the current value of sysVar.printerAssociation. Issue a close statement option for each print destination, as multiple printer or print files can be open at the same time.

EGL run time ensures that all printers are closed when the program ends.

SQL record

When you use the name of an SQL record in a close statement, EGL closes the SQL cursor that is open for that record.

EGL automatically closes a cursor in these cases:

  • A cursor-processing loop follows an open statement and continues until a No Record Found (NRF) condition indicates that all rows in the set were processed

  • EGL runs a get statement for an SQL record when a single row is read and neither forUpdate nor singleRow was specified as an option

  • EGL runs a replace or delete statement that uses the cursor opened by a get statement; in this case, forUpdate was specified as an option in the get statement

  • EGL begins to process an open or get statement for a record that is associated with an open cursor; the close precedes the other processing

  • The program runs either sysLib.commit or sysLib.rollback

EGL closes all open cursors in this case:

  • The program is of type textUI and does an automatic commit before conversing a form; for details on textUI programs and the converse statement, see Segmentation

Related concepts
Record types and properties
resultSetID
Segmentation in text applications
SQL support

Related tasks
Syntax diagram

Related reference
add
delete
EGL statements
Exception handling
execute
get
get next
get previous
I/O error values
open
prepare
replace
recordName.resourceAssociation
SQL item properties
sysLib.commit
sysLib.rollback
sysVar.printerAssociation
sysVar.terminalID