Coding SQL statements in application programs: General information

IMS provides a way to issue SQL statements directly in a COBOL application to access your IMS data. IMS uses the same SQL coding techniques as Db2 for z/OS® when programming IMS SQL for COBOL.

Procedure

To include a SQL statement in an application program:

  1. Choose one of the following methods for communicating with IMS:
    • Embedded dynamic SQL
    • JDBC application support

    If you are writing your applications in Java™, you can use JDBC application support to access IMS.

    If you are writing your applications for COBOL, use embedded dynamic SQL.

  2. Define an SQL communications area (SQLIMSCA) that for your COBOL program can use to check whether an SQL statement executed successfully.
  3. Define at least one SQL descriptor area (SQLIMSDA).
  4. Declare any of the following data items for passing data between IMS and COBOL:
    • host variables
    • host structures
    Ensure that you use the appropriate data types.
  5. Code SQL statements to access IMS data.

    If you are using a SELECT statement to query IMS data, use cursors to select a set of rows and then process one row at a time.

  6. Check the execution of the SQL statements.
  7. Handle any SQL error codes.