Was this helpful?
Coding Requirements for Writing EQUEL Programs
The following sections describe coding requirements for writing EQUEL programs.
Comments Embedded in Pascal Output
Each EQUEL statement generates one comment and a few lines of Pascal code. You may find that the preprocessor translates 50 lines of EQUEL into 200 lines of Pascal. This may result in confusion about line numbers when you are debugging the original source code. To facilitate debugging, each group of Pascal statements associated with a particular statement is preceded by a comment corresponding to the original EQUEL source. (Note that only executable EQUEL statements are preceded by a comment.) Each comment is one line long and informs the reader of the file name, line number, and type of statement in the original source file.
One consequence of the generated comment is that you cannot comment out embedded statements by putting the opening comment delimiter on an earlier line. You have to put the opening comment delimiter on the same line, before the ## delimiter, to cause the preprocessor to treat the complete statement as a Pascal comment.
The Pascal Semicolon and EQUEL Statements
With one exception, EQUEL statements embedded in Pascal host code do not require a terminating semicolon. Pascal declarative statements must be separated by a semicolon, as required in the Pascal language.
The exception occurs when an EQUEL statement that allows but does not include the optional with clause is followed immediately by a Pascal with statement. When this occurs, the EQUEL statement must be terminated with a semicolon. For example:
##  {Assume "emprec" has been declared as a 
##   record variable}
##  create employee (name=c30, age=i4); 
##  {Note the semicolon here}
##  with emprec do
##  begin
    ...
##  end;
If the EQUEL statement with the optional with clause is followed by another EQUEL statement or by Pascal host code, then the semicolon is optional.
Pascal Blocks Generated by EQUEL
As mentioned above, the preprocessor may produce several Pascal statements for a single EQUEL statement. However, all the Pascal statements that the preprocessor generates for an EQUEL statement are surrounded by a begin-end block. Thus, the statement:
    if error then
##  deleterow form table 1
will produce legal Pascal code, even though the deleterow statement generates more than one Pascal statement.
Note that multiple EQUEL statements will cause the preprocessor to generate multiple begin-end blocks. Therefore, when placing multiple EQUEL statements in a Pascal if statement, you must surround the whole group of statements with a begin-end block, just as you would for multiple Pascal statements in an if statement. For example:
    if error then 
    begin
##      message 'Deleting because of error'
##      sleep 2
##      deleterow form table 1
    end;
A semicolon always terminates the begin-end block that the preprocessor generates for an EQUEL statement. Therefore, because Pascal does not permit semicolons before the else clause of an if statement, you must surround any single EQUEL statement that precedes an else clause with a begin-end block. For example, the following if statement will cause a Pascal error:
    if error then
##      message 'Error occurred'
        {Preprocessor adds a semicolon here}
    else
##      message 'No error occurred'
By delimiting the then clause with begin-end, you eliminate the error:
    if error then 
    begin
##      message 'Error occurred'
        {Preprocessor still adds semicolon here...}
        end 
        {...but that's okay because there's no semicolon here}
    else
##      message 'No error occurred'
An EQUEL Statement that Does Not Generate Code
The declare cursor statement does not generate any Pascal code. This statement should not be coded as the only statement in Pascal constructs that does not allow null statements. For example, coding a declare cursor statement as the only statement in a Pascal if statement not bounded by begin and end would cause compiler errors:
    if (using_database)
##  declare cursor empcsr for retrieve (employee.ename)
    else
        writeln('You have not accessed the database.');
The code generated by the preprocessor would be:
    if (using_database)
    else
        writeln('You have not accessed the database.');
which is an illegal use of the Pascal else clause.
Last modified date: 11/28/2023