Generate and Embed an SQL Program and Query

Walks you through the process of using the OpenESQL Assistant to generate a generic COBOL SQL program, embedding the program into an existing COBOL program in the OESQLAsst project, and adding the generated SQL query to the program.

Generate a generic SQL Pprogram

  1. In the OpenESQL Assistant, click the Auxiliary Code tab.
  2. From the Statement Type drop-down list, select Generic SQL Program.

    OpenESQL Assistant generates a generic SQL program in the Generated Auxiliary Code box on the Auxiliary Code tab.

Replace the code in Program1.cbl with the code generated by the OpenESQL Assistant

  1. On the Solution Explorer in Visual Studio, double-click Program1.cbl.

    This opens the file in the COBOL Editor with the cursor placed at the very beginning of the file.

    Note: The Program1.cbl program file was automatically generated and added to the OESQLAsst project when the project was created.
  2. Select and delete all text in the file.
  3. Switch to the OpenESQL Assistant window.
  4. In the OpenESQL Assistant, with the Auxiliary Code tab showing in the right pane, click Insert query into program (Insert query into program).
  5. Switch back to Program1.cbl in the COBOL Editor.

    You can see that the generated code now appears in Program1.cbl.

  6. Click Save (Save) to save the program file. Do not close the COBOL Editor.

Embed the SQL Query into program1.cbl

  1. In Visual Studio, in the COBOL Editor, place the cursor on the line just after the comment:
    *> Put your program logic/SQL statements here
    
  2. On the OpenESQL Assistant, click the Query tab; then click Insert query into program (Create New Query) from the toolbar.
  3. Switch back to Program1.cbl in the COBOL Editor.

    You can see that the generated query code now appears in Program1.cbl.

  4. Click Save (Save) to save the program file. Do not close the COBOL Editor.