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

write a cobol logic. i have file that has 10 records .1 record go to first output file and second record goes to 2 output and etc

691


) How do u handle errors in BMS macro

1497


2 input fles: 2 flat files, with different number of records. both are having unique key for each record and already sorted in ascending order . match these files using unique key and in output only matching key value has to be written. please procide cobol logic

2084


How many sections are there in data division in COBOL?

671


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

2003






What is the difference between structured cobol programming and object alternativelyiented cobol?

746


I need to compare 3 variables(dates) and do some processing based on the earliest date. There could be more then 1 date record in any of the 3 fields. What is the best way to code this?

1795


Define static linking and dynamic linking.

652


What are the different types of condition in cobol and write their forms.

648


INREC AND OUTREC? HOW TO SPLIT 5K RECORDS TO DIFFERENT FILES IN A FILE IN COBOL? RESTART IN COBOL-DB2? ISOLATION LEVELS?

404


What is the utilization of copybook in cobol?

647


Which Search verb is equivalent to PERFORM…VARYING?

673


Name the divisions, which are available in a cobol program?

674


Write a program that uses move corresponding.

664


What is the difference between external and global variables in COBOL?

804