Putting it all together (part 1 of 4)
Here's a short example that will demonstrate how all the notions
in this section work together.
It will also give you an excellent idea of how simple it is to
use ADB by comparison to SQL or a compiled excutable. I'll be
building on this example after I describe ADB in detail.
(Think of this as a "preview.")
Let's assume that the project file suffix is "xx".
We have two input files in this example: Cust.xx and Invoice.xx.
The first is our customer master, and the second is for invoices.
Here's the global defintions file, which will define all the
fields and the layouts.
Note that both the pound sign and the exclamation point are for
"line comments." (You can also use a slash.)
I've simply chosen to use them in a stylistic manner.
Similarly, I've decided to use semicolons to separate fields in a
file layout, and commas to do so for sort keys.
However, this is also a stylistic decision that I've made.
Spaces and/or tabs may also be used.
To distinguish reserved words from values, I've capitalized
the reserved words.
# Customer Master fields: customer name, balance and #
FLD Cust_No_ 9 ! Integer (8/9 digits)
FLD Cust_Name 25 ! A regular string field
FLD Cust_Balance__ 12 2 ! Fixed decimal: -00000000.00
# Layout of the customer master file, and the sort key
FSET Cust_Mast Cust_No_; Cust_Name; Cust_Balance__ END
FSET Cust_Srt Cust_No_ END
# Invoice fields: invoice #, date, amount and cust#
FLD Inv_No 10 ! A regular string field
FLD Inv_Date___ 10 ! Date field from the DMBS
FLD Inv_Amnt__ 12 2 ! Fixed decimal: -00000000.00
FLD Inv_Cust_No_ 9 ! Integer (8/9 digits)
# Layout of the invoice sort key, and invoice file:
FSET Inv_Srt Inv_Cust_No, Inv_No END
FSET Invoice @Inv_Srt; Inv_Amt; Inv_Date; END
Note that @-sign preceeding "Inv_Srt" in the "Invoice" FSET.
What this means is that the fields from the field set "Inv_Srt"
have been included in the field set "Invoice". I.e. the field set
"Invoice" contains the fields: Inv_Cust_No, Inv_No, Inv_Amt, and
Inv_Date (in that order).
Because you can use the "@" prefix on a field set name to
incorporate an entire group of fields, you'll have very little
trouble maintaining consistent file layouts (when field lengths
or types change). If you're a C/C++ programmer, you can think of
"@" as a kind of "#include" (except one that's useful for fields).
Why do some fields have underscores after their names? These
actually determine the field type. For now, don't worry about
their significance: just use the remarks on the right as your
guide.
Now if you're used to programming in any language, you'll
recognize FSET as a kind of record layout. It's not a file name
in the sense that it's associated with a specific physical file.
Instead, FSET defines structure.
But because ADB always sorts in an increasing and a
case-INsensitive
manner, an FSET can also be used to declare a
sort sequence.
So I've named the sort FSET in each pair with the suffix "_Srt"
and used commas instead of semicolons to delimit the fields (in
order to remind the reader that I do intend to use the second
FSET in each pair in a different way.)
Again, that's a purely "stylistic" decision on my part. ADB
won't know the difference between an FSET used as a file record
declaration (AKA "layout" or "struct") and one used as a sort key
declaration--not until I actually put those FSETs to work.
And in fact there's no reason why I can't sort a file on every
field within it (provided it has no more than 15 fields).
Let me remind you again that everything above would probably go
in your global definitions file.
Why? Because chances are that the customer master and the
invoice file are both used for many other jobs (processes).
Return
to local table of contents
Return
to global table of contents
Frames mode, or
No frames