The include directive

The include directive allows you to specify a file to include within your program.

The preprocessor places the contents of the specified file into the source file. Stage 1 of the preprocessor reads the contents of filename into the current file at the position of the include directive.

You can use the include preprocessor directive in either of the following two formats:
  • EXEC SQL include filename;
  • $include filename;

Replace filename with the name of the file you want to include in your program. You can specify filename with or without quotation marks. If you use a full path name, however, you must enclose the path name in quotation marks.

The following example shows how to use full path names in a Windows™ environment.
EXEC SQL include decimal.h;

EXEC SQL include "C:\apps\finances\credits.h";
Tip: If you specify the full path name, you must recompile the program if the location of the file changes. Better programming practice specifies search locations with the esql -I option and specifies only the file name with the include directive.

If you omit the quotation marks around the file name, changes the file name to lowercase characters. If you omit the path name, the preprocessor checks the preprocessor search path for the file. For more information about this search path, see Name the location of include files.

You can use include for the following types of files:
  • The header file
    You do not have to use the .h file extension for the header file; the compiler assumes that your program refers to a file with a .h extension. The following examples show valid statements to include header files:
    EXEC SQL include varchar.h;
    $include sqlda;
    EXEC SQL include sqlstype;
  • Other user-defined files

    You must specify the exact name of the file that you want to include. The compiler does not assume the .h extension when you include a header file that is not the header file.

    The following examples show valid statements to include the files constant_defs and typedefs.h in a UNIX™ environment:
    EXEC SQL include constant_defs;
    EXEC SQL include "constant_defs";
    $include typedefs.h;
    EXEC SQL include "typedefs.h";

You must use the include directive if the file you specify contains embedded SQL statements, or other statements.

Use the standard C #include directive to include system header files. The #include of C includes a file after preprocessing.
Restriction: Embedded INCLUDE statements are not supported within declare sections and can generate misleading errors. For correct usage, see ids_esqlc_0093.html#ids_esqlc_0093.