This blog outlines my efforts to use OpenESQL Assistant to create a native COBOL project that will extract data from a database with MicroFocus Visual COBOL and Visual Studio 2019.
(Note: A native COBOL project is not the same as a .NET COBOL application).A. Create a native console COBOL project.
1. From the Visual Studio menu, select File, New, Project.
2. Select the console application template, and then click Next.
3. Give the project a name, e.g. ConsoleApplication, and save in a a location e.g C:\ConsoleApplication.
4. Click on Create.
5. A new program, Program1.cbl will be created. Do not delete any text in this program.
B. Configure OpenESQL Assistant.
1. From the Visual Studio menu, select Tools, Options, MicroFocus, OpenESQL Assistant.
2. Change Type Global Variable to SQL TYPE (or standard), Mode to ODBC, Output Language to COBOL, generate EXEC SQL.
3. For the project, click on Project on the Visual Studio menu, scroll down to ConsoleApplicationProperties.
a. Select SQL (on left panel), ESQL Preprocessor, OpenESQL
b. Add directive, select DBMAN
c. Value ODBC for native.
d. Click OK
C. To start using OpenESQL Assistant
1. From the Visual Studio menu, select View, scroll down to MicroFocus SQL Tools, OpenESQL Assistant.
This will open the Assistant and point to a database. In my case. it points to a sample database TESTSQL32.
D. To create a new program using OpenESQL Assistant and the database.
1. Click on TESTSQL32 and select a table from the database. In my case, I selected the employee table.
2. Under Select Type of Query to create, click on SELECT(cursor). Then select the columns EmployeeID, Last Name, Position from the table. These will be added to the Query.
3. Click on Sort and move Last Name to the right column. The result will sort the data to be extracted by Last Name.
4. Click on Run Query to see the results.
(Note: Run Query is between Create New Query and Insert Query into project at the top left of the OpenESQL Assistant).
E. Add this query into the COBOL Program, Program1.cbl
1. Click on Auxiliary Code tab, scroll down to Generic SQL Program. This will generate some sample code.
2. Click on Insert Query Into Program. This will insert the generated code into the COBOL program, Program1.cbl
3. Check the COBOL program that the generated code is inserted. Check that you do not have two Working Storage Section and two Procedure Division. Delete one of each found at the bottom of the program.
4. In the OpenESQL Assistant, select Auxiliary Mode, Host Variable Declaration. This will generate a copybook called Employee.cpy. Click Save. It will be saved in the project folder.
5. Move back to the program, and place your cursor immediately before EXEC SQL END DECLARE. Go back to the Assistant and click on Insert Query into program.
6. Back in the program, right click on include employee statement and select Open "Employee.cpy" in a new window. This will show the details of the table Employee.
7. While in the program, place the cursor just before the EXEC SQL DISCONNECT. Go back to the Assistant and click on Insert Into Program.
F. Change the Display "ROW FOUND" and replace it with
DISPLAY
Employee-Employee-ID ' '
Employee-Last-Name ' '
Employee-Position
G. Insert this after END-PERFORM:
STOP ' '
(Note: This will hold the results on the console, otherwise it will appear and disappear in a flash).
H. Run the program
1. From Visual Studio Menu, click on Build. Hopefully, you will have a clean build with no errors.
2. Then Run the program. Click on Debug, Start without debugging.
I. The Results.
The results will show up on the console--just wait about 30 seconds.
REFERENCES:
Database Use, Chpt 15, pp.162-173. MicroFocus Publication. 2015-2016.
Using the OpenESQL Assistant, Appendix II. pp.276-289. MicroFocus Publication, 2015-2016.
POSTSCRIPT.
In this exercise, I was using MicroFocus Visual COBOL and Visual Studio 2019.
In its Chpt 15, Database Use publication, MicroFocus described registering a database with ODBC as follows:
From the Windows Start Menu, Select all Programs, MicroFocus Visual COBOL, Data Tools, Data Connection, ODBC Data Source Administration , etc
However, on my version of MicroFocus Visual COBOL, there is no Data Tools. Consequently, I could not use this method to connect to the sample Library database.
Maybe there is a way around this but I could not figure it out.
Dated: December 29, 2019.
No comments:
Post a Comment