Previous Topic Next topic Print topic


JVM Host Variables in Managed Code

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

When your managed 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 JVM type. However, by declaring your host variables using the JVM 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 JVM types, thereby greatly enhancing performance.
  • No size restrictions - JVM variables in managed 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 JVM.
When coding your applications to use JVM host variables, keep in mind:
  • All JVM host variables must be defined at the 01 level or compiler errors result.
  • Syntax for common JVM data types can be defined with the short name. For example, System.String can be defined simply as:
    01 myName string.
  • Syntax for other JVM variables typically include a TYPE clause. For example:
    01 myDate type java.sql.Timestamp.
  • If a specific JVM 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 JVM host variables. Currently, no DBMS vendors provide direct support for EXEC SQL syntax in JVM applications.
  • For complete information on declaring JVM host variables for the OpenESQL Managed Runtime, see the reference topics under SQL Data Types.
  • The OpenESQL Assistant provides an easy method of generating JVM 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 JVM 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 java.sql.Timestamp.
       01  EMP-JOB                            STRING.
       01  EMP-EDLEVEL                        BINARY-SHORT.
       01  EMP-SEX                            STRING.
       01  EMP-BIRTHDATE                      type java.sql.Timestamp.
       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
Previous Topic Next topic Print topic