Skip to content

PKY

Previous Key

This string function returns the previous key value in a DIRECT or SORT file without changing the current key pointer.

PKY (channel [, SRT=sort-name] [, END=line-ref]
[,ERR=line-ref|,ERC=error-code])
channel
is an integer in the range of 0 to 32764 specifying the channel of an OPEN DIRECT or SORT file. If omitted, the default is 0.
sort-name
is any string of 20 characters or fewer that specifies the name of a sort sequence in an MSORT file; if not specified, the current sort sequence is used. Specifying a sort-name other than the current sort sequence does not change the current sort sequence for [P]READ and [P]EXTRACT.
line-ref
is the program line number or label to branch to if the file is empty (END=) or an error is produced by this function (ERR=).
error-code
is a programmer-defined error code. Valid values are positive or negative whole numbers.

The SRT= option is only valid for MSORT files. Specifying SRT= does not alter the currently active sort key for [P]READ and [P]EXTRACT, but provides the ability to obtain the values for other sort keys from the next sequential record based on PKY.

If an attempt is made to find PKY on a channel that is not OPEN, an ERR=14 results.

If an attempt is made to find PKY on a channel that is OPEN to a file that is not a key-access file, an ERR=13 results.

If an attempt is made to find PKY on a channel that is OPEN to a file with no data, an
ERR=2 (end of file) results.

The PKY of a key-access file is the key whose value is next lowest in collating sequence to the current key in that file.

LET PREVIOUS_KEY$ = PKY (1, ERR=01000, END=02000)

places the key for the file OPEN on channel 1 with the next lowest collating sequence in PREVIOUS_KEY$, branches to program line number 02000 if the file is empty, and branches to statement 01000 if any error other than ERR=2 (end of file) results.

FKY, KEY, and LKY functions

From the Thoroughbred Basic Language Reference, Volume II: F–Q, version 8.9.1. Open this page in the PDF