Tutorial: Application Migration - Switching Package Sets

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 Tools

If Enterprise Developer and HCOSS for SQL Server tools are already running, skip this phase.

  1. 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.
  2. In Visual Studio, click View > Micro Focus SQL Tools > HCO for SQL Server Tools.

Phase 2: Analyze the Native Application

  1. 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.
  2. From the Solution Explorer, open the TwoPackageSet.cbl file to view its contents. Pay particular attention to the EXEC SQL statements.
  3. Close the code editor.
  4. Open the project properties for the TwoPackageSet project.
  5. Notice that the Output type on the Application tab is Console Application.
  6. Switch to the COBOL tab, and set the following:
    Configuration Debug
    Platform target x86 (default)
  7. 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(INIT) Initiates the database connection
    SQL(NOCHECK) No SQL compile-time checking performed
  8. Close the Properties window.

Phase 3: Build the Native Application

  1. From the Solution Explorer, rebuild the TwoPackageSet project, thereby generating a DBRM for the application.
  2. 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
  1. From the HCO for SQL Server interface, click Manage Packages and Plans.
  2. From the SQL Server Connection drop-down list, select HCODemo.
Create Two Packages
  1. Click New Package. Then specify the following:
    Property Value
    Collection Name TEST
    Library Name <Default>
    Member Name TWOPACKAGESET
    Default Qualifier TEST
    Action Replace
  2. Click Execute. This creates the package in the database.
  3. Change the Collection Name to PROD and the Default Qualifier to PROD.
  4. Click Execute. This creates a second package.
  5. 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
  1. Click New Plan.
  2. In the Plan Name field, type TWOPACKAGESET.
  3. On the Available Collections list, click PROD.
  4. On the Available Packages list, click TWOPACKAGESET.
  5. Click Add to add this package to the Selected Packages list.
  6. Repeat steps 3 through 5, substituting TEST instead of PROD, to add the TEST.TWOPACKAGESET package to the Selected Packages list.
  7. In the Action group, click Replace.
  8. Click Execute to add the BIND PLAN entry to the script and to also bind the plan.
Verify the Results
  1. Using Microsoft SQL Server Management Studio, connect to your SQL Server instance.
  2. 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.
  3. 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

  1. From the Solution Explorer in Visual Studio, open the TwoPackageSet.cbl source file.
  2. Set a break point on the STOP RUN line.
  3. Press F5 to start debugging.
  4. 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
  1. From the Solution Explorer, switch the starting project: Right-click the MTwoPackageSet project and select Set as StartUp Project.
  2. Open the project properties for the MTwoPackageSet project.
  3. 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.
  4. Close the Properties window.
Build the Managed Application
  • From the Solution Explorer, right-click the MTwoPackageSet project and select Rebuild.
Bind the Managed Application
  1. From the HCO for SQL Server interface, go to the Bind Scripts tab of the Manage Packages and Plans tool.
  2. 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
  1. From the Solution Explorer in Visual Studio, open the TwoPackageSet.cbl source file.
  2. Set a break point on the STOP RUN line.
  3. 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.