Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 10: File processing


Close file: Step 5 of File Handling

  • Once all required processing is done we can close the file to disconnect it from program
  • CLOSE statement s used to close the file. If we don’t close files, the completion of the program closes all the files used in program
  • Basic syntax:-

    CLOSE file-name.

  • Where,
    file-name is logical file name of file which we want to close.

Example of CLOSE statement

INPUT FILE (PS DATASET):-

10000STEVE OKURA 20000AMIT KHATRI 30000KARISHMA KAIF

COBOL PROGRAM:-

000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. CLOSEFL. 000300 ENVIRONMENT DIVISION. 000400 INPUT-OUTPUT SECTION. 000500 FILE-CONTROL. 000600 SELECT EMPLOYEE ASSIGN TO EMPL 000700 ORGANIZATION IS SEQUENTIAL 000800 ACCESS IS SEQUENTIAL. 001000 DATA DIVISION. 001100 FILE SECTION. 001200 FD EMPLOYEE. 001300 01 EMPLOYEE-REC. 001400 05 EMPL-ID PIC 9(05). 001500 05 EMPL-NAME PIC X(15). 001600 WORKING-STORAGE SECTION. 001700 01 WS-EMPL. 001800 05 WS-EMPL-ID PIC 9(05). 001900 05 WS-EMPL-NAME PIC X(15). 002000 01 WS-EOF-FLAG PIC A(01). 002100 PROCEDURE DIVISION. 002200 MAIN-PARA. 002300 OPEN INPUT EMPLOYEE. 002400 PERFORM UNTIL WS-EOF-FLAG = 'Y' 002500 READ EMPLOYEE INTO WS-EMPL 002600 AT END 002700 MOVE 'Y' TO WS-EOF-FLAG 002800 NOT AT END 002900 DISPLAY 'REC : ' WS-EMPL 003000 END-READ 003100 END-PERFORM. 003200 CLOSE EMPLOYEE 003300 STOP RUN.

Mainframe Job Step to run above program:-

//STEP01 EXEC PGM=CLOSEFL //STEPLIB DD DSN=USER.TEST.LOADLIB,DISP=SHR //EMPL DD DSN=MAINFRAM.FILE.MAIN,DISP=SHR //SYSOUT DD SYSOUT=*

SYSOUT After Job run:-

REC : 10000STEVE OKURA REC : 20000AMIT KHATRI REC : 30000KARISHMA KAIF

You can observe in above COBOL program, how file is closed after required operation is performed





© copyright mainframebug.com
Privacy Policy