How to find the number of records in a flat file using COBOL ?

I tried in many ways, but it loops over again and again in the last record and reports me abend error.

Showing Answers 1 - 13 of 13 Answers

HI BHUVANESWARI.....


  ws-x   pic  9(09).

        open input-file.

 perform read-para
           until end-of-file.

 display 'number of record in input-file : ' ws-x.

   close input-file.

 stop run.


read-para.


 read input-file
   at end move 'y' to ws-end-of-file

 compute ws-x = ws-x + 1.

  Was this answer useful?  Yes

The above answers are ok; i'm giving it in a simplified way: The complete program follows:
********************************************************************
ID DIVISION.
PROGRAM-ID. ABC.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
       SELECT INFILE ASSIGN TO DD1
       ORGANIZATION IS SEQUENTIAL
       ACCESS MODE IS SEQUENTIAL
       FILE-STATUS IS FS1.
DATA DIVISION.
FILE SECTION
.
FD INFILE.
01 INREC PIC X(80).
WORKING-STORAGE SECTION.
77  I   PIC 9(4).
77  EOF  PIC X(3) VALUE 'NO'.
PROCEDURE DIVISION.
       OPEN INPUT INFILE.
       DISPLAY 'OPEN INFILE=' FS1.
       PERFORM UNTIL EOF = 'YES'
         READ INFILE
              AT END MOVE 'YES' TO EOF
              NOT AT END 
              ADD 1 TO I 
       END-PERFORM.
       DISPLAY 'THE NUMBER OF RECORDS IN THE FILE ARE ='  I.
       CLOSE INFILE.
       DISPLAY 'CLOSE FILE=' FS1.
       STOP RUN.
*****************************************************************      
      
The above program really works if you execute. Thanks.

In this code i am using cnt for finding the number of records.

0700-LOAD-UOM-FILE.
READ MPSF-item-FILE AT END

MOVE WSL-Y TO WSW-ITEM-FILE-SWT
MOVE WS-ITEM-TAB-CNT TO WS-UOM-ITEM-MAX
GO TO 0700-LOAD-UOM-FILE-EXIT.
ADD WSC-1 TO WS-ITEM-TAB-CNT.
IF WS-ITEM-TAB-CNT > WSC-100
MOVE WSE-ERROR-MSG TO USER-MSG-TEXT
ELSE
MOVE MPSR-OLDITEM TO WS-OLDITEM (WS-ITEM-TAB-CNT).
MOVE MPSR-NEWITEM TO WS-NEWITEM (WS-ITEM-TAB-CNT).

DISPLAY 'ITEM RECORD READ' WS-ITEM-TAB-CNT .

0700-LOAD-UOM-FILE-EXIT. EXIT.

  Was this answer useful?  Yes

Mainframe programmers wouldn't normally write a Cobol program just to count the number of records in a file.  We would count the number of records using DFSort or SyncSort, or use AMS(Idcams repro).   Both SORT and REPRO would be executed in a JCL stream.  Much faster than writing a Cobol program.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions