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

You are required to have the 32-bit PAM package installed to access Db2 with COBOL for Linux® on x86. To check whether it was installed during your Db2 installation, run this command:
sudo yum list 'pam'
, where the sudo command or becoming the root user ensures that you have the privilege to run this command.
If the PAM library is not installed when you run the compiler with the -qsql option to translate your EXEC SQL statements, you will get the following IGYDS0220 message that the compiler cannot load the Db2 co-processor:
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.
While missing the PAM package is one of the reasons you get the IGYDS0220 message, other reasons could be as follows:
  • 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 list command mentioned previously, and you still get the error, you can check for other missing libraries with this command:
    ldd /opt/ibm/db2/V11.5/lib32/
To install the PAM package:
  • On RHEL 7.8 or 7.9, use this command:
    sudo yum install pam.i686
    , where pam.i686 is the PAM package name on RHEL, and yum is 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
    , where dnf is the default package installer on RHEL 8.0 or higher.
  • On Ubuntu, use this command:
    sudo apt-get install libpam0g:i386
    , where libpam0g:i386 is the PAM package name on Ubuntu, and apt-get is 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 EXEC SQL and END-EXEC statements.
  • 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 contain, 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 SQL compiler option.
  • Compile with the NODYNAM compiler option if the application was compiled using the Db2 stand-alone precompiler.
    Note: The NODYNAM compiler option is required for programs that contain EXEC CICS® or EXEC SQL statements.

    If EXEC SQL statements are used in COBOL libraries that are loaded by a COBOL dynamic call, then one or more EXEC SQL statements must be in the main program. (Called Db2 APIs cannot be loaded using a COBOL dynamic call.)

  • Use the -L and -l options when linking. Below is an example:
       -L/opt/ibm/db2/V11.1/lib32 -ldb2

Related concepts  
Db2 coprocessor