How to store a NULL value in a particular column of a DB2 table using COBOL-DB2 program?

DB2DatabaseBig Data Analytics

We will make use of NULL indicator in order to store a NULL value in any column of a DB2 table. Firstly, we should move a value -1 in the NULL indicator in our COBOL-DB2 program. After that we execute UPDATE or INSERT query to store the NULL value.

For example, if we have to update a NULL value in the ORDER_DESCRIPTION column of the ORDER table where ORDER_ID is 3345612.

A020-UPDATE-ORDERS.
   MOVE -1 TO ORDER-DESCRIPTION-N
   MOVE SPACES TO ORDER-DESCRIPTION-DATA
   EXEC SQL
      UPDATE ORDERS
         SET ORDER_DESCRIPTION =
            :ORDER-DESCRIPTION-DATA
   :ORDER-DESCRIPTION-N
   WHERE ORDER_ID = ‘3345612’
END-SQL.

ORDER-DESCRIPTION-N is the NULL indicator here. The important point to note here is that the second line in the paragraph i.e the line highlighted with orange is optional. Once we have moved -1 in the null indicator then no matter what value we give in the data field, only NULL value will be stored in DB2 table.

raja
Published on 14-Sep-2020 18:30:31
Advertisements