How to read records in reverse order in flat file?
I know we can do it by reading all records into an array....
Then read records in reverse order by using subscript or index
but can any body give me the exact code.

Answer Posted / prasad rellu

IDENTIFICATION DIVISION.
PROGRAM-ID. RRED.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO DD1.
SELECT OUTFILE ASSIGN TO DD2.
DATA DIVISION.
FILE SECTION.
FD INFILE.
01 INREC.
05 EMP-ID PIC X(3).
05 EMP-NAME PIC X(10).
05 EMP-ADD PIC X(10).
FD OUTFILE.
01 OUTREC.
05 E-ID PIC X(3).
05 E-NAME PIC X(10).
05 E-ADD PIC X(10).
WORKING-STORAGE SECTION.
01 WS-COUNT PIC 9(4).
01 EOF PIC X(1) VALUE 'N'.
01 ARRAY1.
05 ARREC OCCURS 1 TO 50 TIMES DEPENDING ON WS-COUNT.
10 AR-EMP-ID PIC X(5).
10 AR-EMP-NAME PIC X(10).
10 AR-EMP-ADD PIC X(10).
PROCEDURE DIVISION.
MOVE 1 TO WS-COUNT.
OPEN INPUT INFILE.
OPEN OUTPUT OUTFILE.
PERFORM MOVE-RECORD UNTIL EOF = 'Y'.
PERFORM PARA1 UNTIL WS-COUNT = ZEROS.
CLOSE INFILE.
CLOSE OUTFILE.
STOP RUN.
MOVE-RECORD.
READ INFILE AT END MOVE 'Y' TO EOF
NOT AT END
MOVE INREC TO ARREC(WS-COUNT)
ADD 1 TO WS-COUNT
END-READ.
PARA1.
MOVE ARREC(WS-COUNT) TO OUTREC.
WRITE OUTREC.
SUBTRACT 1 FROM WS-COUNT.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the utilization of copybook in cobol?

659


What is length is cobol?

652


What is amode(24)?

684


how do you reference the rrds file formats from cobol programs

805


What is a report item?

741






How to traceback if I am getting SOC7 or SOC4 abend? List down the steps

1077


How to get the last record in vsam file in cluster? And how can you get the kids file records into your cobol program?

744


Difference between cobol and cobol-ii?

715


input= ,,,, mainframe training ,,, hyderabad .... location.... output1=$ mainframe training in hyderabad location$ output2=**** mainframe training in hyderabad location ****. In this pgn when we give input considering the spaces the output is displayed in this format.Like in the place of ,,,, $ should be displayed likewise.So please helpmeout.

1785


What are 77 levels used for?

661


how do you reference the variable block file formats from cobol programs

690


how do you reference the variable unblock file formats from cobol programs

754


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

705


what is difference between cobol and cobol/400

21574


What is amode(31)

728