4. Embedded SQL for Fortran : The SQL Communications Area : The Include SQLCA Statement
 
Share this page                  
The Include SQLCA Statement
You should issue the include sqlca statement in your main program module and in each subprogram of your Fortran file that includes Embedded SQL statements. If the file is composed of one main program and a few subprograms include sqlca should be the first Embedded SQL statement in each of the program units. For example:
program EmpPrc
            exec sql include sqlca 
            ...
end

subroutine EmpSub
            exec sql include sqlca 
            ...
end

integer function EmpFun
            exec sql include sqlca 
            ...
end
The include sqlca statement instructs the preprocessor to generate code to call Ingres runtime libraries. It generates a Fortran include statement to make all the generated calls acceptable to the compiler.
Regardless of whether you intend to use the SQLCA for error handling, you must issue an include sqlca statement in each program unit containing Embedded SQL statements; if you do not, the Fortran compiler can complain about undeclared functions. Furthermore, the program aborts at runtime because program memory is overwritten. This occurs because, without explicit declaration of the SQLCA by means of the include sqlca statement, the Fortran compiler implicitly declares all references (including preprocessor-generated references) to the SQLCA as type real.
To help detect runtime errors due to missing include sqlca statements, you may want to include the Fortran implicit undefined statement (UNIX) or implicit none statement (VMS and Windows) in each program unit, or use the -u flag (UNIX), qualifier warnings=declarations (VMS), or /warn:declarations or /4Yd (Windows) with the compiler command. By doing so, you can ensure that the compiler generates a warning upon encountering a reference to an undeclared SQLCA.