How to read records which is in sequential file in reverse
order ? Exp. 1 2 3 4 5 . i want 5 4 3 2 1?please clear my
doubt any one
Answers were Sorted based on User's Feedback
Answer / abhishek
i am giving you pseudo code of same
suppose we have 5 records
rec-no 1-->10
rec-no 2-->1
rec-no 3-->25
rec-no 4-->35
rec-no 5-->20
read sequential file to get record count of file
close file
define an array whose size is equal to record count of file
open file
read file in loop
move current record of sequential file to last subscript of
array define above ( this can be taken care using perform
varying)
read the array starting from subscript 1 to record count
this will be similar to reading sequntial file in reverse
order.....
thanks,
Abhishek
| Is This Answer Correct ? | 23 Yes | 0 No |
Answer / mustafa i
Abhishekh your logic is correct
just to add to it
we can even do it by reading the file only once.
1)Read File & Move into an array until EOF also increment a
counter after every read.
3)By decrementing the Counter and using it as subscript
we can now read the array and hence the file in
reverse order.
| Is This Answer Correct ? | 10 Yes | 4 No |
Answer / chp
ok.. but if my file consists of the records 10 1 25 35 20??
| Is This Answer Correct ? | 6 Yes | 3 No |
Answer / sreejith
sort the file firt in decending order
and then read sequentially
| Is This Answer Correct ? | 12 Yes | 10 No |
Answer / rakesh
we dont know how many records in the file so how can u
declare the array ?
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / abhishek
@Rakesh You can define table occurs clause based on the No
of records that input file have.
All, You can reverse the file it self using external sort
before reading it.
Thanks,
Abhishek
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / gautam
Read file till end of the file and move the record to array.
Increase the counter.
Read the record from array until counter = 0.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / mustafa i
@Rakesh ... you can then set it to a maximum.
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / mastan ummadisetti
First read the file and add a sequence number to it.
Then use sort for descending the records based on sequence numbers.
| Is This Answer Correct ? | 0 Yes | 0 No |
give the examples of strings in cobol
Consider the following code: 77 A PIC 99V99 VALUE 55.35 77 B PIC 99V999 VALUE 32.754 ADD B TO A ON SIZE ERROR DISPLAY "ERROR!!!" What will be the result ? (a) A=88.10, B=32.754 (b) A=87.00 B=32.754 (c) A=87.10 B=32.754 (d) ERROR!!! will be DISPLAYed on the screen.
What are some examples of command terminators?
How to retrive the 9th records out of ten records using the cobol program ?
Have you used comp and comp-3 in your project? And how?
how to refer the data field?
What will happen if you code GO BACK instead of STOP RUN in a stand-alone COBOL program i.e. a program which is not calling any other program ?
What is the default value(s) for an initialize? What keyword will allow for an override of the default?
Can a Search can be done on a table with or without Index?
01 a pic s9(5) value -12345, if we disply a , the sign will overpunched with last digit but i need to get the miuns sign in the result?
in the TIME parameter we r giving hours r minutes
What is the mode in which you will OPEN a file for writing?