[Migrated content. Thread originally posted on 20 February 2012]Using embedded SQL statements in a COBOL program is a fairly common thing to do but even if you've been doing this for a while, it's not always clear what options are available. Here's a quick summary of what you can do and when you need to opt for one approach over another.
Generally speaking, there are 2 approaches to accessing a database from a COBOL program that contains embedded SQL statements:
1. Use the Database vendor’s pre-compiler. The pre-compiler takes as input the COBOL source file and outputs another file that is compiled by the Micro Focus COBOL compiler.
2. Use Micro Focus OpenESQL technology.
There are some upsides and drawbacks to using the a pre-compiler:
1. The pre-compiler can offer extra performance over OpenESQL but this is generally negligible.
2. The pre-compiler allows you to access non-standard DB-specific extensions.
3. Compilation is a two stage process. Pre-compiler and then COBOL compilation.
4. The debugging experience isn’t integrated – the developer debugs the pre-compiler output and not the actual embedded SQL originally coded.
5. Pre-compilers do not currently support managed code, JVM or .NET.
COBSQL -- Micro Focus provides a technology called COBSQL which improves the developer experience when using pre-compilers. Points 3 and 4 are much improved using this technology.
OpenESQL provides ubiquitous database access. No database vendor pre-compiler is required. Again, upsides and drawbacks:
1. OpenESQL is database agnostic, COBOL programs can be switched to use a new database with no changes.
2. OpenESQL is the only technology which allows ADO.NET and JDBC access by COBOL programs.
3. Performance may be slightly reduced over pre-compilers but this is generally negligible.
4. OpenESQL may not support non-standard ANSI SQL extensions that some database vendors provide. So it is possible that moving to ESQL from a pre-compiler will require updating the code to replace these extensions.
Database vendors take responsibility for certifying their pre-compilers with Micro Focus technology. However, Micro Focus also tests all the major databases, DB2 LUW, Oracle and SQLServer.
For other databases, vendors that provide ODBC access to their database can be accessed with Micro Focus OpenESQL technology. There are on occasion nuances we encounter with the ODBC implementations of some vendors, when we discover these we usually rectify within OpenESQL.