SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

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.

DATA lt_table TYPE TABLE OF T001.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_table
FROM t001
WHERE adrnr NE space.
* is same with
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_table
FROM t001
WHERE adrnr <> ''. " you can also use: "adrnr = ''"
Code

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.

SELECT * INTO TABLE @DATA(lt_table)
FROM t001
WHERE adrnr EQ @space.
Code

ABAP Select using SPACE instead of Null or Initial

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:

DATA lt_table TYPE TABLE OF T001.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_table
FROM t001
WHERE adrnr IS INITIAL.
Code

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.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_table
FROM t001
WHERE adrnr IS NULL. " fails to return data
Code


SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.