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:

 "C" Create Indexfile
(Creates a index file with the specified characteristics.)
 "O" Open Indexfile
(Makes a index file available for access.)
 "K" Close Indexfile
(Releases a index file from availability.)
 "I" Insert Record
(Insert a new record.)
 "F" Search First
(Gets the key value and record number of the data record with the first key value.)
 "L" Search Last
(Gets the key value and record number of the data record with the last key value.)
 "N" Search Next
(Gets the key value and record number of the data record following the current record.)
 "A" Search Next After
(Gets the key value and record number of the data record whose key value is greater than the requested key value.)
 "E" Search Previous Before
(Gets the key value and record number of the data record whose key value is less than the requested key value.)
 "Y" Auto Refresh
(Specifies file locking and cache modes in single- and multi-user environments.)

PRINT "This Test Program was designed for Microsoft Basic"
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 (FAR-Strings)"
PRINT
PRINT "     BC tst1eng7 /Lp /Fs"
PRINT "     LINK tst1eng7 fats.obj fats_mb7.obj"
PRINT
PRINT "     or if you own the extended version of FATS:"
PRINT
PRINT "     LINK tst1eng7 fatsx.obj fats_mb7.obj"
PRINT
PRINT "  2. METHOD: Calling the Dynamic Link Library"
PRINT
PRINT "     BC tst1eng7 /Lp /Fs"
PRINT "     LINK tst1eng7 fatsmb7d.obj fats_o16.lib     (call FATS_O16.DLL)"
PRINT
PRINT "     or if you own the extended version of FATS:"
PRINT
PRINT "     LINK tst1eng7 fatsmb7d.obj fatsxo16.lib     (call FATSXO16.DLL)"
PRINT
INPUT "Please press the [ENTER] key ...", X$
PRINT

REM  -------> open file with test data

OPEN "R", #1, "..\..\..\DEMODATA\CUSTOMER.ASC", 105
FIELD #1, 5 AS F1$, 25 AS F2$, 25 AS F3$, 25 AS F4$, 5 AS F5$, 20 AS F6$

REM  -------> create data file

PRINT "Creating Data File ..."

OPEN "R", #2, "CUSTOMER.DAT", 128
FIELD #2, 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

PRINT "Creating Index File ..."

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

REM  -------> insert records

PRINT
PRINT "290 records will be inserted into the data file."
PRINT "For each record 4 keys will be stored in the index file"
PRINT
INPUT "Please press the [ENTER] key ...", X$

FOR X=1 TO 290
  GET #1,X
  LSET DELETEDMARK$=" "
  LSET CUSTID$=F1$
  LSET NAME$=F2$
  LSET JOB$=F3$
  LSET STREET$=F4$
  LSET ZIP$=F5$
  LSET CITY$=F6$
  CMND$="I\1\"+RTRIM$(CUSTID$)+"\"+RTRIM$(NAME$)+"\"+RTRIM$(JOB$)+"\"+RTRIM$(ZIP$+CITY$)
  CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)
  IF ERRORCODE% <> 0 GOTO ENDE
  PRINT NAME$;" --> RecNo ";RECNO&
  PUT #2,RECNO&
NEXT X

CLOSE #1

REM  -------> print all customers, sorted in ascending order by NAME

PRINT
PRINT "This list shows some fields from the Customer Table,"
PRINT "sorted in ascending alphabetical order on the Customer's"
PRINT "surname and forename."
PRINT
INPUT "Please press the [ENTER] key ...", X$

CMND$="F\2\1"
LOOP1:
  CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)
  IF ERRORCODE% <> 0 GOTO LABEL1
  FATSKEY$=SPACE$(KEYLEN%)
  CALL FATSGETKEY(FATSKEY$)
  GET #2,RECNO&
  PRINT NAME$;" ";JOB$;" --> RecNo ";RECNO&
  CMND$="A\2\"+STR$(RECNO&)+"\1\"+FATSKEY$
  GOTO LOOP1
LABEL1:

REM  -------> print all customers, sorted in ascending order by JOB

PRINT
PRINT "Two columns - JOB and NAME are displayed, sorted in ascending"
PRINT "order by the JOB field."
PRINT
INPUT "Please press the [ENTER] key ...", X$

CMND$="F\3\1"
LOOP2:
  CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)
  IF ERRORCODE% <> 0 GOTO LABEL2
  GET #2,RECNO&
  PRINT JOB$;" ";NAME$;" --> RecNo ";RECNO&
  CMND$="N\1"
  GOTO LOOP2
LABEL2:

REM  -------> print list with records sorted by ZIP and CITY

PRINT
PRINT "Three columns - ZIP, CITY and NAME are displayed, sorted in"
PRINT "descending order by ZIP then CITY."
PRINT
INPUT "Please press the [ENTER] key ...", X$

CMND$="L\4\1"
LOOP3:
  CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)
  IF ERRORCODE% <> 0 GOTO LABEL3
  FATSKEY$=SPACE$(KEYLEN%)
  CALL FATSGETKEY(FATSKEY$)
  GET #2,RECNO&
  PRINT ZIP$;" ";CITY$;" ";NAME$;" --> RecNo ";RECNO&
  CMND$="E\4\"+STR$(RECNO&)+"\1\"+FATSKEY$
  GOTO LOOP3
LABEL3:

ENDE:

REM  -------> close index file

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

CLOSE #2
END

© 2008  GCS Software, Udo Gertz