DB2 SQL query in COBOL program - Bind Warning

When we write embedded SQL in COBOL-DB2 application program , we know that

  • It should be always within EXEC SQL END-EXEC.
  • If we are doing a SELECT or using a Predicate with specific value passed in variable for comparison, that variable should always be preceded by :

All the variables preceded by : called as Host Variable.

Ex :




Here :WS-DATE ,DAY OF TABLE_A are host variable , declared somewhere in working storage section with appropriate definition.

What would be the consequence if somehow we miss this variable to precede with :(Say TABLE_A.DAY was not preceded by : in above query)

Will we able to compile the program ?? Bind it ?? What error will we get , if query is getting executed.

First of all, yes program can be compiled, and bind will be successful. But there will be a warning message in your Bind step with SQLCODE 203 and SQLSTATE 01552.

So lesson learnt is if your bind is successful not necessary mean that all is well, carefully look at if there is any warning provided by DB2 precompiler.If you miss it , you will be in for surprise Production/Test failure. Just here in this case if you just go ahead and move the code with Bind warning and when program runs and try to execute this query it will fail with SQLCODE -206


No comments:

Post a Comment