WHERE clause subfield support

When you use the IMS JDBC drivers to pass SQL statements, you can use the WHERE clause to list subfields of any field, as long as the field itself is searchable and is fully defined by the subfields.

For example, a DBD-defined field is named ADDRESS and is 30 bytes long. In a COBOL copybook, this field is split into the subfields CITY, STATE, and ZIPCODE, as illustrated by the following code.

01 ADDRESS
   02 CITY PIC X(10)
   02 STATE PIC X(10)
   03 ZIP PIC X(10)

Without subfield support, the ADDRESS value in the WHERE clause would have to be padded manually and entered as follows:

WHERE ADDRESS = 'san jose  ca        95141     '

With subfield support, you can enter the WHERE clause as follows:

WHERE CITY = 'san jose' 
   AND STATE = 'ca'
   AND ZIPCODE = '95141'

The IMS JDBC drivers convert the individual subfields and bundle them into the ADDRESS field before sending the SQL query to IMS.

The following rules and restrictions apply to WHERE clause subfield support:

  • Parameter markers are supported for subfields. For example, for a prepared statement, the following WHERE clause entry is valid:

    WHERE CITY = ? AND STATE = ? AND ZIPCODE = ?
  • The only relational operator supported for subfields is = (equals operator).

  • The only Boolean operator is AND for connecting subfields. The following WHERE clause entry is valid because the subfields are connected using only AND operators:

    WHERE HOSPCODE=? OR CITY = ? AND STATE = ? AND ZIPCODE = ?
  • All the subfields for a particular searchable field must be specified in the WHERE clause. You cannot omit any subfields of a field. For example, the following WHERE clause entry is invalid because the STATE subfield was not provided:

    WHERE CITY = ? AND ZIPCODE = ?
  • When specifying the subfields in a WHERE clause, all the subfields for a searchable field must be listed adjacent to each other. For example, the following WHERE clause entry is invalid because the listing of the subfields is not contiguous:

    WHERE CITY = ? AND STATE = ? OR HOSPCODE=? AND ZIPCODE = ?
  • You can enter subfields for multiple searchable fields in the WHERE clause. For example, if the PATNAME field was broken into LASTNAME and FIRSTNAME subfields, you can specify the subfields for ADDRESS and PATNAME as follows:

    WHERE CITY = ? AND STATE = ? AND ZIPCODE = ?
       OR LASTNAME = ? AND FIRSTNAME = ?
  • When specifying the subfields in a WHERE clause across multiple tables, all the subfields for the searchable fields in each table must be listed together, before listing the subfields for the next table. For example, if the ADDRESS field was in the HOSPITAL table and the PATNAME field was in the PATIENT table, the following WHERE clause entry is invalid because not all the ADDRESS subfields have been listed for HOSPITAL:

    WHERE HOSPITAL.CITY = ? AND HOSPITAL.ZIPCODE = ?
       AND PATIENT.LASTNAME = ? AND PATIENT.FIRSTNAME = ?