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

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

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 Eclipse, click Run > Tools > Data Tools > HCO for SQL Server.

Phase 2: Analyze the Native Application

  1. From the Eclipse IDE, click File > Import.
  2. Expand General, and select Existing Projects into Workspace; then click Next.
  3. Select Set root directory; then browse to the %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Mainframe\Eclipse\SQL\hcoss\TwoPackageSet directory, and click OK.
  4. On the Projects list, check TwoPackageSet.
  5. Check Copy projects into workspace.
  6. Click Finish. Eclipse loads the project and builds it automatically.
  7. 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.
  8. Close the code editor.
  9. Open the project properties for the TwoPackageSet project.
  10. 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(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
  11. 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
  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 4: Run the Native Application

  1. From the COBOL Explorer in Eclipse, open the TwoPackageSet.cbl source file.
  2. Set a break point on the STOP RUN line.
  3. Click Run > Debug to start debugging.
  4. If prompted with the Debug As dialog box, select COBOL Application; then click OK.
  5. When prompted to open the Debug perspective, click Yes.
  6. 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.