IB Statements/close

From CometWiki

Jump to: navigation, search

CLOSE statement

Syntax: CLOSE [(lun)]

Discussion: The CLOSE statement closes a specified logical unit number, one that was opened via a previous OPEN statement. Once a logical unit number (lun) is closed, it may be reassigned by another OPEN statement. A device that is closed by one task is available for use by other tasks. Note that data files are not treated as devices, therefore data files may be opened by more than one user at a time.

The CLOSE statement without a lun closes all logical unit numbers (including logical unit number 0).

If a task is terminated by an END or a STOP statement or is aborted, all logical unit numbers are closed automatically.

The CLOSE statement is ignored if the logical unit number it refers to was not assigned by a previous OPEN statement.

Example 1: OPEN (1) "LP1"





In this example, logical unit number 1 is opened and assigned to the printer device named LP1. Later in the program, logical unit number 1 is closed (and thus, LP1 is available for other applications).

Example 2: CLOSE (6) & OPEN (6) "WORKFILE"

In this example, logical unit number 6 is first closed, then opened and assigned to a data file named "WORKFILE." This technique guarantees that the logical unit number is available before the OPEN statement is executed.

Example 3: CLOSE  ! Close all logical unit numbers




OPEN (0) TERM$  ! Open TERM$ as logical unit number 0

This example shows how the CLOSE statement without a lun closes all logical unit numbers. The OPEN statement is used to re-open the console device (TERM$) as lun 0.

Personal tools