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 / ch. ranveer gurjar

you can try this i will give 100% exact output...by
CH. RANVEER SINGH GURJAR





IDENTIFICATION DIVISION.
PROGRAM-ID. 'OCCURS'.
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 IN-EMP-ID PIC X(5).
05 IN-EMP-NAME PIC X(10).
05 FILLER PIC X(65).
FD OUTFILE.

01
OUTREC.
05 OUT-EMP-ID PIC X(5).

05 OUT-EMP-NAME PIC X(10).

05 FILLER PIC X(65).

WORKING-STORAGE
SECTION.
01 WS-COUNT PIC 9(4) VALUE ZEROS.

01 EOF PIC X(1) VALUE 'N'.



01ARRAY1.
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).

PROCEDURE
DIVISION.
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.
PARA1.
MOVE ARREC(WS-COUNT) TO OUTREC
WRITE OUTREC
SUBTRACT 1 FROM WS-COUNT.

Is This Answer Correct ?    12 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What kind of error is trapped by on size error option?

743


What is the default value(s) for an initialize and what keyword allows for an override of the default?

697


What are the various section in data division and briefly explain them.

700


Which Search verb is equivalent to PERFORM…VARYING?

688


What is the difference between binary search and sequential search?

643






What is the local-storage section?

683


i was faced one question- i have value -00001234.56 Suppress the zeroes and the output should be -1234.56 But Not - 1234.56 spaces should not be available after suppressing the zeroes. logic in jcl and cobol?

897


When is inspect verb is used in cobol?

679


What is the difference between Global and External Variables?

666


1.give the details about WHEN OTHER. 2. how many form are available in evaluate.

1616


what is difference between cobol and cobol/400

21570


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

649


Have you used the sort in your project?for this type of questions any working on real time project give the eg. with real time scenario.

2060


What is perform what is varying?

711


IF I mention stop run in CICS what happens?

1898