ABAP SQL - Null Values
SQL, null values can be handled using the condition
IS NULL, a
null indicator, and the function
Write ABAP SQL statements generally do not create null values, except when editing
views that do not cover all columns of a database column.
In reads using the ABAP SQL statement
SELECT, null values can be produced by
aggregate functions, in outer
SQL expressions, and when
CDS views containing appropriate constructs are accessed. When transferred to data objects, they are transformed to type-dependent
initial values. However,
in the additions
GROUP BY and
ORDER BY, in
table buffering, and when using internal tables as
data sources, null values are treated as such. A
null indicator of a structured target area of a query can show which columns of the results set contain null values and which do not.
7.31 | 7.40 | 7.54
- When subqueries are inserted
MODIFY, any null values are also transformed to type-dependent initial values or raise an exception after an attempt to set a key field to the null value.
- In Native SQL and AMDP, null values passed to ABAP objects are also transformed to their type-dependent initial values.
- It is, by principle, not possible to insert null values in key fields of database tables. If attempted, this raises an exception on the database.
- In ABAP Dictionary, a flag for initial values can be set when inserting new columns in existing database tables to preserve the type-dependent initial value instead of the null value.
In the following example, the condition
IS NULL is true because the
CASE expression on the left side does not find a true
WHEN condition and does not have an
DELETE FROM demo_expressions. INSERT demo_expressions FROM @( VALUE #( id = 'X' ) ). SELECT SINGLE '_' AS id FROM demo_expressions WHERE CASE WHEN id = 'Y' THEN 'Z' END IS NULL INTO @DATA(wa).