Programming for a Db2 environment
In general, the coding for a COBOL program will be the same if you want the program to access a Db2® database. However, to retrieve, update, insert, and delete Db2 data and use other Db2 services, you must use SQL statements.
Ensuring that the PAM package is installed
, where the
sudo yum list 'pam'
sudocommand or becoming the root user ensures that you have the privilege to run this command.
-qsqloption to translate your EXEC SQL statements, you will get the following IGYDS0220 message that the compiler cannot load the Db2 co-processor:
While missing the PAM package is one of the reasons you get the IGYDS0220 message, other reasons could be as follows:
The "SQL" compiler option was in effect, but the compiler was unable to load the IBM Db2 SQL co-processor services module. All "EXEC SQL" statements were discarded.
- The LD_LIBRARY_PATH environment variable has not been exported or it does not contain the path where the co-processor library is installed.
- The co-processor library is corrupted.
- You do not have sufficient file system permissions to use the co-processor library.
- One or more libraries that the co-processor requires are not present, such as the PAM package.
If the PAM package is installed as checked with the
yum listcommand mentioned previously, and you still get the error, you can check for other missing libraries with this command:
- On RHEL 7.8 or 7.9, use this command:
, where pam.i686 is the PAM package name on RHEL, and
sudo yum install pam.i686
yumis the default package installer on RHEL 7.8 or 7.9.
- On RHEL 8.0 or higher, use this command:
sudo dnf install pam.i686
dnfis the default package installer on RHEL 8.0 or higher.
- On Ubuntu, use this command:
, where libpam0g:i386 is the PAM package name on Ubuntu, and
sudo apt-get install libpam0g:i386
apt-getis the default package installer on Ubuntu.
Communicating with Db2
To communicate with Db2, do these steps:
- Code any SQL statements that you need, delimiting them with
- Start Db2 if it is not already started.
- Set the LD_LIBRARY_PATH, NLSPATH, DB2INSTANCE, and SYSLIB
environment variables before compiling. Note that the directory LD_LIBRARY_PATH specifies should
libdb2.so, which is the file for the Db2 co-processor, so that the co-processor can be loaded.Below is an example:
export LD_LIBRARY_PATH=/opt/ibm/db2/V11.1/lib32 export NLSPATH=/opt/ibm/db2/V11.1/msg/%L/%N export DB2INSTANCE=db2in111 export SYSLIB=/opt/ibm/db2/V11.1/include/cobol_a
- Compile with the
Compile with the
NODYNAMcompiler option if the application was compiled using the Db2 stand-alone precompiler.Note: The
NODYNAMcompiler option is required for programs that contain EXEC CICS® or EXEC SQL statements.
EXEC SQLstatements are used in COBOL libraries that are loaded by a COBOL dynamic call, then one or more
EXEC SQLstatements must be in the main program. (Called Db2 APIs cannot be loaded using a COBOL dynamic call.)
- Use the
-loptions when linking. Below is an example:
Using Db2 files
Coding SQL statements
Starting Db2 before compiling
Compiling with the SQL option
Passing options to the linker