Skip to Content
avatar image
Former Member

Where condition alternative for is not initial

Hello

Will Variant 1 work with all data types like Variant 2.
I don't want to use Variant 2 because the performance is important.

But im not sure if Variant 1 works with all data types or only with characters. Because for example Dates are saved with 0000000 and not '' in the Database.

Variant 1

  SELECT * FROM table INTO ls_table WHERE field <> ''.

    DO something.

 ENDSELECT.

Variant 2

 select * from table into ls_table.

    if field is not INITIAL. 

        do something. 

    endif. 

  endselect. 
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Jan 06, 2017 at 03:02 PM

    Horst's solution does work (to my surprise):

    SELECT * FROM t000 WHERE logsys <> @( VALUE #( ) ) INTO TABLE @DATA(gt_out).

    If your release does not support it yet I suppose you can always create a dummy line and use that since all its values are initial.

    DATA: ls_dummy  TYPE t000,
          lt_result TYPE STANDARD TABLE OF t000.
    SELECT * FROM t000 INTO TABLE lt_result WHERE logsys <> ls_dummy-logsys.

    I was looking for constants of initial values for each predefined type so you do not have to declare the dummy variable and make the code more readable but could not find them.

    Add comment
    10|10000 characters needed characters exceeded

    • Sure, I was more looking for something like cl_abap_exceptional_values=>char_initial_value to avoid the helper variable all together. For just comparing one field your approach is the better option though!

  • Jan 05, 2017 at 09:45 PM

    If type inference works (I'm not logged on to the ABAP system), the following might do ...

    ... WHERE field <> @( VALUE #( ) )
    Add comment
    10|10000 characters needed characters exceeded

  • Jan 17 at 08:48 AM

    Yes, we'll offer a real IS INITIAL in Open SQL in an upcoming release.

    I just documented it.

    Thanks for asking for it!

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 10, 2017 at 10:08 AM

    Given that usually you know the type, I've not had a problem. I use WHERE field EQ SPACE or WHERE field NE SPACE in most cases. However, where I've needed to check for initial date, I've declared

    DATA initial_date TYPE d.

    And used initial_date in the where clause. I didn't use a constant, because that requires setting a value.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 05, 2017 at 06:50 PM

    Good question, I'll examine if we have a workaround for ABAP's IS INITIAL in Open SQL ...

    Add comment
    10|10000 characters needed characters exceeded