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


Please Help Members By Posting Answers For Below Questions

Define static linking and dynamic linking.

669


What is the local-storage section?

683


here is my requirement A1 is alphanumeric with value 'A1B2C3D4' as defined below 05 A1 PIC X(8) VALUE IS 'A1B2C3D4' but i need to have A2,A3 as ABCD & 1234 repectively...... A2 = ABCD A3 = 1234 Can you please explain me what are the different ways to do it?

6832


How to read the 2nd last record of a VSAM file? (The file size is huge and we don't know the key)

2723


) How do u handle errors in BMS macro?

1429






Explain the configuration section of a cobol program with examples of syntax.

659


What is the LINKAGE SECTION used in COBOL?

889


What is an in line perform? When would you use it? Anything else you wish to say about it.

645


Write the code to count the sum of n natural numbers.

701


example for sub strings ? and refernce modifications whit output pls

1846


Write some characteristics of cobol as means of business language.

619


How do define dynamic array in cobol.

671


What is amode(31)

724


HOw can I get the negative sign while deduct high value from low value

1790


How do you get the data to code the BMS macro?

1476