Page 1 of 1

Read the file from bottom.

PostPosted: Tue Jan 01, 2013 11:58 pm
by Viswanathchandru
Dear all,

I need clues to read a file from bottom. I tried but I'm struck in this. My code goes like this(Aimed to read the last six records but it didn't obviously it wont)

""EXECIO * DISKR INDD(STEM XEM."
DO IX = XEM.0 TO 6 BY -1 "
.


I'm not able to find how to read the last 6 records of a file. I'm confused to resolve this "DO IX=XEM.0 TO "y" BY -1" I don't know what should be the value of "y". Any suggestions will be helpful.

Regards,
Viswa

Re: Read the file from bottom.

PostPosted: Wed Jan 02, 2013 12:58 am
by Viswanathchandru
Dear all,

I assume it is not possible to read a file in reverse. googled landed in sort :) finally a way out! Thanks all ..

Wishing you all a very happy and prosperous New year :)

Regards,
Viswa

Re: Read the file from bottom.

PostPosted: Wed Jan 02, 2013 2:51 am
by enrico-sorichetti
just for the sake of proper logic ...
( very basic math ... after all :mrgreen: )

since You have everything in a stem ( logically equal to an array )
it should not have been that difficult to conclude that
being N the number of elements of the array
the last K entries go from N-K+1 to N

and ...
do i = N to N-K+1 by -1

will process <backwards>

while
do i = N-K+1 to N

will process <forward>

any recent version of <SORT> should support the SUBSET clause
extracting in quite a sophisticated fashion any number of record

Re: Read the file from bottom.

PostPosted: Wed Jan 02, 2013 4:07 pm
by NicC
Just a quick correction on terminology - you do not read a file from the 'bottom' but from the end. ISPF may display a file file from top-to-bottom but you conceptually process a file from start-to-end, left-to-right. Weird? Maybe, but after so many years of looking at diagrams of files in books it is strange to think about proessing top-to-bottom when all the diagrams are left-to-right.