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



How to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

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

How to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

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

How to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

Answer / chp

ok.. but if my file consists of the records 10 1 25 35 20??

Is This Answer Correct ?    6 Yes 3 No

How to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

Answer / sreejith

sort the file firt in decending order
and then read sequentially

Is This Answer Correct ?    12 Yes 10 No

How to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

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

How to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

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

How to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

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

How to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

Answer / mustafa i

@Rakesh ... you can then set it to a maximum.

Is This Answer Correct ?    1 Yes 1 No

How to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

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 to read records which is in sequential file in reverse order ? Exp. 1 2 3 4 5 . i want 5 4 3 2..

Answer / gumba

Use Open Input file Reversed

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More COBOL Interview Questions

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?

7 Answers  


if i am reading a file with some 50000 records and moving to a DB2 table and suddenly the program abends in between, is there anyway i could restart from the exact record at which the job failed once the program restarts.

2 Answers   UST,


I have a sequential file. How do I access a record in this sequential file randomly in my program ?

8 Answers   CGI, Xansa,


what is the diff b/w select stsmt and cursor ?

2 Answers  


What is normalisation?

2 Answers   IBM,






have in 100 records in a file i want to move only matched records to one output_file1 and nonmathed records are moved to another output_file2 ... any one can provide logic code

3 Answers  


What is the maximum length of a field you can define using COMP-3?

4 Answers   Complex System, Infosys,


How do u initialize an array?

2 Answers   CTS,


What will happen if a variable is declared as below.. Explain with an example? Working storage section:- 01 WS-VARX PIC X(10) VALUE 'ABCDEFGHIJ'. 01 WS-VARN REDEFINES WS-VARX PIC 9(5) VALUE '12345'. What will happen I want Display WS-VARX and WS-VARN?

3 Answers   Xansa,


Describe the difference between subscripting and indexing ?

2 Answers  


I am getting S00F abend when i try to compare two variable of different pic class,one variable is of 9(09) and another is S9(09) comp-3. First i moved the data from S9(09) comp-3 to 9(09), but no luck. So i tried to move the data from S9(09) comp-3 to X (09) and move to 9(09). I am getting same error message, Please help me to find solution for this ptoblem. ERROR MESSAGE - "The system or user abend S00F R=NULL was issued."

1 Answers  


i declare a Table as OCCURS 2000 TIMES.If the input file has more than 2000 records will the COBOL program fail?

12 Answers  


Categories