View previous topic :: View next topic
|
Author |
Message |
sudhee_rb
New User
Joined: 29 Mar 2006 Posts: 34
|
|
|
|
hi 2 all friends,
This is sudheer
I have a doubt regarding on reading a file
Can we read a file in reverse way?
Any body please clear my doubt.
thanks 4 before |
|
Back to top |
|
|
vikasc4
New User
Joined: 11 Dec 2005 Posts: 32
|
|
|
|
Hi sudheer,
Yes u can read the file in reverse way, but there is a trick.............
and the trick is just first read the file in a table and then read that table in reverse order .
The size of table can be change dynamically by defining it with DEPENDING ON CLAUSE .
Regards
Vikas |
|
Back to top |
|
|
subramanianup Warnings : 1 New User
Joined: 18 May 2005 Posts: 46 Location: Bangalore, INDIA
|
|
|
|
Hi sudheer and Vikas,
Reverse reading of file possible with some tricks.
For this you have to use SORT option, Introduce SEQNUM in that file and Sort the file in decending Order and then Remove Sequencial Nos and Now the File is in Reverse order
IN SORT
INREC FIELDS= < Here you have to INSERT Sequence No>
SORT FIELDS= < Here you have to Sort records on dec order of Seqnum>
OUTREC FIELDS = < After Sorting remove Sequence Number and write it in another file>
With Regards,
Subramanian UP |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
Back to top |
|
|
winchaat
New User
Joined: 23 Mar 2005 Posts: 14
|
|
|
|
We have to open the input file in reverse order as shown below:
OPEN INPUT file-name1 REVERSED
REVERSED positions the file at its end; subsequent READ statements retrieve the records in reversed order.
--------------->RAG |
|
Back to top |
|
|
ranga_subham
New User
Joined: 01 Jul 2005 Posts: 51
|
|
|
|
Hmm.......not able to understand what benefits would it provide? I believe it just proves one's technical capability rather than achieving any purpose. Is it worth debatable? |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Ranga, I have seen this question asked many times before, usually as part of some Interview questions.
Most of the previous posts are accurate with the answer - No, not using COBOL if the data is on DASD (QSAM or VSAM). Yes, if the data is sorted in descending order first. Yes, using COBOL if the data is on TAPE. Yes, using REXX data stacks as previously shown. And finally, Yes using COBOL with the data on DASD if run within a CICS application. |
|
Back to top |
|
|
karthik1680 Warnings : 2 New User
Joined: 14 May 2005 Posts: 64 Location: chennai
|
|
|
|
hi sudheer ,
this may help you.
open-statement
______________________________________________________________________________
| |
| >>__OPEN___________________________________________________________________> |
| <__________________________________________________________________ |
| <________________________________________________ | |
| >________INPUT____file-name______________________________________|_____|__>< |
| | |_____REVERSED___________________| | |
| | |______________NO__REWIND__| | |
| | |__WITH__| | |
| | <__________________________________________ | |
| |__OUTPUT____file-name________________________________|_______| |
| | |______________NO__REWIND__| | |
| | |__WITH__| | |
| | <____________ | |
| |__I-O____file-name__|________________________________________| |
| | <____________ | |
| |__EXTEND____file-name__|_____________________________________| |
| |
|______________________________________________________________________________| |
|
Back to top |
|
|
karthik1680 Warnings : 2 New User
Joined: 14 May 2005 Posts: 64 Location: chennai
|
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
karthik1680, I wish you had posted ALL of the information regarding the OPEN statement, especially the footnote for the REVERSED and NO REWIND parameters, as documemted here:
Quote: |
REVERSED
Valid only for sequential single-reel files. REVERSED is not valid for VSAM files.
If the concept of reels has no meaning for the storage medium (for example, a direct access device), the REVERSED and NO REWIND phrases do not apply.
|
|
|
Back to top |
|
|
|