Suprtool

Suprtool Coding Tips

Neil Armstrong

Suprtool is not only a database tool, but is also a language. Like any "programming" language there are things you can do to improve the readability of the scripts you are writing.

Suprtool does very little work when accepting commands. It does syntactic checking and some semantic checking of the commands, but Suprtool does very little work until you "xeq" the task or exit. (The Table command is the exception to this rule as it may have to read and sort a file to fill the table!)

Here is some sample bad code (although it is syntactically correct, the ordering of the commands does not make the logic clear):

  base mytest,5
  table mytable,order-number,file,myords
  get mydataset
  item order-date,date,ccyymmdd
  output myfile,link
  sort order-number
  ext order-number
  if order-date=$today(-1) and $lookup(mytable,order-number)
  sort order-date
  ext order-quantity,order-ctgy
  ext order-description
  ext order-dollars
  ext order-tax
  xeq
  exit

Writing good Suprtool code can be achieved by simply dividing up commands into some simple categories.

These categories are:

  1. Source of Records
  2. Selection of records
  3. Order of records
  4. Fields for output
  5. Optional Steps
  6. Destination of records
In the Suprtool course there is one slide that I always tell student to mark as the most important slide in the course, as it clearly outlines the commands and what they are for.

So applying this slide to the previous code we would get the following:

  base mytest,5
  get mydataset
  
  table mytable,order-number,file,myords
  item order-date,date,ccyymmdd
  if order-date=$today(-1) and $lookup(mytable,order-number)
  
  sort order-number
  sort order-date
  
  ext order-number
  ext order-quantity
  ext order-ctgy
  ext order-description
  ext order-dollars
  ext order-tax
  
  output myfile,link
  exit

We moved the code around to be separated into logical groupings, making the code a lot easier to read and maintain. The Table command is near the If command for easy reference. The Item command is before the If command and is necessary to tell the If command the date type that the order-date is, so I keep it near the If command. We have a clear definition of the input source.

The two sort keys are clearly defined as well as each field.

If you needed to define a field to rename a field being extracted, say order-dollars to be order-total, I would change the script as follows:

  base mytest,5
  get mydataset
  
  def order-total,1,4,double
  
  table mytable,order-number,file,myords
  item order-date,date,ccyymmdd
  if order-date=$today(-1) and $lookup(mytable,order-number)
  
  sort order-number
  sort order-date
  
  ext order-number
  ext order-quantity
  ext order-ctgy
  ext order-description
  ext order-total=order-dollars
  ext order-tax
  
  output myfile,link
  exit

The Define commands can be grouped where you specify the input source, or even as I have them, as their own separate section. Next time you are developing some Suprtool scripts, why not give this guideline a try. We trust you will find your code much more readable.