Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cobol - how to START and READ PRIOR the last record in a keyed file

2,107 views
Skip to first unread message

Bob Lepp

unread,
Jan 24, 2001, 1:37:06 PM1/24/01
to
Never had to do this before....

Can someone advise how to position a file so the last record in keyed
sequence can be read in Cobol?

I've tried START with a key value higher than the last actual key on file
with teh ntent to READ PRIOR after that, but you get INVALID KEY.

START allows only 'equal to' or 'greater or equal to', there is no 'less
than or equal to' so every attempted START fails with no valid record
position.

I hope it's something stupid I'm missing.

Thanks!

Bob


Peter Schalber

unread,
Jan 24, 2001, 2:43:29 PM1/24/01
to
 

Bob Lepp schrieb:

> Never had to do this before....
>
> Can someone advise how to position a file so the last record in keyed
> sequence can be read in Cobol?
>  

READ PRIOR ....
IF NO-RECORD
    READ LAST .....
END-IF
 

Charles R. Pence

unread,
Jan 24, 2001, 3:09:24 PM1/24/01
to

If this is something for just after open of the file, both OVRDBF and
POSDBF can give this. Examples:
> OVRDBF FILE(THEFILE) TOFILE(*FILE) POSITION(*KEYBE) SHARE(*YES)
POSITION(*KEYBE 2 KEYEDFMT 'LARGEST KEY VALUE PLUS THE CHARACTER X')
/* If the key value is replaced by a variable name, it is best declared
one larger than the key length, and have a non-blank as the last byte */

> OVRDBF KEYEDFILE *FILE SHARE(*YES)
> OPNDBF KEYEDFILE *INP ACCPTH(*FILE)
> POSDBF KEYEDFILE *END

The latter method can be used at any time after open, repeatedly using the
POSDBF to establish position, given the shared open.

http://publib.boulder.ibm.com:80/cgi-bin/bookmgr/BOOKS/QB3AG302/6.1.7.7.4#HDRFILEPOS
notes an extension for "dynamic access" using READ LAST. This may accomplish above
for a keyed open.

Regards, Chuck
All comments provided "as is" with no warranties of any kind whatsoever.

Bob Lepp

unread,
Jan 24, 2001, 6:48:58 PM1/24/01
to
Turns out I needed the READ .... FIRST RECORD, or READ... LAST RECORD, not
the START statement.
Thanks to the helpers!
Bob

Charles R. Pence <crp...@vnet.ibm.com> wrote in message
news:3A6F3674...@vnet.ibm.com...

0 new messages