This tutorial takes you through the process of migrating a DB2 application to a SQL Server application, using HCOSS to switch
package sets and alternate fetching data using a single cursor name.
This tutorial also demonstrates how, with HCOSS, you can bind the application using the HCOSS Manage Packages and Plans tool.
Requirements
Before attempting this tutorial, you must first complete the following tutorials to ensure you have an established SQL Server
database named HCO_Test containing the required PROD and TEST schemas and a connection to the HCO_Test database:
- Tutorial: Create a SQL Server Database
- Tutorial: Create a Database Connection
- Tutorial: DB2 Database Migration or
Tutorial: Setup for Application Migration Tutorials
Eclipse Project
The
Eclipse project we provide for this tutorial contains
the
TwoPackageSet project, which is a native COBOL project.
Phase 1: Start
Enterprise Developer and HCO for SQL Server Tools
If
Enterprise Developer and HCOSS for SQL Server tools are already running, skip this phase.
- Start
Enterprise Developer as an administrator. This procedure varies depending on your Windows version. If you need instructions, see
To start
Enterprise Developer as an administrator.
- In
Eclipse, click
Run > Tools > Data Tools > HCO for SQL Server.
Phase 2: Analyze the Native Application
- From the Eclipse IDE, click
File >
Import.
- Expand
General, and select
Existing Projects into Workspace; then click
Next.
- Select
Set root directory; then browse to the
%PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Mainframe\SQL\hcoss\TwoPackageSet directory, and click
OK.
- On the
Projects list, check
TwoPackageSet.
- Check
Copy projects into workspace.
- Click
Finish. Eclipse loads the project and builds it automatically.
- From the
COBOL Explorer,
expand
TwoPackageSet > COBOL Programs; then double-click the
TwoPackageSet.cbl file to view its contents. Pay particular attention to the EXEC SQL statements.
- Close the code editor.
- Open the project properties for the
TwoPackageSet project.
- Expand
Micro Focus > Project Settings > COBOL; then select
SQL Settings. Several OpenESQL compiler directives have been set for you. The following table offers a brief description of each:
SQL(BEHAVIOR=OPTIMIZED)
|
Optimizes ambiguous cursor declarations
|
SQL(DBMAN=ODBC)
|
Uses an ODBC connection
|
SQL(TARGETDB=MSSQLSERVER)
|
Target database is SQL Server
|
SQL(DB=HCODemo)
|
SQL Server connection name is HCODemo
|
SQL(DIALECT=MAINFRAME)
|
HCOSS database syntax conversion is enabled
|
SQL(DBRMLIB)
|
EXEC-SQL commands are extracted and placed in database request module (DBRM)
|
SQL(INIT)
|
Initiates the database connection
|
SQL(NOCHECK)
|
No SQL compile-time checking performed
|
- Close the Properties window.
Phase
3: Bind the Native Application
Here, you bind the application to the DBRM generated when the application was built. You do this using the HCOSS Manage Packages
and Plans tool to create two packages and a plan. Each package you create is in its own collection and has a unique qualifier,
but both point to the same source member and library. You then bind both packages into one plan.
- Start the Manage Packages and Plans Tool
-
- From the HCO for SQL Server interface, click
Manage Packages and Plans.
- From the
SQL Server Connection drop-down list, select
HCODemo.
- Create Two Packages
-
- Click
New Package. Then specify the following:
Property
|
Value
|
Collection Name
|
TEST
|
Library Name
|
<Default>
|
Member Name
|
TWOPACKAGESET
|
Default Qualifier
|
TEST
|
Action
|
Replace
|
- Click
Execute. This creates the package in the database.
- Change the
Collection Name to
PROD and the
Default Qualifier to
PROD.
- Click
Execute. This creates a second package.
- Switch to the
Bind Scripts tab. Notice the BIND script commands that were created as a result of creating each package.
- Bind the Two Packages into a Plan
-
- Click
New Plan.
- In the
Plan Name field, type
TWOPACKAGESET.
- On the
Available Collections list, click
PROD.
- On the
Available Packages list, click
TWOPACKAGESET.
- Click
Add to add this package to the
Selected Packages list.
- Repeat steps 3 through 5, substituting
TEST instead of
PROD, to add the
TEST.TWOPACKAGESET package to the
Selected Packages list.
- In the
Action group, click
Replace.
- Click
Execute to add the BIND PLAN entry to the script and to also bind the plan.
- Verify the Results
-
- Using Microsoft SQL Server Management Studio, connect to your SQL Server instance.
- On the Object Explorer, expand
Databases > HCO_Test > Programmability > Stored Procedures to see the stored procedures HCOSS created when you executed your packages and plan.
- Open one of the stored procedures that contains
PKG as part of its name.
In this, you see the SQL from your application code. You also see SQL Server function calls to UPPER. These were converted
from DB2 function calls to UCASE. This is due to having set the SQL(DIALECT=MAINFRAME) directive when you compiled.
Phase
4: Run the Native Application
- From the
COBOL Explorer in
Eclipse, open the
TwoPackageSet.cbl source file.
- Set a break point on the STOP RUN line.
- Click
Run > Debug to start debugging.
- If prompted with the Debug As dialog box, select
COBOL Application; then click
OK.
- When prompted to open the Debug perspective, click
Yes.
- Click
Resume to continue to your breakpoint.
You should see from the output that alternating rows are coming from different database schemas. This demonstrates the use
of a single cursor to switch package sets, pulling data from different schemas.
Note: If the output window is not visible, minimize Eclipse to reveal it.
This completes the tutorial.