Tutorial: Generate and Embed a SQL Program

Now that the SQL query has been generated, you can use OpenESQL Assistant to generate a generic SQL program and embed the query right into it.

Requirements
Before attempting this tutorial, you must complete the following tutorials in the order listed:
  • Tutorial: Create a SQL Server Database
  • Tutorial: Create and Configure an Eclipse Project
  • Tutorial: Set OpenESQL Assistant Configuration Options
  • Tutorial: Catalog a Connection
  • Tutorial: Build and Test a Query
Generate a Generic SQL Program
  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.

Copy the Generic SQL Program to Program1.cbl
You can now replace the code in Program1.cbl with the generated SQL program code.
  1. From the Auxiliary Code tab, click Add Query to temporary fileAdd Query to temporary file.

    This copies the generated code to the clipboard.

  2. Click Save temporary fileSave temporary file to disk, and browse to the directory contains the Program1.cbl file you created earlier.
  3. Select program1.cbl; then click Save. A prompt appears, asking if you want to replace the current file.
  4. Click Yes.

Back in the COBOL editor in Eclipse, the Program1.cbl file is updated with the new code, and the file is saved in the project.

Embed the SQL Query
Next, you embed the generated SQL query into Program1.cbl.
  1. From the OpenESQL Assistant, click the Query tab; then click Add Query to temporary fileAdd Query to temporary file.
  2. In Eclipse, in the COBOL Editor, place the cursor on the line just after the comment:
    *> Put your program logic/SQL statements here
    
  3. Right-click; then select Paste.

    OpenESQL Assistant inserts the query into the program

  4. Click File > Save to save Program1.cbl.