We provide two Visual Studio projects that contain the base application files you need to complete the OpenESQL Managed Code tutorials. We also provide several tutorial-specific files. For each tutorial, you create one solution and project, add to each the files that are specific to the tutorial, and also add and reference the two projects that contain the base application. Therefore, each solution is tailored to its corresponding tutorial; however, the base application is essentially the same for each. Any nuances in tutorial-specific demonstration files are detailed in the individual tutorials.
The base application, referenced in these tutorials as BookDemo, is provided in two projects - SqlLegacyBook and SqlBookWrapper. To become familiar with how this application works, study the SqlLegacyBook Project and SqlBookWrapper Project sections below. These sections provide details of the programming logic, and how the projects work together.
To look at the source code directly, go to the %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\SQL\ado.net SqlLegacyBook and SqlBookWrapper subdirectories (default locations), and open the appropriate files in any text editor.
Look at the code for SqlBookWrapper.cbl. You see that the BookDetails method returns a pointer to the book-details host variable defined in book-rec-net.cpy. This host variable definition matches the working-storage host variable defined in book-rec.cpy and included by the sqlbook.cbl program. In effect, this enables the sqlbook.cbl program to see the book-detail host variable it expects, passed in by reference. The address is sent to it by reference to allow sqlbook.cbl code to update book-details based on SQL return values. sqlbook.cbl reads the stock number from this host variable, reads a database record from SQL Server, and then puts the data into the fields of the book-details host variable, and ultimately updates the values in SqlBookWrapper.cbl.
This is the main project used to query the SQL Server database. The project contains:
This is the intermediary project that maps .NET data types onto COBOL data types. The project contains:
method-id get property BookDetails.
procedure division returning bookDetailsAddress as pointer.
set bookDetailsAddress to address of book-details
end method.
method-id CallLegacyWithRunUnit.
local-storage section.
01 book-status pic x(5).
01 book-message pic x(80).
procedure division using by value bookFunction as string.
declare myRunUnit = new RunUnit()
declare myProgram = new type SqlLegacyBook()
declare myPossibleException as type System.Exception = null
try
invoke myRunUnit::Add(myProgram)
invoke myProgram::SqlLegacyBook(by value bookFunction, by reference self::BookDetails, by reference book-status, by reference book-message)
catch e as type System.Exception
*> To catch a specific exception, specify the exception type in the CATCH above
set myPossibleException to e
set book-message to e::Message
finally
invoke myRunUnit::StopRun(0)
end-try
invoke self::RaiseExceptionIfError(book-status, book-message, myPossibleException)
end method.
Where:
working-storage section.
copy "book-rec-dotnet.cpy" replacing == (prefix) == by == book ==.
...
The contents of book-rec-dotnet.cpy are:
01 (prefix)-details.
03 (prefix)-text-details.
05 (prefix)-title pic x(50) property as "Title".
...
03 (prefix)-stockno pic x(4) property as "StockNumber".