SAP ABAP SQL NULL VALUES



Get Example source ABAP code based on a different SAP table
  



AB_SQL - Null Values
A null value is a special value returned by a database in order to indicate an undefined value or result. Null values do not correspond to any content of data objects in ABAP. Especially, a null value is not the same as a type-dependent initial value.
In AB-SQL , null values can be handled using one of the following:
The condition IS NULL
The special expression sql_null
A null indicator
The function coalesce
The parameter on_null in date/time conversion functions
AB-SQL statements for write access generally do not create null values, except when processing views that do not cover all columns of a database table.
As values of database fields, null values might occur in the following situations:
Depending on the database system, empty strings can also be represented by null values.
Null values can be produced in DDIC database tables if new columns are appended to filled tables.
In read accesses with the AB-SQL statement SELECT, null values can be produced by
aggregate functions,
outer joins,
SQL expressions,
when CDS views containing such constructs are accessed.
When they are passed 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 handled as such. A null indicator of a structured target area of a query can show which columns of the result set contain null values and which do not.



Latest notes:

When subqueries are inserted using INSERT or MODIFY, 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.
It is, by principle, not possible to insert null values in key fields of DDIC database tables. If an attempt is made, this raises an exception on the database.
In the ABAP Dictionary, a flag for initial values can be set when inserting new columns in existing DDIC database tables to preserve the type-dependent initial value instead of the null value.
NON_V5_HINTS
In Native SQL and AMDP, null values passed to ABAP objects are also transformed to their type-dependent initial values.
ABAP_HINT_END

ABAP_EXAMPLE_VX5
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 ELSE branch.
ABEXA 01199
ABAP_EXAMPLE_END