Tutorial: Developing Web Application Projects

Overview

This tutorial shows how to create a COBOL Web application project and how to make it interact with an existing COBOL program. The project includes a page that is generated in managed COBOL. The page calls an intermediary program to map .NET data types onto COBOL data types. The intermediary program then calls the existing COBOL program to perform the business logic.

The Web application project has three programs:

  • A Web page. The Microsoft form designer enables you to create a Web page (also known as a Web form) in any .NET language, such as C# and COBOL. This tutorial shows how to generate these forms in .NET COBOL.
  • Existing COBOL program, the Book program. This program simulates a pre-existing COBOL program, which contains the business logic and which remains unchanged. This program is supplied and this tutorial adds it as a reference to the Web application project so that it is recompiled as managed code and exposed as a class that can be called by .NET managed code without needing any changes to the source.
  • Intermediary COBOL class, the BookWrapper program. This program acts as an interface between the client form and the pre-existing COBOL program. This intermediary class interfaces with the .NET client form using objects, and it interfaces with the existing COBOL using the standard COBOL PIC X data types. This intermediary class is supplied and this tutorial adds it as a reference to the Web application project.

Create a Web Application Project

The first task is to create a Web Application Project, which you do as follows:

  1. Start Visual Studio.
  2. Create a new Web Application Project by clicking File > New > Project.
  3. Expand Installed > Templates > COBOL and click Web.
  4. Ensure .NET Framework 4.5 is selected in the dropdown list above the installed templates pane.
  5. Select ASP.NET Web Application.
  6. Specify a name such as BookDemoWebApplication.
  7. Specify a location to store the project on your file system such as c:\tutorials.
  8. Uncheck Create Directory for Solution.
  9. Click OK.

This creates the BookDemoWebApplication project, which is shown in the Solution Explorer. The project includes:

  • App_Data, which is an empty folder for holding application data
  • Default.aspx, which is the trigger program that displays the main form
  • Default.aspx.cbl, which contains your code for the form
  • Web.config, which is the application configuration file

Add the Legacy Code and the Wrapper Code

You now need to add the existing COBOL code that contains the business logic, so that the form can use it. This code is supplied in a LegacyBook project containing book.cbl.

In addition, you need some wrapper code to convert the data from .NET types to COBOL types. The project uses .NET data types; these are System.String objects in our case. The book program uses COBOL types such as PIC X and PIC 99V99. The supplied program BookWrapper.cbl does this conversion, and you need to add this to the solution.

The supplied files are in the %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples and in the Forms subfolder.

To include dependant code in your Web application project, you need to add a reference to the code in your solution as follows:

  1. Right-click the solution in Solution Explorer.
  2. Click Add > Existing Project.
  3. Navigate to the Forms\BookWrapper subfolder in the Samples directory.
  4. Select the .cblproj file and click Open.
  5. Similarly, add the LegacyBook project from the Forms\LegacyBook subfolder in the Samples.
  6. Add the two projects as references to the BookDemoWebApplication project as follows:
    • Right-click BookDemoWebApplication in Solution Explorer and click Add Reference.
    • Expand Solution in the left-hand pane and then click Projects.
    • Check the BookWrapper and the LegacyBook projects and click OK.

      The projects are now added to the References folder in your solution.

Provide Access to the Legacy Code

You now need to add some code to the form to call the wrapper code:

  1. Open Default.aspx.cbl and declare the data item my-book in the working storage section, as follows:
           01 my-book   type BookWrapper.Book.