Abend
Abend
Abend
How to Handle the DB2 sql Code -305 �in cobol-DB2 Application Program
?
In DB2, the columns defined as�NULL�needs to be handled carefully else it will throw
null exception error, in order to over come this error�data type can be handled by
using�null indicator.
NULL is stored using a special one-byte null indicator that is “attached” to every
nullable column.
If the column is set to NULL, then the indicator field is used to record this.
Using NULL will never save space in a DB2 database design – in fact, it will always
add an extra byte for every column that can be NULL. The byte is used whether or
not the column is actually set to NULL. The indicator variable is transparent to an
end user
SN CHAR (10)
Note :: Unless you specify NOT NULL, the default is to allow for�NULL
In above table SN and SNAME columns holds null values by default, in order to handle
these null variables we need to have NULL-INDICATORS declares in the Program
as�S9(4) comp�variable (A indicator variable is shared by both the database
manager and the host application. Therefore, this variable must be declared in the
application as a host variable, which corresponds to the SQL data type SMALLINT)
Let us declare the Null indicators for above two variables in application program as
2)�A table column is defined as NULL, The host variable has a not null value and the
Null indicator is not set in the host program, so the null indicator is defaulted to a
negative value.
Resoulution :This should be resolved by using a null indicator in the host program
and moving the relevant value to the null indicator. Here inorder to move null value into
respective column nove -1 to null indicator.
Eg :
MOVE -1 to SNAME-INDNULL
EXEC SQL INSERT INTO SAMP_TAB
(SN,SNAME,STATUS,CITY) VALUE
(:SN,:SNAME:SNAME-INDNULL,:STATUS,:CITY)
END-EXEC
Eg :
INTO :SNAME:SNAME-INDNULL
FROM SAMP_TAB
WHERE SN =�:SN-IN
END-EXEC
Else
End-If
Unless you specify NOT NULL, the default is to allow for NULLs
It’s easy for us to get lazy and allow columns to contain NULLs when it would be
better to specify NOT NULL
Remember to allow for NULLs creating UNKNOWN logical values. Always test your
code with NULLs in all possible places.
The NULL is a global creature, not belonging to any particular data type, but able to
replace any of their values.
A NULL isn’t a zero, it isn’t a blank string, it isn’t a string of length zero.
The basic rule for math with NULLs is that they propagate. An arithmetic operation
with a NULL will return a NULL. If you have a NULL in an expression, the result will
be NULL.
If you concatenate a zero length string to another string, that string stays the same. If
you concatenate a NULL string to a string, the string becomes a NULL.
Sometimes negating the wording of the problem helps. Instead of saying “Give me
the cars that met all the test criteria,” say “Don’t give me any car that failed one of
the test criteria.” It is often easier to find what you do not want than what you do
want. This is very true when you use the NOT EXISTS, but beware of NULLs and
empty tables when you try this.
You can’t completely avoid NULLs in SQL. However, it is a good idea to try as hard
as you can to avoid them whenever possible.
Make yourself think about whether you really need NULLs to exist in a column
before you omit the NOT NULL clause on the column definition.
———————————————————————————————–
If you get -305 sqlcode which means you got null values into the host variables.
Solution –
Use NULL INDICATOR VARIABLES to stop getting -305.
Example
———–
,: FIRST-NAME :WS-FIRST-NAME-NULL-IND
,: INIT-NAME :WS-MID-NAME-NULL-IND
IF WS-FIRST-NAME-NULL-IND >= 0
… Means Field populated with proper value
ELSE
… Means Field populated with null value
END-IF