sequential file read
ID DIVISION.
PROGRAM-ID. ESDSRD.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMPFILE ASSIGN TO AS-DD1
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS WS-FS1.
DATA DIVISION.
FILE SECTION.
FD EMPFILE.
01 EMPREC.
05 EMPNO PIC 9(04).
05 FILLER PIC X(01).
05 EMPNAME PIC A(10).
05 FILLER PIC X(01).
05 EMPLOC PIC X(10).
05 FILLER PIC X(01).
05 EMPSAL PIC 9(05).
05 FILLER PIC X(48).
WORKING-STORAGE SECTION.
01 WS-FS1 PIC 9(02).
01 WS-CHOICE PIC X(02).
PROCEDURE DIVISION.
PERFORM OPEN-PARA.
PERFORM READ-PARA UNTIL WS-FS1 = 10.
PERFORM CLOSE-PARA.
OPEN-PARA.
OPEN INPUT EMPFILE.
IF WS-FS1 = ZERO
DISPLAY 'OPEN SUCCESFUL' WS-FS1
ELSE
DISPLAY 'ERROR IN OPENING FILE' WS-FS1
STOP RUN
END-IF.
READ-PARA.
READ EMPFILE
AT END
DISPLAY 'END OF FILE' WS-FS1
NOT AT END
DISPLAY EMPREC
END-READ.
IF WS-FS1 = ZERO
DISPLAY 'READ SUCCESFUL' WS-FS1
ELSE
DISPLAY 'ERROR IN READING FILE' WS-FS1
STOP RUN
END-IF.
CLOSE-PARA.
CLOSE EMPFILE.
IF WS-FS1 = ZERO
DISPLAY 'CLOSE SUCCESFUL' WS-FS1
ELSE
DISPLAY 'ERROR IN CLOSING FILE' WS-FS1
STOP RUN
END-IF.
STOP RUN.
PROGRAM-ID. ESDSRD.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMPFILE ASSIGN TO AS-DD1
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS WS-FS1.
DATA DIVISION.
FILE SECTION.
FD EMPFILE.
01 EMPREC.
05 EMPNO PIC 9(04).
05 FILLER PIC X(01).
05 EMPNAME PIC A(10).
05 FILLER PIC X(01).
05 EMPLOC PIC X(10).
05 FILLER PIC X(01).
05 EMPSAL PIC 9(05).
05 FILLER PIC X(48).
WORKING-STORAGE SECTION.
01 WS-FS1 PIC 9(02).
01 WS-CHOICE PIC X(02).
PROCEDURE DIVISION.
PERFORM OPEN-PARA.
PERFORM READ-PARA UNTIL WS-FS1 = 10.
PERFORM CLOSE-PARA.
OPEN-PARA.
OPEN INPUT EMPFILE.
IF WS-FS1 = ZERO
DISPLAY 'OPEN SUCCESFUL' WS-FS1
ELSE
DISPLAY 'ERROR IN OPENING FILE' WS-FS1
STOP RUN
END-IF.
READ-PARA.
READ EMPFILE
AT END
DISPLAY 'END OF FILE' WS-FS1
NOT AT END
DISPLAY EMPREC
END-READ.
IF WS-FS1 = ZERO
DISPLAY 'READ SUCCESFUL' WS-FS1
ELSE
DISPLAY 'ERROR IN READING FILE' WS-FS1
STOP RUN
END-IF.
CLOSE-PARA.
CLOSE EMPFILE.
IF WS-FS1 = ZERO
DISPLAY 'CLOSE SUCCESFUL' WS-FS1
ELSE
DISPLAY 'ERROR IN CLOSING FILE' WS-FS1
STOP RUN
END-IF.
STOP RUN.
Comments
Post a Comment