CLOSE WORK FILE

#### Search Results

Search

# CLOSE WORK FILE

`CLOSE WORK` [`FILE`] work-file-number

This document covers the following topics:

- CLOSE WORK FILE Usage

- CLOSE WORK FILE Syntax Description

- Example

For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.

Related Statements: `DEFINE WORK FILE` | `READ WORK FILE` | `WRITE WORK FILE`

Belongs to Function Group: Control of Work Files / PC Files

## CLOSE WORK FILE Usage

The statement `CLOSE WORK FILE` is used to close a specific work file. It allows you to explicitly specify in a program that a work file is to be closed.

A work file is closed automatically:

- When command mode is reached.

- When an end-of-file condition occurs during the execution of a `READ WORK FILE` statement.

- Before a `DEFINE WORK FILE` statement is executed which assigns another file to the work file number concerned.

## CLOSE WORK FILE Syntax Description

Syntax Element | Description
--- | ---
`work-file-number` | Work File Number: The work file number (as defined to Natural) to be used. The work file number is either a numeric constant in the value range 1:32 or a numeric variable of type (B/N/P/I) defined with a `CONST` clause which assigning a value in range (1:32). Variable is a scalar (non-array) without precision digits for type (N/P), length in between 1-4 for type (B), and no redefinition field.

## Example

    ** Example 'CWFEX1': CLOSE WORK FILE
    ************************************************************************
    DEFINE DATA LOCAL
    1 W-DAT   (A20)
    1 REC-NUM (N3)
    1 I       (P3)
    END-DEFINE
    *
    REPEAT
      READ WORK FILE 1 ONCE W-DAT  /* READ MASTER RECORD
      /*
      AT END OF FILE
        ESCAPE BOTTOM
      END-ENDFILE
      INPUT 'PROCESSING FILE' W-DAT (AD=O)
          / 'ENTER RECORDNUMBER TO DISPLAY' REC-NUM
      IF REC-NUM = 0
        STOP
      END-IF
        FOR I = 1 TO REC-NUM
        /*
        READ WORK FILE 1 ONCE W-DAT
        /*
        AT END OF FILE
          WRITE 'RECORD-NUMBER TOO HIGH, LAST RECORD IS'
          ESCAPE BOTTOM
        END-ENDFILE
      END-FOR
      I := I - 1
      WRITE 'RECORD' I ':' W-DAT
      /*
      CLOSE WORK FILE 1
      /*
    END-REPEAT
    END

### On this page

- CLOSE WORK FILE Usage
- CLOSE WORK FILE Syntax Description
- Example