Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

Key Segments

ISAM level applications define key values by specifying where to find, and how to treat each data field, or part of a data field, comprising the key. Each part of a key is called a key segment.

Once you define a Record Schema for a file, you can use it to easily define key segments. See Key Segment Modes (Key Segment Modes, /doc/ctreeplus/30863.htm) for more information.

When key segment mode SCHSEG (12) or any of its variants (USCHSEG, VSCHSEG, or UVSCHSEG) are used, the interpretation of the data is based on the underlying type found in the schema. Based on the above DODA example, a triple of the form below implies the usage of the third field, social security number (the first field is schema field zero). Since it is an unsigned integer, it will be treated as such by the index routines.

segment position = 2

segment length = 4

segment mode = 12 (SCHSEG)

The use of VSCHSEG instead of SCHSEG is rather subtle. If a fixed-length field, such as the zipcode field in the above DODA example, has a field delimiter or a length count, specifying VSCHSEG indicates that if the actual data is shorter than the segment length, pad the contents out to the full segment length. The default padding is an ASCII space character, but the SetVariableBytes() function can be used to change the padding byte. If SCHSEG is used instead, then delimiters or length counts will not be used to determine how to pad the key segment. Whatever is in the fixed-length field will be used; even if it causes “garbage” to be used beyond the actual contents. Of course, if a fixed-length field is carefully prefilled or padded, then the use of SCHSEG will not cause any problem.

The segment mode value can be modified to permit the use of alternative collating sequences or to collate the key segment in descending order. Note that these modifications apply to the segment, not the entire key. OR-ing DSCSEG into the segment mode, (or adding 16 to the segment mode), indicates descending order. OR-ing ALTSEG into the segment mode, (or adding 32 to the segment mode), indicates the use of an alternative collating sequence. Both of these modifications can be used at the same time.

Alternative collating sequences are assigned to an index file with SetAlternateSequence().