Tuesday, July 7, 2020

Creating an Interactive Webform with Visual Cobol 6.0 and Visual Studio 2019

This project was created using Visual COBOL 6.0 and Visual Studio 2019.  The objective was to interactively extract data from an indexed COBOL datafile and apply the result to a webform.

To begin, start up Visual Studio. Select File, New, Project.  Select ASP.NET Web Application for COBOL as the template.  Framework should be .NET Framework 4.6.

Give the project a name and a storage location. Click Create.  This should open up a form.

Go to Solution Explorer and add the projects LegacyBook and BookWrapper to the application as well as into the reference of the application.  LegacyBook is a procedural COBOL project that contains the business logic which the form can use.  LegacyBook uses COBOL types such as PIC X and PIC 99V99.  The BookWrapper project converts data from .NET types to COBOL types.

Note that LegacyBook requires a copybook (book-rec.cpy) and so does the BookWrapper project (book-rec-dotnet.cpy).

At this point, it is time to paint the Webform.  Painting the labels, buttons and textboxes on to the form was done by direct coding in the Default.aspx file and not by dragging and dropping them from the Toolbox.  The attachment below shows the Default.aspx file with the coding for this project.

 

The Default.aspx file showing the coding for the webform

Once the form has been drawn, it is time to add the following code to the Web.config file.

 

The Web.config file

Note that the indexed COBOL data file (bookfile.dat) is added to the Web.config file.

 

Next add the following code in the Default.aspx.cbl file.

 

The Default.aspx.cbl file that activates all the controls on the form

 This file activates the Search button, populates the form from the datafile and manages any error handling.

 At this point, there should be no errors in the project as shown on the bottom left of the Visual Studio screen.

 Run the application if no errors are identified.  Select Rebuild and then Debug, Start without Debugging.

 Visual Studio will  complete the above two processes and finally display the form.

 To display the results, enter four digits (from 1111 to 6666) in the book number field and click Search.

 

The completed webform with a search result for book number 2222

The form should be filled up with the results of the search.  The following shows a search for book number 2222.