Skip to Content

Finding out the value of a field of internal table incase it can contain blank or null

Hi Experts,

I am having a table in DDIC with columns containing blank and null values both. Using SAP Logon we cannot differentiate between both of them. So I write a following prorgam where I am able to get entries if i am using null in where condition(Please refer to the program) and otherwise 0 entries( in case of blank).

I am trying to check the value of the field which contains null by using "IS NOT INTIAL". But it never enters the if block, it means test2 is not null.

So I am having following questions :

1.) When we transfer data from SAP database in an internal table, what happens to the null values(which were present in sap database). Does internal table fields also contains null values or they gets intialized.

2.) I am using "IS NOT INTIAL" to check if a field is having null value. Is there any other way also to check the same?

In UI it is shown as:

Table : ZTEST_NEERAJ

|ID |NAME |AGE|TEST|TEST2 |

| 1 |NEERAJ|45 | 0 | |

| 2 | |45 | 0 | |

In Actual it is as below:

Table : ZTEST_NEERAJ

|ID |NAME |AGE|TEST|TEST2 |

| 1 |NEERAJ|45 | 0 | NULL |

| 2 | |45 | 0 | NULL |

FUNCTION ZSQL_QUERY2.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" EXPORTING
*" REFERENCE(DBCNT) TYPE SY-DBCNT
*"----------------------------------------------------------------------


DATA : TABLE1 LIKE TABLE OF ZTEST_NEERAJ INITIAL SIZE 10 WITH HEADER LINE.

Select * from ZTEST_NEERAJ INTO TABLE TABLE1 where test2 IS NULL.

DBCNT = SY-DBCNT.

READ TABLE TABLE1 INDEX 1.

DATA: X TYPE I VALUE 0.
IF TABLE1-test2 IS NOT INITIAL.
X = 1.
ENDIF.

ENDFUNCTION.

Thanks,

Partish

Add a comment
10|10000 characters needed characters exceeded

  • The simple/stupid solution could be to have another boolean field with VALUE_NULL

  • Hi Sandra Rossi,

    Thanks for the enlightening comment.

    Yes, it is of char type.

    I understand that we should not allow to contain both null and blank but we are already having pre existing data and we are performing Extraction and Loading of data. While performing ETL we have to bring data in a internal table.

    Can you please also help me with any reference which states that "ABAP converts null into blanks".

    Thanks,

    Partish

  • (below, I assume that your column has the type character, so I use the term BLANK, I might have used the term INITIAL to be type-agnostic)

    Because ABAP convert the NULL value into BLANK, you should NOT allow your table column to contain both NULL and BLANK.

    Moreover ABAP can only write BLANK values, so choose only BLANK.

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Oct 30, 2019 at 01:13 PM

    If the value is NULL, maybe you can use instead a value which is not likely to happen, and you use the COALESCE function:

    Select coalesce( test2, '!%µ£$;,:' ) AS test2
      from ZTEST_NEERAJ
      INTO TABLE @TABLE1.
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.