FATS - Fast Access Tree System
Table of Contents
Programming Interfaces
MS-Basic for OS/2


The  FATS matchcode commands create a full-text index with the content of your data tables or -files.
Every word and every number is incorporated into the index, an "inverted list" is generated.

This index enables FATS to find each data record by specification of any terms in fractions of a second.

The following Microsoft Basic example demonstrates the use of the FATS matchcode commands:

PRINT "This program needs the extended version of FATS (FATSX.OBJ or FATSXO16.DLL)"
PRINT
PRINT "Up to version 6.0 of the basic compiler all strings were administered"
PRINT "in the data segment of the application. Starting from the version 7.0"
PRINT "the entire memory can be used by strings (compiler flag /Fs)."
PRINT
PRINT "To compile and link the test program, use ONE of the following methods:"
PRINT
PRINT "  1. METHOD: Linking FATS to the program"
PRINT
PRINT "     BC MCSORT /Lp"
PRINT "     LINK MCSORT fatsx.obj fats_mb6.obj"
PRINT
PRINT "    or if you use Far-Strings:"
PRINT
PRINT "     BC MCSORT /Lp /Fs"
PRINT "     LINK MCSORT fatsx.obj fats_mb7.obj"
PRINT
PRINT "  2. METHOD: Calling the Dynamic Link Library"
PRINT
PRINT "     BC MCSORT /Lp"
PRINT "     LINK MCSORT fatsmb6d.obj fatsxo16.lib      (call FATSXO16.DLL)"
PRINT
PRINT "    or with Far-Strings:"
PRINT
PRINT "     BC MCSORT /Lp /Fs"
PRINT "     LINK MCSORT fatsmb7d.obj fatsxo16.lib"
PRINT
INPUT "Please press the [ENTER] key ...", X$
PRINT


REM  -------> Activation of Network Operation
REM
REM  FATS is standardly equiped for the network environment.
REM  Nearly all commands can be executed both in single workstation
REM  and network environment. With the  "Y" Auto Refresh command you
REM  determine the behavior of FATS accessing all index files.
REM  Normally it is sufficient to apply this instruction one time at
REM  the program start whereby the specified access mode will apply
REM  to all coming opened files, i.e. they are accessed either with
REM  network (Y\2) or single workstation access (Y\0).

CALL FATSBASIC("Y\2", ERRORCODE%, RECNO&, KEYLEN%)


REM  -------> Open data file

PRINT "Opening data file ..."

OPEN "R", #1, "CUSTOMER.DAT", 128
FIELD #1, 1 AS DELETEDMARK$,_
          5 AS CUSTID$,_
         25 AS NAME$,_
         25 AS JOB$,_
         25 AS STREET$,_
          5 AS ZIP$,_
         20 AS CITY$


REM  -------> Opening key file

CALL FATSBASIC("O\CUSTOMER.KEY\2", ERRORCODE%, RECNO&, KEYLEN%)
IF ERRORCODE% <> 0 THEN

  PRINT
  PRINT "Error opening the file CUSTOMER.KEY"
  PRINT "Please create the file using the test programs"
  PRINT "TST0_ENG.BAS or TST1_ENG.BAS"

  GOTO ENDE

END IF


REM  ========================================================================
REM            Creating Matchcode Index
REM  ========================================================================


REM  -------> Creating Matchcode Index File
REM
REM  With the command  "MC" Create Matchcode File, the most important
REM  query facilities are determined already while creating the
REM  matchcode index file. With the search-group flag ("I#"), several
REM  logically related data columns can be registered in a common index
REM  so that a query to this index resp. search group extends automatically
REM  over all these columns. A matchcode file manages up to 32 search
REM  groups that can be used for joined queries (using the "AND"-operator).
REM
REM  In this example the following search groups are defined:
REM
REM    Search Group    Fields
REM
REM        I1          NAME
REM        I2          JOB
REM        I3          ZIP & CITY
REM
REM  The syntax of the command string:
REM
REM    szCmnd = "MC\{FileName}\{Flags}\{FileNo}\{Col1def}[\{Col2def}]"
REM
REM      FileName   Filename, perhaps with an additional path
REM                 (i.e. C:/DATA/CUSTOMER.FMS or CUSTOMER.FMS)
REM
REM      Flags      Reserved, not used at the moment
REM
REM      FileNo     File number
REM
REM      Col#def    Definition of data column # (flags, separated by comma).
REM                 The content of the corresponding data columns is transferred
REM                 the commands "MB", "MI" and "MD" later in the order determined
REM                 by this command.
REM
REM                 I#  The content of the data column becomes part of search
REM                     group #. You can combine several columns into a logical
REM                     search group (e.g. first name, surname).
REM
REM                 C   The content of the data column is edited for word overall
REM                     searching, i.e. a search for "motorca" e.g. finds
REM                     "motorcar" and "motor caravan".
REM
REM                 N   Numbers are handled as words, i.e. during a search
REM                     according to "150", "12150" e.g. is also found.
REM
REM               K#:#  This switch activates the management of a primary key
REM                     for this matchcode index file. The first value after
REM                     the 'K' is the position of the data column within the
REM                     key (1 == first part), the second value specifies the
REM                     length of the data column valid as the key.
REM
REM                 Further adjustments are possible and described in detail
REM                 in the user manual.

PRINT
PRINT "Creating matchcode index file ..."

CALL FATSBASIC("MC\CUSTSORT.FTS\\1\K1:5\I1\I2\I3", ERRORCODE%, RECNO&, KEYLEN%)
IF ERRORCODE% <> 0 THEN

  REM
  REM  "MC\{Filename}\\{FileNo}\K#:#\I1\I2\I3"
  REM
  REM  The flag K#:# enables the management of a primary key within
  REM  the matchcode file. FATS normaly only uses the record number
  REM  during the generation of a result set. In specific situations,
  REM  if e.g. the physical record number is not known, or does not
  REM  correspond to the ID specified with the MB-command, the generation
  REM  of a primary key becomes necessary. The browser commands then also
  REM  make in addition to the record- or ID-number this key available via
  REM  the FATSKEY-variable to the application.
  REM
  REM  With the use of this flag, FATS generates a supplementary file with
  REM  the file extension .FMK which is used for the sequential storage of
  REM  the key.

  PRINT
  PRINT "FATS errorcode: "; ERRORCODE%; " (command: MC)"
  GOTO ENDE

END IF

REM  -------> Insert text into the matchcode index
REM
REM  After the matchcode file was generated, the content of the
REM  data columns may be with the command  "MB" Build Matchcode
REM  inserted into the matchcode index. The position of the
REM  data columns within the command string ("Col#data") corresponds
REM  to that with the call of command Create Matchcode File ("MC")
REM  determined definition.
REM
REM  The syntax of the command string:
REM
REM    szCmnd = "MB\{FileNo}\{RecNo}\{Col1data}[\{Col2data}[\{Col3data}]]"
REM
REM      FileNo     File number
REM
REM      RecNo      <> 0 Record- resp. id-number
REM                 == 0 Stop Build, no more records
REM
REM      Col#data   Content of data column #
REM
REM
REM  The following sample program code indexes contents of the
REM  entire data file within a loop:

PRINT
PRINT "Building matchcode index in sorted order"
PRINT
INPUT "Please press the [ENTER] key ...", X$

CURRECNO& = 0
CMND$ = "F\2\2"

REM

DO

  CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)

  IF ERRORCODE% = 0 THEN

    GET #1, RECNO&

    CURRECNO& = CURRECNO& + 1

    CMND$ = "MB\1\" + STR$(CURRECNO&)

    REM  Add the primary key to the command string

    CMND$ = CMND$ + "\" + RTRIM$(CUSTID$)

      CMND$ = CMND$ + "\" + RTRIM$(NAME$)
      CMND$ = CMND$ + "\" + RTRIM$(JOB$)
      CMND$ = CMND$ + "\" + RTRIM$(ZIP$ + " " + CITY$)

    CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)

    IF ERRORCODE% <> 0 THEN

      REM  If an error occurred during the execution of the "MB" command,
      REM  the matchcode index file is already closed by FATS.

      PRINT "FATS errorcode: "; ERRORCODE%; " (command: MB)"
      EXIT DO
    END IF

    PRINT "  "; NAME$; " --> RecNo "; CURRECNO&

    CMND$ = "N\2"

  ELSE

    REM  After the last record was inserted the creating process
    REM  has to be terminated with the command "MB\{FileNo}\0".
    REM  Because this command closes the matchcode index file you don't
    REM  have to do a close command.

    CALL FATSBASIC("MB\1\0", ERRORCODE%, RECNO&, KEYLEN%)
    EXIT DO

  END IF

LOOP WHILE NOT ERRORCODE%


REM  ========================================================================
REM            Matchcode Search
REM  ========================================================================


REM  -------> Open matchcode index file
REM
REM  With the command  "O" Open Indexfile you open an existing
REM  matchcode index file with the opening flags defined with
REM  the command  "Y" Auto Refresh. After the file was opened
REM  it can be accessed under the file number you specified.

CALL FATSBASIC("O\CUSTSORT.FTS\1", ERRORCODE%, RECNO&, KEYLEN%)


REM  -------> Search in Search-Group 1 (NAME)
REM
REM

PRINT
PRINT "We now search for all customers with the first name Michael."
PRINT
INPUT "Please press the [ENTER] key ...", X$
PRINT

CMND$ = "MS\1\\0\michael"

DO

  CALL FATSBASIC(CMND$, ERRORCODE%, HITID&, KEYLEN%)
  IF ERRORCODE% <> 0 THEN EXIT DO

  REM

  FATSKEY$ = SPACE$(KEYLEN%)
  CALL FATSGETKEY(FATSKEY$)

  CMND$ = "S\1\2\" + FATSKEY$
  CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)
  IF ERRORCODE% <> 0 THEN EXIT DO

  GET #1, RECNO&
  PRINT NAME$; " | "; JOB$
  PRINT ZIP$; " "; CITY$; " (#"; RECNO&; ")"
  PRINT

  CMND$ = "MA\1\" + STR$(HITID&)

LOOP WHILE NOT ERRORCODE%


REM  --------> Close all fats files

CALL FATSBASIC("K", ERRORCODE%, RECNO&, KEYLEN%)

ENDE:

CLOSE #1

© 2008  GCS Software, Udo Gertz