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 no extension is given to the filename (or to the file name pointed at by the logical name), the default Pascal input file extension ".sp" is assumed.
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 ".pas" 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 Pascal %include directive. If you use the -o flag (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.
For example, assume that no overriding output extension was explicitly given on the command line. The Embedded SQL statement:
exec sql include 'employee.dcl';
is preprocessed to the Pascal statement:
%include 'employee.pas'
and the file "employee.dcl" is translated into the Pascal file "employee.pas".
As another example, assume that a source file called "inputfile" contains the following include statement:
exec sql include 'mydecls';
You can define the name "mydecls" as a system logical name pointing to the file "dra1:[headers]myvars.sp" by means of the following command at the system level:
$ define mydecls dra1:[headers]myvars
Because the extension ".sp" is the default input extension for Embedded SQL include files, it need not be specified when defining a logical name for the file.
Assume now that "inputfile" is preprocessed with the command:
$ esqlp -o.inc inputfile
The command line specifies ".inc" as the output file extension for include files. As the file is preprocessed, the include statement shown earlier is translated into the Pascal statement:
%include 'dra1:[headers]myvars.inc'
and the Pascal file "dra1:[headers]myvars.inc" is generated as output for the original include file, "dra1:[headers]myvars.sp".
You can also specify include files with a relative path. For example, if you preprocess the file "dra1:[mysource]myfile.sp," the Embedded SQL statement:
exec sql include '[-.headers]myvars.sp';
is preprocessed to the Pascal statement:
%include '[-.headers]myvars.pas'
and the Pascal file "dra1:[headers]myvars.pas" is generated as output for the original include file, "dra1:[headers]myvars.sp."
Source Code with Labels
Some Embedded SQL statements generate labels. If you include a file containing such statements, you must be careful to include the file only once in a given Pascal scope. Otherwise, you may find that the compiler later complains that the generated labels are multiply defined in that scope.
The statements that generate labels are the Embedded SQL block-type statements, which are:
select-loop
display
formdata
tabledata
unloadtable
submenu
You must also issue the exec sql label statement in the same scope as the label-generating statement.
Last modified date: 08/28/2024