SQL/MX 3.1 Programming Manual for C and COBOL (H06.23+, J06.12+)
Program and Module Management
HP NonStop SQL/MX Release 3.1 Programming Manual for C and COBOL—663854-001
17-15
Effect of the Target Attribute
file, use class MAP DEFINEs for database object names and apply compile-time name
resolution (or PROTOTYPE host variables and build into your application the logic to
set these variables to their proper values at run time) to build applications that target
different sets of database objects without changing the source code. For more
information, see DEFINE Names for SQL/MP Objects on page 8-3 and Compile-Time
Name Resolution for SQL/MP Objects on page 8-6.
The target attribute is necessary if you want two or more targeted applications (and
their module files) to coexist and run concurrently on the same NonStop system.
Without the target attribute, each build of the application writes an identically named
module in the /usr/tandem/sqlmx/USERMODULES directory, unless you change the
MODULE directive in the source code or unless you have instructed the compiler to
generate locally placed modules. The target attribute prevents a subsequently built
application from overwriting the module file of the previously built application.
Effect of the Target Attribute
The SQL preprocessor checks for the presence of a Module TableSet Specification
String (MTSS), which is a regular or delimited identifier that you specify with
preprocessor options. For information on how to specify an MTSS, see Running the
SQL/MX C/C++ Preprocessor on page 15-8 and Running the SQL/MX COBOL
Preprocessor on page 16-9. For information on identifiers, see the SQL/MX Reference
Manual.
Targeting Example for C: Using ModuleTableSet (MTSS)
In the next example, a C application that counts employees in various departments is
prepared twice to use different sets of tables. One set of tables is for a test
environment, and the other set of tables is for a production environment. In the source
file empcnt.sql, the application’s SQL statements are coded with class MAP
DEFINEs.
EXEC SQL DECLARE COUNT_EMP_BY_DEPT CURSOR FOR
SELECT D.DEPT_NUM, COUNT(E.EMP_NUM)
FROM =DEPT AS D, =EMPLOYEE AS E
WHERE D.DEPT_NUM = E.EMP_DEPTNUM GROUP BY D.DEPT_NUM;
The application has a MODULE directive:
EXEC SQL MODULE CAT.SCH.EMP_CNT_MODULE NAMES ARE ISO88591;
To build the application, targeting a set of tables on a test system:
1. Use the OSS add_define command to give =DEPT and =EMPLOYEE the desired
values:
add_define =DEPT class=MAP file=\\TEST.\$DATA.HR1.DEPT
add_define =EMPLOYEE class=MAP \
file=\\TEST.\$DATA.HR1.EMPLOYEE
C










