KGEN() Function - Key Generate

Syntax

KGEN(str1,str2,int{,ERR=lineref})

Description

The KGEN() function derives the value of a key contained within a record.

Parameter

Description

str1

Record containing a key. This record may have been read in from an MKEYED, XKEYED or VKEYED file or built in an application program.

str2

Description of the key segments for the record contained in str1. Normally, this string is obtained from bytes (86) to the end of the FIN() of an MKEYED, XKEYED or VKEYED file.

int

Key number.

ERR=lineref

Branch to be taken if an error occurs during execution.

By default, the KGEN() function returns string values that can be directly compared across records to produce the correct sorting sequence. If the key definition contains field modifications ("B", "D", "I", "N", "U"), this raw string might not correspond to the value returned by the KEY() function. To generate a value that corresponds to the KEY() function, add 256 to the desired key number.

NOTE: If str1 does not contain enough data, or the format of the data is not as the combination of str2 and int describes, an error will be generated. Additional errors may be generated if str2 is not formed correctly or int is not a key in str2.

Examples

erase "mkeyed.dat",err=mkeyed
mkeyed:
mkeyed "mkeyed.dat",[1:1:1:"D"],[2:1:1],80,1000
mk=unt
open (mk)"mkeyed.dat"
fid$=fid(mk),fin$=fin(mk)
for rec=0 to 9
    f1$=chr(asc("A")+rec),f2$=str(rec),rec$=f1$+$0a$+f2$+$0a$
    write record (mk,dir=0)rec$
    k$=key(mk)
    k0$=kgen(rec$,fin$(86),0)
    k256$=kgen(rec$,fin$(86),0+256)
    k1$=kgen(rec$,fin$(86),1)
    k257$=kgen(rec$,fin$(86),1+256)
    print "key='",k$,"',kgen(0)='",k0$,"'=$",hta(k0$),"$,kgen(0+256)='",
    print k256$,"','kgen(1)='",k1$,"',kgen(1+256)='",k257$,"'"
next rec
end

See Also

XKGEN() Function