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
I have File 1 occurs 5 times with Employee-ID,Employee-Name,Employee-Dept (EEE and MECH). I have File 2 occurs 10 times with Employee-ID,Employee-Name,Employee-Dept (EEE,CIVIL,CHEMICAL and MECH). In FIle 1 and FIle 2 , for matching Employee-DEPT (Only MECH) , we need to move entire records from file1 to file 2. We should not use 2D array. Your help is needed here.
Program A (Normal COBBAT) calling a B Program (DB2COBOL, COBBATDB which is using a VSAM file. its a dynamic call. How we will handle VSAM file decleration in our from JCL from where we are running A PGM. And should we have PLAN for A pGM also. if possible can some one post a sample JCL. Thanks for help in advance.
Name the divisions, which are available in a cobol program?
How do we get current date from system with century in COBOL?
Write the code implementing the perform … varying.
What is the default value(s) for an initialize and what keyword allows for an override of the default?
how to convert the recors form vsam file to db2 table tru file aid
How can you get the ksds file records into your cobol program?
How to use the same COBOL program in Batch and CICS on lines? explain with an example
What are the various section in data division and briefly explain them.
What is perform what is varying?
how to refer the data field?
How to get the last record in vsam file in cluster? And how can you get the ksds file records into your cobol program?
) what is the difference between AID and HANDLE AID?
EXPLAIN MAIN FRAME TESTING PROCESS...HOW TO FIX THE MAINFRAME BUGS?