SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Name Resolution, Similarity Checks, and Automatic
Recompilation
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
8-3
Table and View Name References
errors. To avoid these errors, create SQL/MP aliases separately before compiling the
embedded SQL program.
When you code a table name by using an SQL/MP alias, the logical name of the
SQL/MP alias is tightly bound to a physical table when the SQL statement is compiled.
To make the statement refer to some other physical table, you must alter the SQL/MP
alias and then recompile the module. For example, issue this ALTER SQLMP ALIAS
statement before recompiling the module.
ALTER SQLMP ALIAS samdbcat.persnl.employee
$samdb.persnl.employees_region2;
For the syntax of the CREATE SQLMP ALIAS and ALTER SQLMP ALIAS statements,
see the SQL/MX Reference Manual.
DEFINE Names for SQL/MP Objects
You can refer to an SQL/MP table or view with a class MAP DEFINE that resolves to a
Guardian physical name:
EXEC SQL
SELECT jobcode, jobdesc
INTO :hv_jobcode, hv_jobdesc
FROM =JOB
WHERE jobcode = :hv_this_jobcode;
When you use a DEFINE to refer to a table or view, you can compile the statement’s
module with the DEFINE mapped to one table or view name, and then assign the
DEFINE a different name and recompile the module. The recompiled statement then
refers to the second table or view name for the DEFINE. This practice is called
compile-time name resolution. For more information, see Compile-Time Name
Resolution for SQL/MP Objects on page 8-6.
The use of DEFINEs in SQL statements also enables late name resolution. By using
late name resolution, you can compile a statement to use one table and then, without
recompiling the statement, process a different table when the statement is executed by
using a different value for the statement’s DEFINE. For more information, see Late
Name Resolution on page 8-6.
For the syntax of DEFINEs, see the SQL/MX Reference Manual. To use a DEFINE for
a table or view, map it to a Guardian physical file before you compile or execute the
statement. For information on how to ensure proper name resolution, see the SQL/MX
Installation and Management Guide.
Note. Before using DEFINEs in OLTP applications, see OLT Optimization Considerations for
DEFINE Names and PROTOTYPE Host Variables on page 8-5.