Was this helpful?
Include File Processing
The following sections describe include file processing for Windows, UNIX, and VMS.
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.
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.
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 COBOL program unit. Otherwise, you may find that the compiler later complains that the generated labels are defined more than once.
The embedded SQL select loop generates labels and all the embedded SQL/FORMS block-type statements, such as display and unloadtable.
Last modified date: 11/28/2023