KPs

From Br Wiki
Jump to: navigation, search
KPS(<file name> [,<numeric expression>])

The KPs internal function returns the byte position where the key for master file named starts. With an optional second parameter, KPS can also return the position of a section of a key when split keys are used. For example, in KPS(Afile,2), the starting position of the second section of the key is returned.

Comments and Examples

Here is an example to illustrate the use of the optional second parameter for indexes with split keys. In line 1000, file #1 is opened with a key split into three parts. This line replaces the existing master file and the existing key file with newly created empty master and key files.

1000 OPEN #1: "NAME=data,replace,recl=80,KFNAME=key,KPS=70/40/60,KLN=6/7/8", INTERNAL,OUTIN,KEYED

The optional second parameter of the KPS function specifies the key field number when there are split keys. Listed below are values that can be returned by the KPS function with the above OPEN statement for a key field composed of three separate fields:

  KPS(1) = 70
  KPS(1,1) = 70
  KPS(1,0) = 70
  KPS(1,2) = 40
  KPS(1,4) = -1
  KPS(1,3) = 60

KPS(1) returns 70 because it returns the starting position specified first for the key file. Notice that the system does not change the order of parameters; thus, even though position 40 is first physically, KPS returns these numbers according to the order in which they were specified.

The KPS function returns -1 when the file is not open or the master file has no key file. An invalid key field number will also return -1. For example, KPS(1,4) returns -1 because this file was opened with only three key fields. This result occurs whenever the specified field number is bigger than the number of fields used.

Related Functions