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

COBOL Program Compilation
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
16-4
Compiling Embedded SQL COBOL Programs With
Embedded Module Definitions
process. For information on using nmcobol in this way, see nmcobol Utility: Using One
Command for All Compilation Steps on page 16-29. For more information on using
ETK, see ETK online help.
These steps correspond to the steps in Figure 16-1 on page 16-3.
1. Create the COBOL source file that contains embedded SQL statements
(sqlprog.ecob).
2. Preprocess the application’s embedded SQL source file by using the SQL/MX
COBOL preprocessor mxsqlco. See Running the SQL/MX COBOL Preprocessor
on page 16-9.
mxsqlco sqlprog.ecob
In this step, set optional module specification strings and moduleCatalog and
moduleSchema default settings by using the -g option. See page 16-15 or 16-19.
Although you do not set mxcmp defaults here, if the input source file contains
mxcmp default settings, such as EXEC SQL DECLARE/SET/CONTROL QUERY
DEFAULT statements, they are preprocessed into corresponding module language
statements in the output module definition of the annotated source file.
3. The preprocessor produces a modified (annotated) COBOL source file
(sqlprog.cbl) that contains the COBOL and SQL call-level interface (CLI)
translations of embedded SQL statements and additional COBOL source
constructs that represent the module definition. The default behavior creates a
single, self-contained application source file with embedded module definitions.
4. Compile the annotated COBOL source file by using the nmcobol compiler (OSS
environment) or ETK (Windows environment). To produce an object file:
nmcobol -Wcobol="consult /usr/tandem/sqlmx/lib/sqlcli.o" \
-o sqlprog.o -c sqlprog.cbl
If you do not specify the -Wsqlmx or -Wmxcmp flag in the command line, the
nmcobol compiler requires the CONSULT directive to compile the annotated
COBOL source file correctly. The sqlcli.o file contains definitions of the CLI
procedure calls for the translated SQL statements in the annotated COBOL source
file. If you invoke nmcobol with the -Wsqlmx or -Wmxcmp flag, the list of libraries
searched automatically includes sqlcli.o.
Specify the -c option if you do not want nmcobol to link the program. Otherwise,
nmcobol invokes nld to create an executable file.
See Running the COBOL Compiler and Linker on page 16-21.
5. The COBOL compiler produces the object file, sqlprog.o. If you prefer early
detection of SQL compilation errors, you can SQL compile the application’s object
file at this point. During program development, you might want to use the
mxCompileUserModule utility against all the object files rather than against the
executable file. When you SQL compile against the object files, NonStop SQL/MX
does not recompile each module for object files that are linked into more than one
executable file.