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-19
Targeting Example for COBOL: Using
ModuleTableSet (MTSS)
tables is for a test environment, and the other set of tables is for a production
environment. In a source file (empcnt.ecbl), 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 END-EXEC.
The application has a MODULE directive:
EXEC SQL MODULE CAT.SCH.EMP_CNT_MODULE NAMES ARE
ISO88591 END-EXEC.
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
2. Invoke the preprocessor, specifying a module-tableset-specification-
string with the -g option:
mxsqlco empcnt.ecbl -c empcnt.cbl -m empcnt.m \
-g moduleTableSet=TEST
3. The previous preprocessor step produces a pure COBOL file (empcnt.cbl) and a
module definition file (empcnt.m). The nmcobol utility compiles and links the
COBOL file and produces an executable (empcnt_test.exe), and the SQL/MX
compiler compiles empcnt.m. (The user directed nmcobol to name the
executable empcnt_test.exe to indicate that it was prepared for the TEST table
set). Because a module-tableset-specification-string is specified, the
module file produced by the SQL/MX compiler is:
/usr/tandem/sqlmx/USERMODULES/CAT.SCH.^EMP_CNT_MODULE^TEST^
If you want to rebuild the application to target a set of production files, you can do so
without changing the source file empcnt.ecbl:
1. Use the OSS add_define command to give =DEPT and =EMPLOYEE the values
to target a different set of files:
add_define =DEPT class=MAP file=\\PROD.\$DATA.HR1.DEPT
add_define =EMPLOYEE class=MAP
file=\\PROD.\$DATA.HR1.EMPLOYEE
2. Invoke the preprocessor, specifying a module-tableset-specification-
string with the -g option and a different value:
mxsqlco empcnt.ecbl -c empcnt.cbl -m empcnt.m -g \
moduleTableSet=PROD










