Automating TABLES
Database programs such as dBASE and Paradox allow the automated
processing of tables one record at a time. This is also possible in
TABLES using SML (for a series of introductory and advanced articles on
SML programming, see "SML Programming" under ArcTips). For example, let's imagine a
table named TABLE1 which has an item named CODE; values in item CODE
have the format "1234-5678". The following SML, when executed in
TABLES, will remove the hyphen from each entry, resulting in the format
"12345678":
&rem **** extract number of records
&value -19 WKSP
&openw %-19t$dir.lis
DIR TABLE1
&closew
&open %-19t$dir.lis error
&read -1 error
&read -1 error
&close
&extract -11 -1 2
& DEL %-19t$dir.lis
SEL TABLE1
&rem **** set up cursor loop
&sv -9 1
&label while
RES $RECNO IN {%-9}
MOVE CODE TO -1
&value -2 -1 1 %
&value -3 -1 %
&sv -4 %-2%-3
MOVE '%-4' TO CODE
ASEL
&cv -9 %-9 + 1
&goback while &if &rn %-9 1 %-11
&label end
&return
&rem **** I/O error trap
&label error
&type "I/O Error"
&close
&return
In the first part of the routine, the total number of records is
determined by reading a DIR entry for TABLE1. TABLE1 is then selected,
and each record reselected by $RECNO. The SML variable -1 is set equal
to the value of CODE. Variable -4 is set equal to the value without the
hyphen, and that value is substituted back into CODE.