3. Embedded SQL for COBOL : Preprocessor Operation : Include File Processing : Include Files—VMS
 
Share this page                  
Include Files—VMS
The embedded SQL include statement provides a means to include external files in your program's source code. Its syntax is:
exec sql include filename end-exec
filename
A single-quoted string constant that specifies a file name or an environment variable that points to the file name. If no extension is given to the filename (or to the file name pointed at by the environment variable), the default COBOL input file extension .scb 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 .lib is generated. You can override this default output extension with the -o.ext flag on the command line. In the original source file that specified the include statement, a new reference is made to the output file with the COBOL COPY statement. If the -o flag is used with no extension, an output file is not generated for the include statement. This is useful for program libraries using MMS dependencies.
If you use both the -o.ext and the -o flags, then the preprocessor will generate the specified extension for the translated include statements in the program but will not generate new output files for the statements.
For example, assume that no overriding output extension was explicitly given on the command line. The embedded SQL statement:
EXEC SQL INCLUDE 'employee.scb' END-EXEC.
is preprocessed to the COBOL statement:
COPY "employee.lib".
and the file employee.scb is translated into the COBOL file employee.lib.
As another example, assume that a source file called inputfile contains the following include statement:
EXEC SQL INCLUDE 'mydecls' END-EXEC.
The name mydecls can be defined as a system logical name pointing to the file dra1:[headers]myvars.scb by means of the following command at the system level:
define mydecls dra1:[headers]myvars
Because the extension .scb 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:
esqlcbl -o.hdr inputfile
The command line specifies .hdr as the output file extension for include files. As the file is preprocessed, the include statement shown earlier is translated into the COBOL statement:
COPY "dra1:[headers]myvars.hdr"
and the COBOL file dra1:[headers]myvars.hdr is generated as output for the original include file, dra1:[headers]myvars.scb.
You can also specify include files with a relative path. For example, if you preprocess the file dra1:[mysource]myfile.scb, the embedded SQL statement:
EXEC SQL INCLUDE '[-.headers]myvars.scb' END-EXEC.
is preprocessed to the COBOL statement:
COPY "[-.headers]myvars.lib"
and the COBOL file dra1:[headers]myvars.lib is generated as output for the original include file, dra1:[headers]myvars.scb.