Using Db2 files
To access Db2® files from a COBOL application that runs under Linux®, you must follow guidelines for compiling and linking the application and for identifying the Db2 file system, the Db2 instance and database, and the Db2 files.
About this task
- Compile and link the COBOL programs in your application by using the cob2 command.
- Initialize the Db2 environment
by executing the profile for the Db2 instance
that you want to use. For example, you might issue the following command to use instance
db2inst1
:. /home/db2inst1/sqllib/db2profile
- Ensure that the Db2 instance
is running and that you can connect to the database that you want
to access. The following example shows the db2 command that you might use to connect to database
db2cob
, and shows the system response:> db2 connect to db2cob Database Connection Information Database server = DB2/Linux64 9.7.0 SQL authorization ID = MYUID Local database alias = DB2COB
Restriction: Note that COBOL applications can access Db2 files in only one database and Db2 instance at a time. - Set environment variable DB2DBDFT to the intended database. For
example:
export DB2DBDFT=db2cob
- For the files that use Db2,
specify the Db2 file system
(either as the value of the
FILESYS
runtime option or directly in the assignment-name value). Use the fully qualified Db2 table name, including the schema name.For example, the following command completes the assignment of a transaction fileTRANFILE
to system file-name TEST.TRANS in the Db2 file system:export TRANFILE=DB2-TEST.TRANS
Creating Db2 files:
- By using an
OPEN
statement in your COBOL program - By using the TXSeries® or CICS® TX
cicsddt
utilityFor more information about the
cicsddt
command, see the TXSeries or CICS TX documentation referenced below.Note: Effective 9 August 2024, IBM withdraws from marketing IBM CICS TX Standard (5900-ALU) and IBM CICS TX Advanced (5737-K69). - By using the
db2 create
command
CICS
:
db2 create table cics.example\
"(rba char(4) not null for bit data, f1 varchar(80) not null for bit data)"
db2 create unique index cics.example0 on cics.example\
"(rba) disallow reverse scans"
db2 create unique index cics.example0@ on cics.example\
"(rba desc) disallow reverse scans"
db2 describe
command. For example:
> db2 describe table cics.example
Data type Column
Column name schema Data type name Length Scale Nulls
------------------------ --------- ------------------- ---------- ----- ------
RBA SYSIBM CHARACTER 4 0 No
F1 SYSIBM VARCHAR 80 0 No
2 record(s) selected.
The file CICS.EXAMPLE has
variable-length records that would be compatible with a COBOL FILE
SECTION
definition of minimum record length between 0 and
79.
For more information about the functions that are provided by
the db2
utility, enter the command db2.
For information about the additional requirements that apply to using Db2 files with TXSeries or CICS TX, see the related reference about the Db2 file system.