While designing new table, we often enable the initial value check to set the initial value for the field based on the datatype.

test.JPG

A field can also be created in the database as NOT NULL if the initial flag is not set in the ABAP Dictionary.

To see  the default value of each field check

Utilities -> Database object -> Display in the maintenance screen of the corresponding table.

test.JPG

But in select query there are some impact

NULL means that physically nothing is stored in the database. If a database field is defined as CHAR with, say, 80 characters, the NULL value will not waste that space.

When NULL values are transfered from the database, they are converted to the ABAP initial value. But if existing database tables are extended appending new field(s), those fields get stored as NULL values for the existing database records. A WHERE <field> = SPACE will not retrieve the recors with NULL values for the field.

If such a null field is used in WHERE clause, no problem if specifying any values except initial.
If selection of records with initial fields is required  and  you do not know if NULL values exist, select

WHERE ( <field> = space or <field> is NULL ).

So we have to check this aspect of table while doing programming.

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. Volker Wegert

    There is another, probably more severe consequence of setting this field: If you add a field to an existing table that has this flag set, you will force the database not only to ALTER the table, but also to UPDATE every row. This happens e. g. when importing the transport request into the target system. If the table is sufficiently large and used by many users throughout the entire system, this can lead to a rather large and unexpected outage…

    (0) 
  2. Suhas Saha

    Hello,

    Thanks for discussing this topic in detail; a very basic one but not many people (includes me as well) pay too much attention to it 😏

    BR,

    Suhas

    PS – I was surprised to see the F1 help give a detailed explanation. Generally don’t expect SAP documentation to be so detailed πŸ˜›

    (0) 
  3. Athreya Hegde

    There is an option to convert all the null values to their respective initial values in transaction SE14. The ‘Force Conversion’ option available in Menu option ‘Extras’ will adjust the table replacing NULL will the initial values. Just thought of sharing it here πŸ™‚

    Regards,

    ~Athreya

    (0) 
  4. Harish R

    Thank you for this!

    A few days back I had to query a table on a field which was not having any value. I tried WHERE <field> IS NOT NULL and WHERE <field> is INITIAL. Both did not work. I changed it to WHERE <field> is SPACE and the required row was fetched. I did not understand why back then. But now I do. Thank you again.

    I have a corollary question for this. If the NOT_NULL is set for the field then will SPACE be filled for the column? Does this mean some space wastage for each row/field where a SPACE is simply filled? Or does ABAP handle this intelligently?

    (0) 

Leave a Reply