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
here is my requirement A1 is alphanumeric with value 'A1B2C3D4' as defined below 05 A1 PIC X(8) VALUE IS 'A1B2C3D4' but i need to have A2,A3 as ABCD & 1234 repectively...... A2 = ABCD A3 = 1234 Can you please explain me what are the different ways to do it?
Explain how to differentiate call by context by comparing it to other calls?
IF I mention stop run in CICS what happens?
How do define dynamic array in cobol. how do you define single dimensional array and multidimensional array in your cobol?
how to access the file from prodution from changeman tool and to submit a file to production
How to get the last record in vsam file in cluster? And how can you get the ksds file records into your cobol program?
What is the difference between Global and External Variables?
what is amode(24), amode(31), rmode(24) and rmode(any)?
how to convert the recors form vsam file to db2 table tru file aid
If you are current on the owner of a set, what is the difference between obtain next and obtain first?
How do you code cobol to access a parameter that has been defined in jcl? And do you code the parm parameter on the exec line in jcl?
What are the different rules of SORT operation?
How do u write test cases?
How to find out the closest prime number of an input number? I believe it has something to do with SEARCH and COBOL Linear Array.
Explain sorting techniques in cobol program? Provide the sort file definition, the sort statement, its syntax and meaning