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

How to know whether the module is dynamical or statistical?

891


Differentiate between structured cobol programming and object-oriented cobol programming.

875


what is amode(24), amode(31), rmode(24) and rmode(any)?

918


IF I mention stop run in CICS what happens?

2126


How to remove the spaces at the end of each record in the output file of variable length, via cobol program?

933


can you please let me know if there is any walkins for COBOL/PLI/DB2/IMS/JCL in pune other than IBM and ITC infotech

2212


What is report-item in COBOL?

925


Can a Search can be done on a table with or without Index?

1082


Have you used comp and comp-3 in your project? And how?

2242


What is redefines clause in COBOL?

1073


What is amode(31)

944


Explain how to differentiate call by context by comparing it to other calls?

946


how do you reference the esds vsam file formats from cobol programs

917


) what is the difference between AID and HANDLE AID?

1914


Explain about different table spaces.

888