SQL/MP Reference Manual
HP NonStop SQL/MP Reference Manual—523352-013
D-31
Using DEFINEs With SQL Programs
Using DEFINEs With SQL Programs
These rules apply to the use of DEFINEs in SQL statements within programs:
You use TACL or OSS shell commands to supply DEFINEs at compilation for
DEFINE names used in preprocessor or host language statements and in the
SQLCOMP or c89 command. For example, if you use DEFINE names in INVOKE
statements for an SQL program that is executable from Guardian, you use TACL
commands to supply corresponding DEFINEs at preprocessor or host language
compilation.
You normally supply DEFINEs at explicit SQL compilation for any DEFINE names
you use in static SQL statements. SQL attempts to resolve such DEFINE names
during explicit compilation, if possible (although the names might be reresolved at
load or execution time according to the rules that follow).
If corresponding DEFINEs do not exist, the SQL compiler issues a warning and
produces a program that, although valid, requires recompilation with appropriate
DEFINE values. (SQL can automatically recompile programs at run time, as
discussed in the SQL/MP programming manual for your host language. If you
prohibit recompilation, however—or if appropriate DEFINEs are still missing by the
time the statement executes—an error occurs.)
Dynamic SQL statements are not affected by explicit compilation, so there is no
reason to supply DEFINEs for those statements before execution.
For SQL programs executable from Guardian, you can use the EXPLAIN
DEFINES option on the SQLCOMP command to automatically generate an OBEY
command file that contains ADD DEFINE commands for the DEFINEs used in your
program. To generate the OBEY command file in TACL OBEY format, use the
OBEY FORM option.
You can use the command file to add the same DEFINEs again at run time. For
information, see the SQL/MP programming manual for your host language.
To use DEFINEs in programs, you can inherit DEFINEs from your TACL or OSS
shell process or use system procedure calls to create DEFINEs within your
program. If a DEFINE does not exist at execution time, SQL uses the stored define
that existed at compilation time.
You can direct your program to access a different set of objects than the ones you
specified at compilation by supplying different DEFINE values at run time than at
compile time. Depending on the compilation options you specified, the similarity
between the objects, and the SIMILARITY CHECK attribute of the objects,
changing DEFINE values at run time causes successful similarity checks,
recompilation, or errors.
To inherit DEFINEs in a program, set DEFMODE ON before you start the program;
to avoid inheriting DEFINEs, set DEFMODE OFF before you start the program,
then set it ON within the program.