Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

without performing any operations on a file how can i know whether it contains data or not

2 Answers  


what is the minimum number of lines a Cobol program should have to successfully compile and run

11 Answers   ABC, Societe Generale,


Can 88 level variable be declared in FD section..?

1 Answers   Infosys,


How do define dynamic array in cobol. how do you define single dimensional array and multidimensional array in your cobol?

0 Answers  


I have PS flat file with 14 records. I want to read from 4th to 9th record and want to write those 6 records (4th record to 9th record) to another PS file (output file). there is no key defined in the input file. I just want read a certain Consecutive records. can any one please give me the procedure division Coding for this. I have coded the below coding but the READ-PARA is performing only 1 time even though I have 14 records in my input file (i.e FILE-1): PROCEDURE DIVISION. A000-SECTION. MOVE 0 TO I. OPEN INPUT FILE-1. IF CHECK-KEY1 > 0 DISPLAY "OPEN ERROR FOR FILE-1, CODE IS:" CHECK-KEY1 END-IF. OPEN EXTEND NEWFILE-1 IF CHECK-KEY3 > 0 DISPLAY "OPEN ERROR FOR NEWFILE-1 COD IS" CHECK-KEY3 END-IF. PERFORM READ-PARA THRU EXIT-PARA UNTIL EOF-REC = 'YES'. DISPLAY " FINALLY OUT OF LOOP" CLOSE FILE-1 CLOSE NEWFILE-1 STOP RUN. READ-PARA. ADD 1 TO I READ FILE-1 AT END MOVE 'YES' TO EOF-REC IF I > 3 AND < 10 PERFORM WRITE-PARA ELSE DISPLAY "NOT IN RANGE" END-IF. EXIT-PARA. EXIT. WRITE-PARA. WRITE NEW-REC FROM FILE1-REC.

8 Answers   IBM,


what is the difference between occurs and occurs depending on? i dont think so there is the difference in storage..then why we should use occurs depending on?

9 Answers   TCS, Tech Mahindra,


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

2 Answers  


have in 100 records in a flat file i want to move records like 1,3,5,7,9,11,.. to Output file1 and 2,4,6,8,10,12,14 .. records moved to Output file2..Pls Provide real time answer..

5 Answers   TCS,


What are the different data types available in COBOL?

4 Answers  


Under which scenario you would go for a static call as opposed to dynamic call?

5 Answers   TCS,


What are INPUT PROCEDURE and OUTPUT PROCEDURE?

0 Answers  


Hi all, I have a following requirement to write the cobol program. I have to load the 129 variables from input sequential file which are in excel sheet to the cobol inernal table. and after loading into table i have to compare this data with the business file. here compare means controlling the data whether the format(numeric,alpha) is same in the business file and in the table??? i have the same data in input and business file. could anyone please give me any idea of the logic?// i have all the 129 different variables(129rows,1 column)is there .

4 Answers   IBM, Syntel, TCS,


Categories