CLOSE WORK FILE

CLOSE WORK [FILE]  work-file-number

This document covers the following topics:

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


Function

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 data set to the work file number concerned.

  • According to sub-parameter CLOSE of profile parameter WORK.

CLOSE WORK FILE is ignored for work files for which CLOSE=FIN is specified in profile parameter WORK.

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 assigns a value in range 1:32. Precision digits for type (N/P) are not allowed.

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