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 |
How do you define a table/array in COBOL?
1.give the details about WHEN OTHER. 2. how many form are available in evaluate.
If A>B next sentence end-if display 1 display 2. display 3. If a>b, it will display only 3.(the next sentence, ie., after fullstop/period) ____________________________________ if a>b continue end-if display 1 display 2. display 3. If a>b, it Will display 1 2 3 (the next statement) ____________________________________ if a>b continue display 1 end-if display 2 display 3. display 4. If a>b, Will it display 2 3 4 (or) 1 2 3 4 ?
Why we need to use redefine clause when we can define the variable seperately... what is actual need....
Hi pls anybody tell me about " ANALYSIS DOCUMENT PREPARATION AND ESTIMATION OF TASK " (in real time project)."I want to update a sequential file in my project" for that purpose i need both structures i mean analysis document and estimation of task.
How do define dynamic array in cobol. how do you define single dimensional array and multidimensional array in your cobol?
how to change picture class of copy book variable inside program?
What type of SDLC u followed? Why?
COMP field occupy ?
is this below syntax correct? CALL 'subprg' using A,B Please help
I have a PS file and I would like to manually insert the binary values (like a COMP format) into the file. How can i do that? the way do in COMP-3 format.. suppose i want to insert -12345 in to file in comp-3 format. simply we can open a file in edit mode and do HEX-ON and insert the value . SEE BELOW-- 135 24D in 3 bytes - this will be COMP-3 presenatation of -12345.
consider the following FD FILE-1 01 REC-1 PIC X(80) ...... WORKING-STORAGE SECTION 01 W-REC PIC X(90) ........ PROCEDURE DIVISION FIRST-PARA ....... READ FILE-1 INTO W-REC AT END MOVE 1 TO EOF-FLAG which of the following is true with respect to the above? a.REC-1 will contain nothing and W-REC will contain the contains of the record read b.REC-1 and W-REC contain the same data c.syntex is invalid and error will occur d.REC-1 and W-REC must be of same size