Version 4.2.6 for Mainframes (Update)
 —  Statements  —

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:

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

Top of page

Syntax Description

work-file-number

The number of the work file (as defined to Natural) to be closed.

Top of page

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                       

Top of page