Cable Column

See all articles from Update April 1995
Author(s): Bill Cable
Publication: Update Magazine
Pub Details: Update April 1995
Date: April 1995
Pages: 27-29

ARCHIVE SERIES PART 20 : MORE ON LINKING DATABASES TOGETHER AND USING SEDIT

CREATING ADDRESS2_DBF and SUBSCR2_DBF

The desired fields for an address database were listed last time and now we need to create it and add a few addresses. We will call it ‘address2’ because it is an address database and the ‘2’ will make it easy to identify with our country database, gazet2. We create address2 at the ARCHIVE prompt just like we did gazet2. Flp1_ will be used as our device throughout :

 create 'flp1_address2'  logical 'a'<ENTER>  {start create}
acode$<ENTER>
date$<ENTER>
name$<ENTER>
fname$<ENTER>
street1$<ENTER>
street2$<ENTER>
city$<ENTER>
stcypv$<ENTER>
postcode$<ENTER>
ccode$<ENTER>
phone$<ENTER>
note$<ENTER>
<ENTER> {end create}
display<ENTER> {show it}
{we will add some made up addresses just so we have
some in the database to play with}
insert<ENTER> {add first address}
smith,b<ENTER> 95/05/15<ENTER> Smith<ENTER>
Bob<ENTER> PO Box 92<ENTER> <ENTER>
Cornish<ENTER> NH<ENTER> 03745<ENTER>
usame<ENTER>(603) 675-4211<ENTER><ENTER>

wilson,r<ENTER> 95/05/15<ENTER> {next one}
Wilson<ENTER>Robert<ENTER>
20 Mow Barton<ENTER><ENTER>Yate<ENTER>
Bristol<ENTER>BF17 5GF<ENTER> uking<ENTER>
(01434) 882 206<ENTER><ENTER>

baum,u<ENTER> 95/05/15<ENTER> {next one}
Baum<ENTER>Ursula<ENTER>
Im Stillen Winkel 12<ENTER><ENTER>
Duisburg<ENTER><ENTER>12133<ENTER>
germa<ENTER>0201-511247<ENTER><ENTER>

Ward,r<ENTER>95/05/15<ENTER>Ward<ENTER>
Roger<ENTER>Old Valley Road<ENTER><ENTER>
Aukland<ENTER><ENTER>32145<ENTER>
nzeal<ENTER><ENTER><ENTER>
{enter some of your own, the more the better}
<F4> {end address entry}
order acode$;a<ENTER> {set order by address code}
close<ENTER> {done with this for now}

Notice the Addresses were given an Address Code consistent with the rules mentioned last time and is our Key for looking up an Address. The Country Code field (ccode$) in Address2 matches values of the Country Code field (ccode$) in Gazet2 which is our Key for looking up Country. Now we have our Country Database (gazet2_dbf) and our Address Database (address2_dbf). We need to create our final database which will be a Subscription Database. It will keep track of subscriptions for three different newsletters we will pretend to sell – macworld, pcworld, qlworld. Creating databases containing real data is a lot of work. We just want enough data to realistically illustrate the linking of the Databases and even that is a fair amount of work. We will pretend we are in charge of keeping subscription information for these 3 newsletters. We will define the following fields in the subscription database :

Field #   Field Description          Field Name
0         Newsletter name            newsletter$
1         Subscribers address code   acode$
2         Starting Date              sdate$
3         Ending Date                edate$
4         Issues left                issues
5         Amount Paid                amt

We will call our database subscr2 to go along with gazet2 and address2. From the ARCHIVE prompt type :

 create 'flp1_subscr2'  logical 's'<ENTER>   {start create}
newsletter$<ENTER>
acode$<ENTER>
sdate$<ENTER>
edate$<ENTER>
issues<ENTER>
amt<ENTER>
<ENTER> {end create}
display<ENTER> {display record}
{we will add some pretend subscriptions}
insert<ENTER> {begin adding}
qlworld<ENTER>smith,b<ENTER>
95/05/15<ENTER>96/04/15<ENTER>
12<ENTER>15<ENTER>

pcworld<ENTER>smith,b<ENTER> {next one}
95/02/15<ENTER>96/01/15<ENTER>
12<ENTER>20<ENTER>

qlworld<ENTER>wilson,r<ENTER> {next one}
94/09/15<ENTER>96/08/15<ENTER>
24<ENTER>30<ENTER>

macworld<ENTER>baum,u<ENTER>
95/02/15<ENTER>96/01/15<ENTER>
12<ENTER>25<ENTER>

qlworld<ENTER>baum,u<ENTER>
95/05/15<ENTER>96/04/15<ENTER>
12<ENTER>15<ENTER>
pcworld<ENTER>ward,r<ENTER>
95/01/15<ENTER>95/12/15<ENTER>
12<ENTER>20<ENTER>
<F4> {end adding}
order newsletter$;a,sdate$;a<ENTER>
close<ENTER>

Notice that the Address Code in the Subscription Database matches the Address Code we set up in our Address Database. So the Address Code in the Subscription Database points to and Address in the Address Datbase which points to a Country in the Country Database and our Linking is complete. Now that we have our databases we need to be able to see information in all three databases at once.

CREATING A SCREEN FOR 3 DATABASES

ARCHIVE has several commands that can be used to print information to the screen but it also has a special Screen Builder which allows you to visually construct a screen layout using a Screen Editor (SEDIT) and then save it to load and use as needed. Although limited in power and not especially user friendly it is an example of visual programming so much the rage these days. Instead of writing code you actually move around the screen putting labels and variable values where you want them to be and then save it to use. Using an ARCHIVE Screen is probably the easiest way to display information from 3 databases simultaneously.

The instructions below will give a brief description of how SEDIT works plus exact key presses to create the screen we want. We will display the subscription database on the left and the address database in the center and the country database on the right. I will use RA to indicate right arrow. So (14RA) will mean press 14 right arrows. The arrow keys move the cursor around the screen. Typing text will enter the text exactly where the cursor is. You can’t push text around you can only overwrite places on the screen. Different colors can be used but I won’t get into that now. Pressing <F3> allows you to access the screen editing commands which includes defining areas where variable values will go. So putting the cursor where you want the variable to start and pressing <F3> and v will cause ARCHIVE to prompt for the variable name. Enter it then press the RA (right arrow) until you have defined enough space for the variable value to be displayed. You will see periods (.) fill that area. Then <ENTER> will end defining that variable area. Variables can include fields of accessed databases. I will use a special ARCHIVE technique to exactly define database field names when more than one database is accessed at once. Notice that above and when we access files below we will use logical names “g” for gazet2 and “a” for address2 and “s” for subscr2. This allows us to precisely refer to which field in which file we want. So a.ccode$ refers to the country code field in the address database and g.ccode$ refers to country code field in the country database. If more than one file is accessed at one time then only one will be active. Which is active can be switched by using the Use command (use “s” or use “a” or use “g”). The active one will not need the “.” prefix to refer to a field but all the others will. In defining the screen I will make the subscription database active and so its fields will be referred to on the screen without any prefix but the Address fields will have an “a.” prefix and the country fields will have a “g.” prefix. If you are not familiar with SEDIT I suggest you also read over that section of your ARCHIVE manual and keep it handy.

Below I will give the key presses to set up the screen. Reading them will not make much sense but as you enter them on your QL you will see on the screen what is happening and it will make sense. Basically a line at a time I am setting up 3 columns (one for each database). Each column will have a label and a field (variable). All the extra RA (right arrows) are to line up the columns or define the variable areas. Rather than carefully counting you will be able to see visually where to move to. This is a challenging exercise but if you suffer through it you will learn a lot about the screen editor before you are through.

 new<ENTER>                        {clear things out}
sedit<ENTER> {start screen editor}
(2RA)SUBSCRIPTION(11RA)ADDRESS(18RA)
COUNTRY<ENTER><ENTER>

(2RA)Newsletter(1RA)<F3>vnewsletter$<ENTER>
(9RA)<ENTER>(3RA)Addr Code(1RA)<F3>v
a.acode$<ENTER>(14RA)<ENTER>
(2RA)Cntry Code(1RA)<F3>vg.ccode$<ENTER>
(15RA)<ENTER><ENTER>

(2RA)Addr Code(2RA)<F3>vacode$<ENTER>
(9RA)<ENTER>(3RA)Date(6RA)<F3>va.date$
<ENTER>(14RA)<ENTER>(2RA)Country(4RA)
<F3>vg.country$<ENTER>(15RA)<ENTER><ENTER>

(2RA)Start Date(1RA)<F3>vsdate$<ENTER>
(9RA)<ENTER>(3RA)Name(6RA)<F3>va.name$
<ENTER>(14RA)<ENTER>(2RA)Continent(2RA)
<F3>vg.continent$<ENTER>(15RA)<ENTER><ENTER>

(2RA)End Date(3RA)<F3>vedate$<ENTER>
(9RA)<ENTER>(3RA)Frst Name(1RA)<F3>va.fname$
<ENTER>(14RA)<ENTER>(2RA)Capital(4RA)
<F3>vg.capital$<ENTER>(15RA)<ENTER><ENTER>

(2RA)Issues(5RA)<F3>vissues<ENTER>
(9RA)<ENTER>(3RA)Street1(3RA)<F3>va.street1$
<ENTER>(14RA)<ENTER>(2RA)Languages(2RA)<F3>
vg.languages$<ENTER>(15RA)<ENTER><ENTER>

(2RA)Amount(5RA)<F3>vamt<ENTER>
(9RA)<ENTER>(3RA)Street2(3RA)<F3>va.street2$
<ENTER>(14RA)<ENTER>(2RA)Currency(3RA)
<F3>vg.currency$<ENTER>(15RA)<ENTER><ENTER>

(25RA)City(6RA)<F3>va.city$<ENTER>
(14RA)<ENTER>(2RA)Population(1RA)<F3>vg.pop
<ENTER>(15RA)<ENTER><ENTER>

(25RA)St/Cy/Prv(1RA)<F3>va.stcypv$<ENTER>
(14RA)<ENTER>(2RA)GDP(8RA)<F3>vg.gdp
<ENTER>(15RA)<ENTER><ENTER>

(25RA)Postal Cd(1RA)<F3>va.postcode$<ENTER>
(14RA)<ENTER>(2RA)Area(7RA)<F3>vg.area
<ENTER>(15RA)<ENTER><ENTER>

(25RA)Cntry Cd(2RA)<F3>va.ccode$<ENTER>
(14RA)<ENTER><ENTER>

(25RA)Phone(5RA)<F3>va.phone$<ENTER>
(14RA)<ENTER><ENTER>

(25RA)Note(6RA)<F3>va.note$<ENTER>
(14RA)<ENTER><ENTER>

<ESC> {done}
ssave "flp1_sub2"<ENTER> {save it}
screen<ENTER> {look at it}
 look "flp1_subscr2" logical "s"<ENTER>

Do all the subscription fields show up? If not sedit again and make corrections where subscr2 variables are. If you have misspelled a variable name you first have to delete it by moving to it then <F3><ENTER> and then reenter it as described above. Exit and look it over again. After it is okay save it and :

 look "flp1_address2" logical "a"<ENTER>

Do all address fields with values show up. If not then correct as with subscr2 and save and then :

 look "flp1_gazet2" logical "g"<ENTER>

Do all country fields show up. If not then correct as with subscr2 and then :

 ssave "flp1_sub2"<ENTER>
close "s": close "a": close "g"<ENTER>

PLAYING WITH 3 LINKED DATABASES

We have our databases and screen defined. Now we will write a little procedure that will allow us to access and view all 3 together and they will be linked so whatever address is specified for the subscription will appear as the address and whatever country is associated with the address will appear as the country. To be really useful a more involved user interface needs to be built up but our purpose is only to illustrate how linking can work. You saved everything as suggested up to this point right?

 new<ENTER>                       {clear everything out}
edit<ENTER> {start ARCHIVE editor}
subview<ENTER> {call procedure subview}
mode 0: error close_all<ENTER>
look "flp1_subscr2" logical "s"<ENTER>
look "flp1_address2" logical "a"<ENTER>
look "flp1_gazet2" logical "g"<ENTER>
sload "flp1_sub2" : screen<ENTER>
use "s"<ENTER>
while not eof()<ENTER>
use "a" : locate s.acode$<ENTER>
use "g" : locate a.ccode$<ENTER>
use "s" : sprint<ENTER>
print "<ENTER> to view next subscription : ";<ENTER>
input ans$<ENTER>
next<ENTER>
endwhile<ENTER>
error close_all<ENTER>
mode 1:print "Done"<ENTER>
<ESC> {finished with subview procedure}
<F3>nclose_all<ENTER> {add close_all procedure}
while 1 : close : endwhile<ENTER>
<ESC> {finished with close_all procedure}
<ESC> {all done adding procedures so exit editor}
save "flp1_subview<ENTER> {save procedures}

We have our procedure ‘subview’ which will step through the subscription database and display the proper address and country for each subscription. Let us try it out.

 subview<ENTER>               {start it}
<ENTER> {continue to <ENTER> until end}

If you have no errors you will see the linked data correctly displayed. It is an interesting exercise and you can see that ARCHIVE’s multifile capabilities coupled with the ability to link databases together and efficiently display them makes for powerful data handling only limited by your imagination. In fact you will find no other structure on the QL that can do this with such relatively little programming effort. Being able to link data together and efficiently display it is a necessity for any sophisticated data handling system. Although this exercise was long and tedious most of the work involved setting up data to play with. The actual programming effort was very small. Can you imagine trying to do this with SuperBASIC. You would have to invent a complete ARCHIVE-like subsystem and why bother since has already been done.

Any of you who will be coming to the 3rd North American QL Show in Oak Ridge Tennessee on June 10th be sure to bring examples of your favorite ARCHIVE problems or solutions. I will be there and will happily discuss all things related to ARCHIVE. Next time more fun with ARCHIVE. Any suggestions are welcomed. Until then, Happy Archiving!

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.