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
If you are current on the owner of a set, what is the difference between an obtain next and obtain first? Actually in which topic will we use dis???Plz explain it clearly
What is the local-storage section?
Explain what you understand by passing by value.
Name the divisions, which are available in a cobol program?
EXPLAIN MAIN FRAME TESTING PROCESS...HOW TO FIX THE MAINFRAME BUGS?
What is the difference between goback, stop run and exit program in cobol?
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
What is the problem of ordered sequential files access?
what is amode(24), amode(31), rmode(24) and rmode(any)?
How do get the result of your program directly on your pc?
please..could u give an example about USAGE IS POINTER ..and explain why and when we use it ?
How do you reference the fixed block file formats from cobol programs
Write a cobol program making use of the redefine clause.
What is the difference between PIC 9.99 and PIC9v99?
What is report-item in COBOL?