What is COBOL host variable equivalent for various DB2 data types?

DB2DatabaseBig Data Analytics

Problem: How will the COBOL-DB2 program behave when there is a mismatch between the host variable and number of columns in the SELECT statement?

Solution

In case there is a mismatch in the number of columns and number of host variables, the query will fail. For example, if we have used the below query in a COBOL-DB2 program which processes the ORDERS DB2 table.

Example

EXEC SQL
   SELECT ORDER_ID,
      ORDER_AMOUNT,
      ORDER_DATE,
      ORDER_STATUS
   INTO :WS-ORDER-ID,
      :WS-ORDER-AMOUNT,
      :WS-ORDER-DATE,
   FROM ORDERS WHERE ORDER_DATE = ‘2020-09-15’
END-EXEC

There is a mismatch in the number of columns and host variables. There are a total 4 columns used in the SELECT statement and for them only 3 host variables are used. In this case the query will fail and there are two ways in which we can detect this condition.

  • The SQLWARN3 field of SQLCA will get the value as ‘W’ in case there is a mismatch.
  • In some installations the SQLCODE field for SQLCA gets the error code as -804 when there is a mismatch.

We can use IF condition to check the value in SQLWARN3 or SQLCODE and direct the program processing accordingly.

Following is an example.

Example

IF SQLWARN3 = ‘W’
   PERFORM X00-ABEND-SECTION
ELSE
   PERFORM A100-SELECT-RESULT
END-IF
raja
Published on 01-Dec-2020 05:06:39
Advertisements