Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

NULL vs INITIAL

Former Member
0 Likes
1,965

Hi all.

Here is my performance dilemma.

Is there any difference between these two lines of code?

SELECT * FROM /abc/def INTO TABLE lt_abc WHERE my_var IS NOT NULL.

or

SELECT * FROM /abc/def INTO TABLE lt_abc WHERE my_var NE ''.

I get a performance error if NULL is used. Would second line be a good alternative?

Thank you.

1 ACCEPTED SOLUTION
Read only

ferry_lianto
Active Contributor
0 Likes
1,125

Hi,

Second select statement is better.

Regards,

Ferry Lianto

4 REPLIES 4
Read only

ferry_lianto
Active Contributor
0 Likes
1,126

Hi,

Second select statement is better.

Regards,

Ferry Lianto

Read only

0 Likes
1,125

Hi Ferry,

Is that the same though?

Thanks.

Read only

Former Member
0 Likes
1,125

From the help:


Variant 7 
f IS [NOT] NULL 

Effect 
The condition is true if the contents of table field f 
(does not) contain(s) the NULL value. 

Example 
Example to select all customers for whom no telephone 
number is specified: 

DATA WA_SCUSTOM TYPE SCUSTOM. 

SELECT * FROM SCUSTOM INTO WA_SCUSTOM WHERE TELEPHONE IS NULL. 
ENDSELECT. 

Note 
Performance: 

The SAP buffer does not support this variant. Therefore, 
every SELECT command on a buffered table or a view with 
fields from buffered table that contains ... WHERE f IS 
[NOT] NULL behaves as though the FROM clause contained 
the BYPASSING BUFFER addition. 

Rob

Message was edited by:

Rob Burbank

Read only

Clemenss
Active Contributor
0 Likes
1,125

Hi,

usually there are no NULL values stored for any field in any table.

NULL values for a field means that physically nothing is stored. This only happend when a new table field is appended for an existing database table. If not explicitly defined as 'INITIAL' the database appends this field and the no value for any record is stored - this is NULL.

For NE '' you can say NE SPACE.

If you have to care for possible NULL values it must be WHERE my_var NE SPACE and WHERE my_var IS NOT NULL.

The bad thing about NULL values is that you can not distinguish them from INITIAL values because the NULL value is converted to initial.

Try once SELECT COUNT( * ) FROM /abc/def where my_var IS NULL.

If any records are found, then you have to care about NULL values. Probably you won't.

Regards,

Clemens