2

I have a rpg program that contains a routine that updates a db2 table.

I have declared a local var in the program

myvar

If <condition>
    %nullind(myvar) = *on

it complains that the field is not capable of null.

I use this variable in an SQL update statement

 UPDATE TABLE
 SET X=:myvar

how can I set X to null?

Arcadian
  • 4,312
  • 12
  • 64
  • 107
  • 3
    Does the table allow NULLs? Have you told the [RPGLE program](http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/c0925083577.htm) to [allow NULLs](http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/c0925083225.htm#HDRHALWNUL)? – Benny Hill Jun 26 '13 at 18:54

1 Answers1

7

Internally defined fields are not null capable but you can use an externally described data structure to import the table definitions and enable nulls for database fields.

H ALWNULL(*USRCTL)

D TABLE         E DS                  EXTNAME(TABLE) QUALIFIED

 /FREE
    if <condition>;
        %nullind(table.x) = *on;
    endif;

    exec sql update table
        set x = :table.x
        where <condition>;
 /END-FREE
James Allman
  • 40,573
  • 11
  • 57
  • 70