Using COBOL copybooks for ODBC APIs

IBM COBOL for AIX provides copybooks that make it easier for you to access databases with ODBC drivers by using ODBC calls from COBOL programs. You can use these copybooks with or without modification.

The copybooks described below are for ODBC Version 3.0. However, Version 2.x copybooks are also supplied, and you can substitute them for the Version 3.0 copybooks if you need to develop applications for ODBC Version 2.x.

Table 1. ODBC copybooks
Copybook for Version 3.0 of ODBC Copybook for Version 2.x of ODBC Description Location
odbc3.cpy odbc2.cpy Symbols and constants include folder for COBOL
odbc3d.cpy odbc2d.cpy DATA DIVISION definitions odbc folder in the samples folder for COBOL
odbc3p.cpy odbc2p.cpy PROCEDURE DIVISION statements odbc folder in the samples folder for COBOL

Include the paths for the include and odbc folders in the SYSLIB environment variable to ensure that the copybooks are available to the compiler.

odbc3.cpy defines the symbols for constant values described for ODBC APIs. It maps constants used in calls to ODBC APIs to symbols specified in ODBC guides. You can use this copybook to specify and test arguments and function return values.

odbc3p.cpy lets you use prepared COBOL statements for commonly used functions for initializing ODBC, handling errors, and cleaning up (SQLAllocEnv, SQLAllocConnect, SQLAllocStmt, SQLFreeStmt, SQLDisconnect, SQLFreeConnect, and SQLFreeEnv).

odbc3d.cpy contains data declarations used by odbc3.cpy in the WORKING-STORAGE SECTION (or LOCAL-STORAGE SECTION).

Some COBOL-specific adaptations were made in these copybooks:

To include the copybook odbc3.cpy, specify a COPY statement in the DATA DIVISION as follows: