KLN(<file name>[,<numeric expression>])
The KLn internal function returns the key length in bytes for master file specified by 'file name'. With an optional second parameter, KLN can also return the length of a section of a key when split keys are used. When the numeric expression is 2, the length 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 a key file 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.
01000 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 KLN function specifies the key field number when there are split keys. Listed below are values that can be returned by the KLN function after the above OPEN statement for a key field composed of three separate fields:
KLN(1) = 21 KLN(1,1) = 6 KLN(1,0) = 21 KLN(1,2) = 7 KLN(1,4) = -1 KLN(1,3) = 8
KLN(1) returns 21 because it returns the total combined length of the separate key fields for the key file (the key lengths of 6, 7 and 8 are added). Notice that when the second parameter is zero, the result is the same as when the second parameter is omitted. KLN(1,0) is equivalent to KLN(1).
The KLN 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, KLN(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.