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


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

REM   FATS 02.30
REM   (c) GCS Software, Udo Gertz 1993-1998
REM
REM   Test program (Microsoft Basic / Quick Basic Compiler)
REM 
REM   Fast Re-Indexing with the command "XB"
REM   This program needs the extended version of FATS
REM
REM   19-03-2009 U.Gertz


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  -------> Create index file


REM   "C" Create Indexfile
REM
REM  With this command you create an index file, whereby a possibly
REM  already existing file with the same name is deleted.
REM  After the file is created it will be opened with the opening
REM  flags defined with the command  Auto Refresh (Y) and can be
REM  accessed under the file number you specified.
REM
REM  Max. 200 primary keys per data record can be administered in an
REM  index file, the max. key length amounts to 240 characters.
REM
REM  Full path names must be specified using forward slashes (/)
REM  instead of Backslashes (\), because FATS normally uses the
REM  Backslash character as delimiter.
REM  You may change the delimiters by placing the desired character
REM  as the first character of the command string,
REM  e.g. szCmnd = "&C&C:\ARTICLES.KEY&1&1&A&1". Any character with
REM  an Ascii code less then 48 will be accepted.
REM
REM  The syntax of the command string:
REM
REM    szCmnd = "C\{Filename}\{KeyLength}\{KeyCount}\{KeyType}\{FileNo}"
REM
REM      FileName   filename, perhaps with an additional path
REM                 (e.g. C:/DATA/ARTICLES.KEY or ARTICLES.KEY)
REM
REM      KeyLength  Maximum key length (1-250)
REM                 If you choose to have more than one key for
REM                 this index file, you may specify the length
REM                 for each key (separated by a semicolon ";")
REM                 to conserve diskette space.
REM                 Otherwise, the maximum length applies to all
REM                 keys, i.e. every key will occupy the maximum
REM                 space.
REM
REM      KeyCount   Number of primary keys (1-200)
REM
REM      KeyType    Key type (A = Ascii text, I = Integer)
REM
REM      FileNo     File number (1-40)


CALL FATSBASIC( "C\CUSTOMER.KEY\5;25\4\A\1", ERRORCODE%, RECNO&, KEYLEN% )
IF ERRORCODE% <> 0 THEN

  PRINT
  PRINT "FATS errorcode: "; ERRORCODE%; " (command: C)"

  GOTO ENDE

END IF


REM  ========================================================================
REM            Re-Indexing
REM  ========================================================================

RECORDS& = 0

DO

  GET #1, RECORDS& + 1

  IF EOF(1) THEN

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

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

  END IF

  RECORDS& = RECORDS& + 1

  IF DELETEDMARK$ = " " THEN

    REM   "XB" Re-Indexing: Build
    REM
    REM  This command inserts the primary keys of the specified
    REM  data record ("RecNo") into the index file. The number
    REM  of keys included in the command string must equal the
    REM  number of primary keys you specified in the "C" command.
    REM
    REM  Use this command to insert the keys of all data records
    REM  into the index after a successful "Create Indexfile" (C)
    REM  command within a programme loop. The command only can be
    REM  used during the re-indexing phase, i.e. immediately
    REM  according to a call of the "C"-command.
    REM
    REM  The command "XB\{FileNo}\0" terminates re-indexing and
    REM  closes the corresponding index file. The file is closed
    REM  automatically in the case of a premature abnormal
    REM  termination of indexing. A subsequent close-command can
    REM  always remain undone.
    REM
    REM  The length of the transferred keys may not exceed the
    REM  maximum key length specified with the "Create Indexfile"
    REM  command. Variable length keys will be padded with the Ascii
    REM  char 0 to the maximum key length.
    REM
    REM  The syntax of the command string:
    REM
    REM    szCmnd = "XB\{FileNo}\{RecNo}\{KeyStr1}[\{KeyStr2}]"
    REM
    REM      FileNo     File number
    REM
    REM      RecNo      <> 0 Record Number
    REM                 == 0 Stop Re-Indexing
    REM
    REM      KeyStr#    Key value

    CMND$ = "XB\1\" + STR$(RECORDS&) + "\"
    CMND$ = CMND$ + RTRIM$(CUSTID$) + "\" + RTRIM$(NAME$) + "\" + RTRIM$(JOB$) + "\" + RTRIM$(ZIP$ + CITY$)

  ELSE

    REM  Add the data record to the list of deleted records.

    CMND$ = "DL\" + STR$(RECORDS&) + "\S\1"

  END IF

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

LOOP WHILE NOT EOF(1)

ENDE:


CLOSE #1

END

© 2008  GCS Software, Udo Gertz