XKGEN() Function

Syntax

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

Description

In BBj 3.0 and higher, the XKGEN() 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 XFIN() 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 XKGEN() 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.

Example

0010 erase "xkeyed.dat",err=*next
0020 xkeyed "xkeyed.dat",[1:1:1],[2:1:1],80,1000
0030 xk=unt
0040 open (xk)"xkeyed.dat"
0050 fid$=fid(xk),fin$=fin(xk)
0060 xfid$=xfid(xk),xfin$=xfin(xk)
0070 for rec=0 to 9
0080 f1$=chr(asc("A")+rec),f2$=str(rec),rec$=f1$+$0a$+f2$+$0a$
0090 write record (xk,dir=0)rec$
0100 k0$=kgen(rec$,fin$(86),0)
0110 xk0$=xkgen(rec$,xfin$(86),0)
0120 if k0$<>xk0$ then escape
0130 print k0$,":",xk0$
0140 k1$=kgen(rec$,fin$(86),1)
0150 xk1$=xkgen(rec$,xfin$(86),1)
0160 if k1$<>xk1$ then escape
0170 print k1$,":",xk1$
0180 next rec
0190 print "ok"
0200 end

See Also

KGEN() Function - Key Generate