Was this helpful?
Coding Requirements for Embedded SQL Programs
The following sections describe coding requirements for writing Embedded SQL programs.
Comments Embedded in Fortran Output
Each Embedded SQL statement generates one comment and a few lines of Fortran code. You may find that the preprocessor translates 50 lines of Embedded SQL into 200 lines of Fortran. This can confuse the program developer who is trying to debug the original source code. To facilitate debugging, a comment corresponding to the original Embedded SQL source delimits each group of Fortran statements associated with a particular statement. 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.
Embedded SQL Statements and Fortran If Blocks
Because each Embedded SQL statement must be on a line by itself, you must use the block-style Fortran if statement to conditionally transfer control to Embedded SQL statements. For example:
if (error) then
     exec sql message 'Error on update'
         exec sql sleep 2
end if
Note that the esqlf preprocessor also generates many nested constructs of do loops and if blocks—specifically, for Embedded SQL block-structured statements, such as display and unloadtable. If you mistakenly omit an end if from your Fortran source, the Fortran compiler complains that there is a missing end statement, which you can trace back to a preprocessor-generated if or do (VMS or Windows).
You can usually solve this problem by checking for matching if-end pairs in the original Embedded SQL Fortran source file. In VMS or Windows, you can also check for do-end pairs as well.
Embedded SQL Statements that Generate Labels
The Embedded SQL statements that generate labels are the Embedded SQL select statement and all the Embedded SQL/FORMS block-type statements. Each of these statements reserves its own range of 200 labels in a defined range for such statements of 7000 through 12000. Consequently, you cannot have more than 200 of any single label-generating statement in the same program unit. For example, 201 display statements in a single subroutine causes a compiler error indicating that a particular label was used more than once. You could, however, have 200 display statements and 200 unloadtable statements without causing a problem.
Embedded SQL Statements that Do Not Generate Code
The following Embedded SQL declarative statements do not generate any Fortran code:

declare cursor
declare statement
declare table

These statements must not contain labels. Also, they must not be coded as the only statements in Fortran constructs that do not allow null statements.
Last modified date: 06/10/2024