ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Inserting a null capable field from DB2 into and RPG Data structure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inserting a null capable field from DB2 into and RPG Data structure

    I have a table that has a field that wants to be converted to allow null values.

    I also have an existing program that performs a 'Select *' from the table into a data structure defined using ExtName(). The null capable field, is not referenced anywhere in the program, it is only ever being inserted into this data structure.

    I am wondering what steps, if any, will I need to perform in order to ensure that this program will not break when a null value is inserted into this field.

  • #2
    You define an (Indicator) Array with INT(5) Elements, one Element for each column in your file.
    In your FETCH Statement you specify the Indicator Array immediately after the Data Structure name only separated by a blank (NOT a comma!)

    Exec SQL Fetch Next from YourCursor into :YourDS YourIndArray;

    Since you are not accessing this field in your program, you do not need anything else.
    If you'd access the NULL capable field, you need to check the Indicator for the field. If the Indicator Element is -1 than a NULL value is returned, if the Indicator Element is *Zero a value is returned.

    ... BTW it is never a good idea to use SELECT * FROM ... it is much better to only the fields/columns you really need.
    Not only because you'd not change anything, but also because SQL works differently than RPG and can return exactly what you need, i.e. less traffic between the database and the program ... faster!

    Birgitta

    Comment

    Working...
    X