![]() | ||
| Getting Started | ![]() ![]() ![]() ![]() | VisualPQL |
VisualPQL is the major application development tool within SIR2002 and is extremely powerful. VisualPQL can be used for numerous tasks from simply analysing some data to building a complex, menu driven application.
In some languages, this is a big hurdle. However with SIR2002, it is easy and straightforward. The VisualPQL program to display "Hello World" is:
Assuming that you have the
You use an editor to create the text. The system allows you to use any editor of your choice and also has two internal editors. Use whatever program you would normally use to edit text and that you are comfortable using.
To check which editor is being used, go to the
Congratulations. You have created and run that vital first program!
N.B. If you do not want to type this program in, it is supplied as member
There is also a
The following program uses a formula to calculate Fahrenheit and Centigrade
temperature equivalents. The program in its simplest form is:
Because neither the
Try running the temperature program (supplied as
The
The following version (
Because conditional tests are frequently required for very simple computations or actions, there is an
A first program
The only way to learn a new language is to write programs in it. The first program in all languages is the same. Print the words: Hello World
PROGRAM
WRITE 'Hello World'
END PROGRAM
All you have to do is to create this text and keep it and you can do this either as a:COMPANY database attached, you might put your test programs in a new family of procedures called, say, TESTSettings - Preferences dialog. This has a check box for external editor and the name of your selected external editor. If the box is not checked, the name is greyed out and the system uses the the selected internal editor. If you do not have access to an external text editor, use the SIR GUI editor. If you select an external editor, the system saves this from session to session. When using the external editor option ensure that the path and the name are correct otherwise trying to edit a program will not work.Steps to run a first program
SIR2002. Attach the COMPANY database.
Program menu.
Members.
PROG1.
Start program compilation
Start program execution
Hello World
End program execution
EXAMPLE.HELLO.
VisualPQL Syntax
See VisualPQL syntax for a
full description. Briefly the rules for VisualPQL are:
RETRIEVAL
PROCESS CASES
PROCESS REC EMPLOYEE
WRITE ID NAME
BIRTHDAY SALARY
END REC
END CASE
END RETRIEVAL
RETRIEVAL
. PROCESS CASES
. PROCESS REC EMPLOYEE
. WRITE ID NAME BIRTHDAY SALARY
. END REC
. END CASE
END RETRIEVAL
PROCESS REC is a synonym for PROCESS RECORD.COMMENT command (synonym C or CC). This specifies that the whole line is a comment.PROGRAM and ends with a matching END command. The commands to begin a routine are:
PROGRAM - any main routine
RETRIEVAL - a main routine that accesses a database
FORM - a main routine that creates screens to do record at a time browsing
SUBROUTINE - an independent routine that is executed from other routines
Example VisualPQL programs
The mechanics of creating and running the programs
are going to be taken as understood from now on. Before doing too much typing in, try saving and restoring data from members or files and you should be comfortable with the mechanics of using an editor.
PROGRAM
FOR FAHR = 0,300,20
COMPUTE CELSIUS = 5/9 * (FAHR - 32)
WRITE FAHR CELSIUS
END FOR
END PROGRAM
VisualPQL is a block structured language and the block used here is a FOR block. This assigns an initial value to a variable and then performs the commands in the block a number of times, incrementing the initial variable each time until the final value is reached. In this case, these values are expressed as constants with a start of 0, an end of 300 and an increment of 20. The end of the block is indicated by the END FOR command.FAHR nor CELSIUS
variables were explicitly declared, they are implicitly declared. In the context they were used they had to be numeric.EXAMPLES.TEMP1) and look at the results. There is a default output format for all variables which may not be precisely what was wanted, but allows a very quick result to be produced. There are no comments in the program, nor any indentation to indicate which commands are in the loop and which are not. A slightly improved version of the program (EXAMPLES.TEMP2) might be:
PROGRAM
C** This program computes Fahrenheit and Celsius equivalents
C** between 0 and 300 fahrenheit
WRITE 'FAHRENHEIT CELSIUS'
FOR FAHR = 0,300,20
. COMPUTE CELSIUS = 5/9 * (FAHR - 32)
. WRITE FAHR(f6.2) 12T CELSIUS(f6.2)
END FOR
END PROGRAM
Note the use of lines starting with a period for indentation. All commands start in column one and periods are used to indent for readability. Indentation and the use of one command per line is recommended. The C in column one indicates a comment. C** is often used conventionally.WRITE can specify output formats (enclosed in parentheses after the variable) to align the output. The (f6.2) format indicates a floating point format 6 characters long with 2 decimal places. The 12T specification specifies that the next field starts in position 12. Two WRITE statements have been used, one to do a brief heading and one to output each line of results. A WRITE automatically writes a new line.EXAMPLES.TEMP3) of the temperature conversion program uses variables to control the FOR loop and uses the SET command to initialise these. It uses the SIMPLE REPORT procedure and writes to a file rather than to the screen.
PROGRAM
C** This program computes fahrenheit and celsius equivalents
C** between a lower limit, and an upper limit in intervals
INTEGER*2 lower upper interval
SET lower,upper,interval(0,300,20)
FOR FAHR = lower,upper,interval
. CELSIUS = 5/9 * (FAHR - 32)
. PERFORM PROCS
END FOR
REPORT FILENAME = TEMP.LIS /
PRINT = FAHR CELSIUS /
NOTOTALS
END PROGRAM
More VisualPQL
Logical Conditions
Some commands are executed depending on particular logical conditions. Specify logical conditions in brackets. You can construct
compound conditions using AND, OR, etc.IF command which is not block structured; it simply determines whether or not the command is executed. The action to be taken is expressed as a continuation of the IF command itself. For example:
RETRIEVAL
PROCESS CASES
. PROCESS RECORD EMPLOYEE
. IF (GENDER EQ 1 ) WRITE NAME
. END PROCESS RECORD
END PROCESS CASES
Database Access
Begin a program that accesses the database with the
RETRIEVAL
command which opens the default database (if more than one database is connected, this is the last database connected or it can be set explicitly).
If the retrieval needs to create, modify or delete data on database records, specify the UPDATE option on the RETRIEVAL command. This opens the database for write
access. Retrievals without the UPDATE option can get data from the database but cannot add, delete or modify data.
A very simple program which accesses the database might be as follows. This program lists the name of all employees:
RETRIEVAL PROCESS CASES . PROCESS RECORD EMPLOYEE . WRITE NAME . END PROCESS RECORD END PROCESS CASES END RETRIEVALThings to note about this program:
RETRIEVAL (as opposed to
PROGRAM) indicating that it uses the database.
PROCESS RECORD / END PROCESS RECORD is a block structure and the block of commands within the PROCESS REC block is executed for each EMPLOYEE record that is retrieved.
NAME is a string variable on the EMPLOYEE record.
PROCESS CASE / END PROCESS CASE block processes every case. If you leave this block out, the program will still work but will give you a warning message.
PROCESS CASE | PROCESS RECORD
CASE IS | RECORD IS
NEW CASE IS | NEW RECORD IS
Is a variant which creates a new case or record if one does not already exist.
OLD CASE IS | OLD RECORD IS
Is a variant which retrieves an existing single case or record.
These blocks are terminated with the END CASE/RECORD command. On case structured databases, record blocks are nested within a case block.
The PROCESS commands are a looping structure and retrieve all matching occurrences of data. The "IS" commands access a single occurrence.
The record processing commands specify a record type and may specify a particular record or subset of records to retrieve. This is done by specifying values which are matched to the record keys or keys in a secondary index.
For example, the OCCUP record has a key of POSITION. To get the OCCUP record which corresponds to the current position value:
RETRIEVAL PROCESS CASES ALL OLD RECORD IS EMPLOYEE . GET VARS currpos . OLD REC IS OCCUP (currpos) . GET VARS ALL . WRITE ID NAME CURRPOS STARTSAL ... . END RECORD IS END RECORD IS END RETRIEVALIf there are no matching records, then the block of commands is skipped completely. In the previous example, the
WRITE is not executed if there is no matching OCCUP record for an employee and thus that employee does not appear in the output. Selection criteria may be specified as constants or variables.
On a PROCESS CASE command there are options to select counts, samples or lists of cases. On a PROCESS RECORD command, there are a number of ways of specifying records to be selected. These include selecting records with keys from a specified value, to a specified value and in a given range. Records can have multiple key fields and the selection may be applied to a subset of keys. In a case structured database, the case id is implicitly used as the first key on record keys (not on secondary indexes). For example to select a sample of employees and find an average of their starting salaries in position grades 4 through 10:
RETRIEVAL
PROCESS CASES SAMPLE = .25
. PROCESS RECORD OCCUP FROM (4) THRU (10)
. COMPUTE AVGSAL = MEANR (STARTSAL);
STDD = STDEVR (STARTSAL)
. END PROCESS RECORD
END PROCESS CASE
WRITE 'Average Salary = ' AVGSAL ' Std. Dev = ' STDD
END RETRIEVAL
To retrieve all employees by name assuming a secondary index called NAME_INDEX has been defined on name:
RETRIEVAL PROCESS RECORD EMPLOYEE INDEXED BY NAME_INDEX WRITE NAME 25T ID END PROCESS REC END RETRIEVAL
![]() ![]() ![]() ![]() |