How to read the last 100 records from a COBOL file. The file
contains N number of records.
Answer Posted / bibhuti swain
PROCEDURE DIVISION.
PARA.
OPEN INPUT STUDFILE.
PERFORM PARA1 UNTIL EOF = 1.
DISPLAY 'TOTAL NO:OF RECORDS ' A.
COMPUTE B = A - 100.
MOVE 0 TO EOF.
CLOSE STUDFILE.
OPEN INPUT STUDFILE.
PERFORM PARA2 UNTIL EOF = 1.
CLOSE STUDFILE.
STOP RUN.
PARA1.
READ STUDFILE AT END MOVE 1 TO EOF.
COMPUTE A = A + 1.
PARA2.
READ STUDFILE AT END MOVE 1 TO EOF.
COMPUTE C = C + 1.
IF C >= B AND EOF NOT = 1
DISPLAY STUD-REC.
If anybody doesn't understand this logic i can explain..
In PARA2 the file is read from the beginning and the moment
the value of C reaches the value of B i.e value of C = B
and then it will satisfy the condition IF C >= B and from
there it will start displaying the records till end.
| Is This Answer Correct ? | 14 Yes | 1 No |
Post New Answer View All Answers
How do you reference the following file formats from cobol programs?
I have a program with an Array of 5000 occurences which is being passed from 5 sub levels to the front end screen. Thess 5 programs using each 5*2 = 10 different arrays with size as 5000. This is causing the transaction to utilize more storage consupmtion. I am looking to reduce the storage consumption. As part of that initially i thought Dynamic array may solve my problem. After viewing the comments given i see its same as normal array. IS there any other way we can resolve this issue?
How arrays can be defined in COBOL?
i made it to stage 3 of an interview process wednessday they will quiz my knowledge again face to face for an analyst role recruiter said it will be based on Business requirements system is cobol and good ideas what they might ask etc
i want to learn mainframe..any websites and material to learn from basic..? my mail id : rajeswaribe2010@gmail.com
Why do we code s9 (4) comp. Inspite of knowing comp-3 will occupy less space?
How do define dynamic array in cobol. how do you define single dimensional array and multidimensional array in your cobol?
What is the LINKAGE SECTION used in COBOL?
What are 77 levels used for?
Which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement?
How to get the last record in vsam file in cluster? And how can you get the kids file records into your cobol program?
Write a program to explain size error.
Write some characteristics of cobol as means of business language.
Is it possible that the redefines clause has different picture clauses compared to the one it redefined?
What is the difference between a binary search and a sequential search? What are the pertinent cobol commands?