Including Common Code
Sections of source code that are shared by a number of different code modules and/or subroutines can be inserted into your program with the INCLUDE statement. This can be particularly useful for symbol definitions (if symbols are defined in one place this can make your code much more maintainable), but any valid DataBasic code can be included, such as internal subroutines and declarations for COMMON variables. Each shared section of code must be in a separate file item.
To include shared code in your program, place an INCLUDE statement on a line by itself, specifying the name of the item to be included and, if it is in a separate file or data section, the location of the item. For example, the following statement includes the item DEFINITIONS from the data section PROGRAMS in the file DB:
INCLUDE DEFINITIONS FROM DB,PROGRAMS
A source program can contain any number of INCLUDE statements and included items can themselves contain INCLUDE statements up to a maximum of 16 nested levels.
Defining Code to be Automatically Included
If you have code that you want to include in every code module in a data section, you can create an item to be automatically included without having to use the INCLUDE statement. To do this, create an item called #AUTOINCLUDE - when your programs are compiled, the contents of this item will be automatically included at the beginning of every code module in the same data section.
Note
If preferred, you can create a global auto-include item that will be included in every DataBasic program in your database after any local automatically included code. Place your common code in the item #AUTOINCLUDE in the default data section of the file BASIC-COMPILERS in the SYSFILES account.
Order of Included Code
If you use all of the features described above, they will be applied in the following order:
-
The local auto-include item. Use for user- or application-specific includes.
-
The global auto-include item. Use for system-wide includes, such as settings for MultiValue compatibility.
-
INCLUDE statements. Use for module-specific includes.