.NET Host Variables in .NET COBOL Code

For your .NET COBOL applications, OpenESQL provides the option of using traditional host variable declarations, and an option to use .NET data types as your host variable declarations. Use of .NET data types is made possible by the OpenESQL Managed Runtime, specified by setting the DBMAN directive option to ADO.

When your .NET COBOL application contains traditional host variable declarations using PIC clauses, this requires the OpenESQL Managed Runtime to read each PIC clause and convert it to the equivalent .NET type. However, by declaring your host variables using the .NET data types in place of the PIC clause, you get these advantages:
  • Improved performance - it is not necessary for the OpenESQL Managed Runtime to translate PIC clauses to .NET types, thereby greatly enhancing performance.
  • No size restrictions - .NET variables in .NET COBOL applications are not restricted in size, whereas native COBOL applications have size restrictions on host variables, especially for applications that involve LOB data.
  • Improved application portability - the managed runtime simplifies the process of porting existing native EXEC SQL applications to .NET.
When coding your applications to use .NET host variables, keep in mind:
  • All .NET host variables must be defined at the 01 level or compiler errors result.
  • Syntax for common .NET data types can be defined with the short name. For example, System.String can be defined simply as:
    01 myName string.
  • Syntax for other .NET variables typically include a TYPE clause. For example:
    01 myDate type System.DateTime.
  • If a specific .NET type doesn't exist for an SQL data type provided by a vendor, you can use OBJECT as the host variable type. For example:
    01 myData object.
Note:
  • Only the OpenESQL preprocessor supports the use of .NET host variables. Currently, no DBMS vendors provide direct support for EXEC SQL syntax in .NET applications.
  • For complete information on declaring .NET host variables for the OpenESQL Managed Runtime, see the reference topics under SQL Data Types.
  • The OpenESQL Assistant provides an easy method of generating .NET host variables for a table via the DCLGEN option in the tool. See OpenESQL Assistant for more information on how to generate copybooks in this format.

Example: Defining .NET host variables

  *> -------------------------------------------
       *> COBOL HOST VARIABLES FOR TABLE EMP
       *> -------------------------------------------
       01  EMP-EMPNO                          STRING.
       01  EMP-FIRSTNME                       STRING.
       01  EMP-MIDINIT                        STRING.
       01  EMP-LASTNAME                       STRING.
       01  EMP-WORKDEPT                       STRING.
       01  EMP-PHONENO                        STRING.
       01  EMP-HIREDATE                       type System.DateTime.
       01  EMP-JOB                            STRING.
       01  EMP-EDLEVEL                        BINARY-SHORT.
       01  EMP-SEX                            STRING.
       01  EMP-BIRTHDATE                      type System.DateTime.
       01  EMP-SALARY                         DECIMAL.
       01  EMP-BONUS                          DECIMAL.
       01  EMP-COMM                           DECIMAL.


EXEC SQL 
 SELECT 
        A.FIRSTNME
       ,A.LASTNAME
       ,A.HIREDATE
       ,A.SALARY
       ,A.EMPNO
INTO 
        :EMP-FIRSTNME
       ,:EMP-LASTNAME
       ,:EMP-HIREDATE:EMP-HIREDATE-NULL
       ,:EMP-SALARY:EMP-SALARY-NULL
       ,:EMP-EMPNO
   FROM HCOSQL.EMP A
  WHERE (A.EMPNO = :EMP-EMPNO)
END-EXEC