Support for Nested COBOL Programs

The DB2 ECM supports nested COBOL programs, but in some cases requires specification of an additional DB2 compiler directive option.

For non-nested COBOL programs, the DB2 ECM generates DB2 interface code in the form of a BND file that is then bound into a DB2 LUW package. The base name of both the BND and the package file defaults to the base name of the source file. You can override the base name using the PACKAGE directive to specify an alternative name. See PACKAGE for details.

For nested programs, you can use one of the following DB2 ECM directives to define how DB2 interface code is generated for a single source file. These directives are mutually exclusive, meaning you can specify only one at a time for any given source file:

SINGLE_PACKAGE
This is the default behavior. For all programs defined in the source file, the DB2 ECM creates a single BND file; thus a single package is bound and stored in your DB2 LUW database. Because they are all bound into the same DB2 LUW package, all programs in the package share the same BIND timestamp token(s) as the main program. The naming conventions of the BND and package files follow the same rules as for non-nested programs. See SINGLE_PACKAGE for details on using this directive.
Important: Cursors that are shared among the programs in a given package must be uniquely named and defined within that package.
MULTI_PACKAGE
When specified, overrides the default SINGLE_PACKAGE behavior. For each program defined in the source file, the DB2 ECM creates a distinct BND file, each with its own BIND timestamp token(s), and a corresponding package.

The names generated for BND files and packages can differ depending on whether or not you also specify the PACKAGE directive with a parameter in addition to MULTI_PACKAGE.

Example 1: Compile DEMO.cbl with MULTI_PACKAGE

The names of generated BND and package files are based on the program ID of each nested program, and the BND file and package names for the main program are based on the base name of the source file as follows:

Program ID Resulting BND file name Resulting PACKAGE name
MAIN DEMO DEMO
SUB1 SUB1 SUB1
SUB2 SUB2 SUB2

Example 2: Compile DEMO.cbl with MULTI_PACKAGE and PACKAGE=TEST

The BND file and package names are modified to include the package name as follows:

Program ID Resulting BND file name Resulting PACKAGE name
MAIN DEMO TEST
SUB1 TESTSUB1 TESTSUB1
SUB2 TESTSUB2 TESTSUB2

See MULTI_PACKAGE for additional details on using this directive.

IGNORE-NESTED
If the main program in a source file contains EXEC SQL statements, or just one nested program contains EXEC SQL statements, you can use the IGNORE-NESTED directive to suppress the generation of DB2 interface code for the other programs in the source file.

If more than one nested program using EXEC SQL statements exists in the source file, you can specify IGNORE-NESTED with a program ID that, when encountered by the DB2 ECM, triggers the generation of DB2 interface code for that program only. The base name of the generated BND and package files is the same as the specified program ID.

If more than one nested program using EXEC SQL statements exists in the source file, and you specify IGNORE-NESTED without a program ID, the DB2 ECM locates the program with a program ID that matches the base name of the source file. In this case, The base name of the generated BND and package files is the same as base name of the source file.

See IGNORE-NESTED for details on using this directive.

Note: You can also specify the PACKAGE directive with a parameter to override the base names for the BND and package files.
Note: Each of these directives has a synonym that provides identical functionality and can be used as a substitute:
Directive Synonym
PACKAGE ACCESS
SINGLE_PACKAGE MULTI-NESTED
MULTI_PACKAGE ALLOW-NESTED