Include File Processing
The Embedded SQL include statement provides a means to include external files in your program's source code. The syntax of the statement is:
exec sql include filename
where filename is a quoted string constant specifying a file name or a logical name that points to the file name. If the file is in the local directory, you can also specify the filename without the surrounding quotes. If no extension is given to the file name (or to the file name pointed at by the logical name), the program assumes the default BASIC input file extension ".sb".
This statement is normally used to include variable declarations, although it is not restricted to such use. For more details on the include statement, see the SQL Reference Guide.
The included file is preprocessed and an output file with the same name but with the default output extension ".bas" is generated. You can override this default output extension with the -o.ext flag on the command line. The preprocessed output of the include statement is the BASIC %include directive. If the -o flag is used without an extension, then the output file is not generated for the include statement. This is useful for program libraries that use VMS MMS dependencies.
If you use both the -o.ext and the -o flags, then the preprocessor will generate the specified extension for the include statements in the program but will not generate new output files for the statements.
In the following example, assume that no overriding output extension was explicitly given on the command line. The Embedded SQL statement:
exec sql include 'employee.sb'
is preprocessed to the BASIC statement:
%include "employee.bas"
and the employee.sb file is translated into the BASIC employee.bas file.
In the next example, the system logical name "mydecls" points at the file "dra1:[headers]myvars.sb". If the following commands are invoked on the system level:
$ define mydecls dra1:[headers]myvars.sb
$ esqlb -o.hdr inputfile
the Embedded SQL statement:
exec sql include 'mydecls'
is preprocessed to the BASIC statement:
%include "dra1:[headers]myvars.hdr"
and the BASIC file 'dra1:[headers]myvars.hdr' is generated.
You can also specify include files with a relative path. For example, if you preprocess the file "dra1:[mysource]myfile.sb," the Embedded SQL statement:
exec sql include '[-.headers]myvars.sb'
is preprocessed to the BASIC statement:
%include "[-.headers]myvars.bas"
and the BASIC file "dra1:[headers]myvars.bas," is generated as output for the original include file, "dra1:[headers]myvars.sb."
Source Code with Labels
Some Embedded SQL statements generate labels. If you include files containing such statements, you must be careful to include the file only once in a given BASIC scope. Otherwise, you may find that the compiler later complains that the generated labels are defined more than once in that scope.
The statements that generate labels are the Embedded SQL block-type statements, such as display, unloadtable, and the select-loop.
Last modified date: 08/28/2024