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
Visual Studio Solution
The
Visual Studio solution we provide for this tutorial contains
two HCOSS projects. The
TwoPackageSet project is a native COBOL project.
The
MTwoPackageSet project is a managed COBOL project. However, the COBOL code is the same in both projects.
Phase 1: Start
Enterprise Developer and HCO for SQL Server
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
Visual Studio, click
View > Micro Focus SQL Tools > HCO for SQL Server Tools.
Phase 2: Analyze the Native Application
- From the Visual Studio IDE, open the solution named
TwoPackageSet, which is located in the
%PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Mainframe\SQL\hcoss\TwoPackageSet directory.
- From the
Solution Explorer,
open 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.
- Notice that the
Output type on the
Application tab is
Console Application.
- Switch to the
COBOL tab, and set the following:
Configuration
|
Debug
|
Platform target
|
x86 (default)
|
- Switch to the
SQL tab. 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(DETECTDATE)
|
Converts date/time strings
|
SQL(INIT)
|
Initiates the database connection
|
SQL(MARS)
|
Enables multiple active results sets
|
SQL(QUALIFIER=TEST)
|
Schema qualifier is TEST
|
SQL(NOCHECK)
|
No SQL compile-time checking performed
|
- Close the Properties window.
Phase 3: Build the Native Application
- From the Solution Explorer, rebuild the
TwoPackageSet project, thereby generating a DBRM for the application.
- Verify that the project built successfully.
Phase
4: 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
5: Run the Native Application
- From the
Solution Explorer in
Visual Studio, open the
TwoPackageSet.cbl source file.
- Set a break point on the STOP RUN line.
- Press
F5 to start debugging.
- Use the tools available from the
Debug toolbar or menu 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.
Phase 6: Analyze, Build, Bind, and Run the Managed Application
- Analyze the Managed Application
-
- From the Solution Explorer, switch the starting project: Right-click the
MTwoPackageSet project and select
Set as StartUp Project.
- Open the project properties for the
MTwoPackageSet project.
- Click the
SQL tab. Notice the directive settings for the OpenESQL ESQL Preprocessor include SQL(DBMAN=ADO). This means that we're using the ADO.NET database connection rather than the ODBC database connection.
- Close the Properties window.
- Build the Managed Application
-
- From the Solution Explorer, right-click the
MTwoPackageSet project and select
Rebuild.
- Bind the Managed Application
-
- From the HCO for SQL Server interface, go to the
Bind Scripts tab of the Manage Packages and Plans tool.
- Click
Execute All, to execute all of the BIND commands listed. Because the application was rebuilt as a managed application, HCOSS uses the same commands to create and bind the packages and plan to the managed version of the application.
- Run the Managed Application
-
- From the Solution Explorer in Visual Studio, open the
TwoPackageSet.cbl source file.
- Set a break point on the STOP RUN line.
- Run the application.
You should see the same data output that you saw when you ran the native application, indicating that the program is switching package sets between row fetches.
This completes the tutorial.