This tutorial walks you through the creation of an object-oriented Windows ASP.NET Web application that interacts with the BookDemo base application using SQL. The project you create includes a page that is generated in managed COBOL. This page calls an intermediary class method to funnel all requests from the Web page to a single routine. This encases the functionality within a run unit for isolation of resources, such as database connections, for any function triggered from the Web page. The intermediary class method then calls the business logic class method to perform the work and access the database.
To complete this tutorial, you must have the ASP.NET and Web Applications feature installed in Enterprise Developer. If this feature is missing, see To install missing features from the IDE for installation instructions.
The OOSQLBookDemoWebApplication solution and project you create for this tutorial uses the following provided demonstration files in addition to the BookDemo base application:
This generates and populates the appropriate table.
In this procedure, you create the OOSQLBookDemoWebApplication solution and project, which contains skeleton versions of the files listed in the Demonstration Solution section.
Name | OOSQLBookDemoWebApplication |
Location | Full path to any local directory; for example, c:\VSTutorials |
Solution Name | OOSQLBookDemoWebApplication |
Framework | Choose the appropriate .NET Framework version from the drop-down list.
Note: Must be .NET Framework 4.5 or higher.
|
01 my-book type OOSqlBookWrapper.SqlBook.
The default Web.config file added when you created the solution does not contain the configuration code needed to access the COBOL runtime and configure the project to run COBOL applications. Here, you replace the default file with a provided updated file.
<asp:Label ID="Label1" runat="server" Text="CATALOG SEARCH"></asp:Label> <asp:Label ID="catalogNumberLabel" runat="server" Text="Catalog Number"></asp:Label> <asp:TextBox ID="textBoxStockNo" runat="server"></asp:TextBox> <asp:Button ID="searchButton" runat="server" Text="Search" OnClick="searchButton_Click" /> <asp:Label ID="errorLabel" runat="server" Text="Status" Visible="False"></asp:Label> <asp:TextBox ID="errorField" runat="server"></asp:TextBox> <asp:Label ID="Label2" runat="server" Text="RESULTS"></asp:Label> <asp:Label ID="titleLabel" runat="server" Text="Title"></asp:Label> <asp:TextBox ID="textBoxTitle" runat="server"></asp:TextBox> <asp:Label ID="authorLabel" runat="server" Text="Author"></asp:Label> <asp:TextBox ID="textBoxAuthor" runat="server"></asp:TextBox> <asp:Label ID="typeLabel" runat="server" Text="Type"></asp:Label> <asp:TextBox ID="textBoxType" runat="server"></asp:TextBox> <asp:Label ID="priceLabel" runat="server" Text="Price"></asp:Label> <asp:TextBox ID="textBoxPrice" runat="server"></asp:TextBox> <asp:Label ID="soldLabel" runat="server" Text="Sold"></asp:Label> <asp:TextBox ID="textBoxSold" runat="server"></asp:TextBox> <asp:Label ID="onHandLabel" runat="server" Text="On Hand"></asp:Label> <asp:TextBox ID="textBoxOnHand" runat="server"></asp:TextBox> <asp:Label ID="stockValueLabel" runat="server" Text="Stock Value"></asp:Label> <asp:TextBox ID="textBoxStockValue" runat="server"></asp:TextBox>
This opens Default.aspx.cbl in the COBOL editor, and inserts a searchButton_Click method into the code. This method is known as a Click Event. At this point in development, the method is empty.
This calls the legacy program and provides input values.
method-id searchButton_Click protected. working-storage section. 01 book type OOSqlBookWrapper.SqlBook. 01 anException type System.Exception. 01 bookFunction string. local-storage section. procedure division using by value lnkSender as object by value lnkEvent as type EventArgs. try set book to type OOSqlBookWrapper.SqlBook::New() set book::StockNumber to textBoxStockNo::Text set bookFunction to "1" invoke book::CallLegacyWithRunUnit(bookFunction) invoke self::PopulateForm(book) catch anException invoke self::DisplayException(anException) end-try end method.
method-id PopulateForm final private. procedure division using aBook as type OOSqlBookWrapper.SqlBook. if aBook <> null set errorLabel::Visible to false set errorField::Visible to false set textBoxStockNo::Text to aBook::StockNumber set textBoxTitle::Text to aBook::Title set textBoxAuthor::Text to aBook::Author set textBoxType::Text to aBook::Type set textBoxPrice::Text to type System.Convert::ToString(aBook::RetailPrice) set textBoxOnhand::Text to type System.Convert::ToString(aBook::NumberOnHand) set textBoxSold::Text to type System.Convert::ToString(aBook::NumberSold) set textBoxStockValue::Text to type System.Convert::ToString(aBook::StockValue) else set textBoxStockNo::Text to "****" set textBoxTitle::Text to "*************************************" set textBoxAuthor::Text to "*************************************" set textBoxType::Text to "****" set textBoxPrice::Text to "****" set textBoxOnhand::Text to "****" set textBoxSold::Text to "****" set textBoxStockValue::Text to "*****" end-if end method. method-id DisplayException private. procedure division using by value lnkException as type System.Exception. set my-book to null set errorLabel::Visible to true set errorField::Visible to true set errorField::Text to lnkException::Message invoke self::PopulateForm(my-book) end method.