KLn: Difference between revisions
No edit summary |
|||
Line 5: | Line 5: | ||
====Comments and Examples==== | ====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. | 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 | 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: | 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) = 21 | ||
KLN(1,1) = 6 | KLN(1,1) = 6 | ||
Line 21: | Line 23: | ||
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. | 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. | ||
====Related Functions | ====Related Functions==== | ||
*[[EXISTS]] | *[[EXISTS]] | ||
*[[FILE$]] | *[[FILE$]] | ||
Line 31: | Line 34: | ||
*[[Rec]] | *[[Rec]] | ||
*[[RLn]] | *[[RLn]] | ||
<noinclude> | <noinclude> | ||
[[Category:Internal Functions]] | [[Category:Internal Functions]] | ||
</noinclude> | </noinclude> |
Revision as of 17:57, 26 January 2012
KLn(N[,X])
The KLn internal function returns the key length in bytes for master file N. With an optional second parameter X, KLN can also return the length of a section of a key when split keys are used. When X 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.