In DB2, what is a plan and what role does it play in executing embedded SQL programs?

Difficulty: Medium

Correct Answer: A DB2 plan is an executable control structure created by the BIND process that identifies one or more packages and contains information about how DB2 will execute their SQL statements at runtime

Explanation:


Introduction / Context:
On IBM mainframe systems, DB2 uses specific runtime objects to manage how application programs execute SQL statements. One of these key objects is the DB2 plan. Questions about plans and packages appear frequently in interviews for COBOL-DB2 and mainframe developer roles because they test understanding of how static SQL moves from compilation to runtime execution under DB2 for z/OS.


Given Data / Assumptions:

  • We are working with DB2 for z/OS or a similar mainframe environment.
  • Application programs, such as COBOL programs, contain embedded static SQL statements.
  • These programs go through precompilation, compilation, link-edit, and BIND steps before execution.


Concept / Approach:
A DB2 plan is a runtime control structure created by the BIND process. It associates one or more DB2 packages, which contain the optimised access paths for SQL statements, with an executable application. The plan tells DB2 which packages the program may use and defines authorisation and resource usage rules. When the application runs, DB2 uses the plan to locate and execute the appropriate packages and to manage how SQL statements are processed. Plans are stored in DB2 catalog tables and are essential for static SQL execution.


Step-by-Step Solution:
Step 1: The programmer writes a COBOL or other host language program that includes embedded SQL. Step 2: The program is precompiled, which separates SQL statements from host code and produces DBRM (Database Request Module) members and modified host language source. Step 3: The host program is compiled and link-edited to produce an executable load module. Step 4: A BIND PACKAGE step converts one or more DBRMs into packages, each containing SQL statements and their chosen access paths. Step 5: A BIND PLAN step creates a DB2 plan that references one or more packages; at runtime, the plan is used by DB2 to determine which SQL to execute and how, based on the access paths stored in the packages.


Verification / Alternative check:
You can verify the role of plans by examining DB2 catalog tables such as SYSIBM.SYSPLAN and related package tables. These catalog entries show which packages are bound into which plans. If a program attempts to run without a valid plan, DB2 will issue errors indicating that no plan is available, demonstrating that the plan is a required runtime object. Performance utilities and accounting reports in DB2 also reference plan names, further confirming their central role in tracking and controlling SQL execution.


Why Other Options Are Wrong:
Option B is incorrect because table rows are stored in table spaces and VSAM datasets, not in plans. Option C is wrong because a plan is a real DB2 catalog object, not merely a graphical design aid. Option D is incorrect because starting and stopping DB2 is handled by JCL procedures, operator commands, and subsystem control statements, not by DB2 plans.


Common Pitfalls:
A common pitfall is confusing plans with packages and DBRMs. New developers may think that only one of these is necessary or fail to understand the connections between them. Another issue is binding too many unrelated programs into a single plan, which can complicate maintenance and security. It is also important to rebind plans when statistics or access patterns change significantly so that the optimiser can choose better access paths. Clear understanding of DB2 plans helps in tuning, troubleshooting, and managing application deployments on the mainframe.


Final Answer:
A DB2 plan is an executable control structure created by the BIND process that identifies one or more packages and contains information about how DB2 will execute their SQL statements at runtime for an application program.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion