GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Mainframe  >  COBOL
Go To First  |  Previous Question  |  Next Question 
 COBOL  |  Question 122 of 159    Print  
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.


  
Total Answers and Comments: 4 Last Update: November 05, 2008     Asked by: Bhuvaneswari Raman 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 22, 2007 03:10:10   #1  
sai mainframes Member Since: November 2007   Contribution: 13    

RE: How to find the number of records in a flat file u...

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.


 
Is this answer useful? Yes | No
November 22, 2007 03:12:16   #2  
sai mainframes Member Since: November 2007   Contribution: 13    

RE: How to find the number of records in a flat file u...
in above answer just  give the condition


until ws-end-of-file = 'y'

 
Is this answer useful? Yes | No
December 26, 2007 09:29:31   #3  
kishoremain Member Since: July 2007   Contribution: 3    

RE: How to find the number of records in a flat file using COBOL ?
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.

 
Is this answer useful? Yes | No
November 05, 2008 02:23:20   #4  
sivachennai Member Since: November 2008   Contribution: 4    

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

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.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape