ABAP Select Statement using Space instead of Null or Initial
This ABAP tutorial helps programmers to run SELECT statement over database tables where a field value is NULL or equal to SPACE in SAP. On SAP database tables, empty field values are not stored as NULL values. Instead they are stored as SPACE in SAP table fields. In this tutorial, ABAP developers will see how to query SAP tables using SPACE instead of NULL on empty table fields.
Here are two ABAP sample codes where develop query T001 Company Codes SAP table where ADRNR Address field is NULL or in a more correct saying where address field is SPACE.
The first sample code has a WHERE clause on "adrnr" field for value NE "Not Equal" to "SPACE"
Of course, you can use the EQ "Equal" to "SPACE" as well as in the second sample query.
What is worth to note here is: we do not use INITIAL as the criteria in WHERE clause.
Below ABAP Select statement is different than the above one.
In this sample ABAP code, lt_table internal table is declared dynamically as an inline declaration.
Please note that we define the target table using "@DATA(...)"
This is a new syntax structure introduced with 7.40
In this case instead of SPACE ve use @SPACE for NULL from other database platforms or empty field value.
Note that while selecting data from SAP tables, we do not apply INITIAL as filter value in SELECT statement WHERE clause.
INITIAL value can be used while working with internal ABAP tables.
If ABAP programmer use following ABAP SELECT statement:
Following error will prevent a successful activation of the ABAP program:
'NULL' was expected here.
Let's modify the SELECT command as like in below code. Unfortunately "IS NULL" criteria will fail to return any data although we have empty values in the target SAP table.