Include Files--Windows and UNIX
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 .cbl 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.
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.cbl".
and the file employee.scb is translated into the COBOL file employee.cbl.
As another example, assume that a source file called inputfile contains the following include statement:
EXEC SQL INCLUDE 'mydecls' END-EXEC.
Windows:
The name mydecls can be defined as a system environment variable pointing to the file c:\src\headers\myvars.scb by means of the following command at the system level:
setenv mydecls c:\src\headers\myvars.scb
UNIX:
The name mydecls can be defined as a system environment variable pointing to the file /src/headers/myvars.scb by means of the following command at the system level:
setenv mydecls /src/headers/myvars.scb
Because the extension .scb is the default input extension for embedded SQL include files, it need not be specified when defining an environment variable 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 following COBOL statement for Windows and UNIX:
Windows:
COPY "c:\src\headers\myvars.hdr".
The COBOL file c:\src\headers\myvars.hdr is generated as output for the original include file, c:\src\headers\myvars.scb.
You can also specify include files with a relative path. For example, if you preprocess the file c:\src\headers\myvars.scb, the embedded SQL statement:
EXEC SQL INCLUDE '../headers/myvars.scb' END-EXEC.
is preprocessed to the COBOL statement:
include "../headers/myvars.cbl".
and the COBOL file c:\src\headers\myvars.cbl is generated as output for the original include file, c:\src\headers\myvars.cbl.
UNIX:
COPY "/src/headers/myvars.hdr".
The COBOL file /src/headers/myvars.hdr is generated as output for the original include file, /src/headers/myvars.scb.
You can also specify include files with a relative path. For example, if you preprocess the file /src/source/myprog.scb, the embedded SQL statement:
EXEC SQL INCLUDE '../headers/myvars.scb' END-EXEC.
is preprocessed to the COBOL statement:
include "../headers/myvars.cbl".
and the COBOL file /src/headers/myvars.cbl is generated as output for the original include file, /src/headers/myvars.scb.