COBOL製品技術情報(FAQ)


Server Express から DB2 へのアクセス方法を教えてください

Server Express、Net Express でCOBOLから DB2 UDBにアクセスするには、以下の3通りの方法があります。


1) DB2 が装備している Micro Focus向けプレコンパイラを使用する

この方法はIBM によってサポートされているテクノロジーです。DB2 はさまざまな言語から埋め込みSQL文による DB2アクセスを可能とするプレコンパイラを提供しています。Server Express についても、独自の対応をサポートしています。$DB2DIR/samples/cobol_mf ディレクトリの下に、Server Express向けのサンプルプログラムが提供されており、プレコンパイル・コンパイル・リンク・実行のステップを体験できます。

以下に、サンプルを実際に実行するステップを示します:

$ db2 connect to sample

  Database Connection Information

Database server        = DB2/6000 7.2.0
SQL authorization ID   = DB2ADMIN
Local database alias   = SAMPLE

$ db2 prep cursor.sqb bindfile

LINE    MESSAGES FOR cursor.sqb
------  --------------------------------------------------------------------
        SQL0060W  The "COBOL" precompiler is in progress.
        SQL0091W  Precompilation or binding was ended with "0"
                  errors and "0" warnings.
$ db2 bind cursor.bnd

LINE    MESSAGES FOR cursor.bnd
------  --------------------------------------------------------------------
        SQL0061W  The binder is in progress.
        SQL0091N  Binding was ended with "0" errors and "0" warnings.
$ db2 connect reset
DB20000I  The SQL command completed successfully.
$ ls -l cursor.*
-rw-r--r--   1 db2admin db2iadm1    4592 Jun 07 11:11 cursor.bnd
-rw-r--r--   1 db2admin db2iadm1   12171 Jun 07 11:11 cursor.cbl
-r--r--r--   1 db2admin db2iadm1    3780 Jun 07 10:56 cursor.sqb
$ cob -c -x checkerr.cbl
$ cob -V -c -x cursor.cbl
* Micro Focus Server Express         V2.0 revision 011 Compiler
* Copyright (C) 1984-2001 MERANT International URN RXCAI/AA0/00000Q
$ cob -x -o cursor cursor.o checkerr.o -ldb2 -ldb2gmf -L$DB2PATH/lib
$ ./cursor
Sample COBOL program: CURSOR
Enter your user id (default none):
Sanders    in dept. +00020 is a manager
Marenghi   in dept. +00038 is a manager
Hanes      in dept. +00015 is a manager
Plotz      in dept. +00042 is a manager
Fraye      in dept. +00051 is a manager
Molinare   in dept. +00010 is a manager
Lu         in dept. +00010 is a manager
Daniels    in dept. +00010 is a manager
Jones      in dept. +00010 is a manager
Lea        in dept. +00066 is a manager
Quill      in dept. +00084 is a manager
$


詳細な情報は DB2 のマニュアルを参照してください。


2) Server Express、Net Expressが提供する OpenESQL機能でODBCドライバ経由で接続する

弊社が標準的に推奨している方法であり、実績もあります。
Net Expressを使用したクロス開発の場合に必須な方法であり、Windows上で対話型のクエリー自動生成や、ホスト変数宣言を自動生成する機能が利用できます。
この方法の場合、データディレクトテクノロジーズから、DataDirect SequeLink ODBCドライバを追加購入する必要があります。


3) Server Express、Net Expressが提供する DB2 ECM機能で、直接DB2クライアント経由で接続する

UDB 7.2 で動作検証済みです。Net Expressによるクロス開発は使用できません。DB2の拡張SQL方言が使用できます。