System Functions
KGN( ) Generate Record Ke y
   
Format KGN([ext_key$],data$,key_def$,key_num [ , SEP=sepchar$ ] [,ERR=stmtref])

Where:

ext_key$ Value of the external key. Optional. String expression.
data$ Contents of the data record. String expression.
key_def$ Key definition structure. String expression. This can be extracted using the FIB( ) function at position 85 (in native ProvideX mode) or using the FIN( ) function at position 86 for a length of 385 (in BBx emulation mode.)
key_num Key number (primary or an alternate key) to extract. Numeric expression - Base 0 (primary key=0, 1st secondasry=1, etc..).
sepchar$ The separator character to be used in the parsing of data$. If omitted the system separator is used or the Dynamic field sepator logic is applied if enabled.
sepchar is a
+PxPlus Exclusive
stmtref Program line number or statement label to which to transfer control.
   
Returns Key of record in file, given the record's contents.
   
Description The KGN( ) function returns a string comprising the key of the record provided. This function can be used to determine the value of an alternate (or primary) key of a record, given the record's contents (and external key, if present).

When comparing keys with descending segments, an application can specify the key number as a negative value. In this case, the descending segments will be inverted so that a logical compare will function properly.

   
Example 0010 OPEN (13)"Cstfile"
0020 IF PRM('BX')=0 THEN X$=MID(FIB(13),85) ELSE X$=MID(FIN(13),86,385)
0030 K$=KEY(13,END=0070)
0040 READ RECORD (13,KEY=K$)R$
0050 PRINT "Key: ",K$," Alt: ",KGN(K$,R$,X$,1)
0060 GOTO 0030
0070 PRINT "End-of-file"
0080 END