Skip to Content
1

Where condition alternative for is not initial

Jan 05, 2017 at 04:12 PM

2.5k

avatar image
Former Member

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. 
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
Fabian Lupa Jan 06, 2017 at 03:02 PM
2

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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

How about this?

CONSTANTS: lcv_dummy_logsys TYPE t000-logsys VALUE IS INITIAL.
2

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!

1
Horst Keller
Jan 05, 2017 at 09:45 PM
6

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

... WHERE field <> @( VALUE #( ) )
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks. Sadly i'm not on 7.4 i don't have the Value Operator. So i can't test it.

0

It works from 7.50 on, when host expressions were introduced

SELECT *
 FROM scarr
 WHERE carrid <> @( VALUE #( ) )
 INTO TABLE @DATA(result).
1
Horst Keller
Jan 17 at 08:48 AM
4

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

I just documented it.

Thanks for asking for it!

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Great news! Thank you! :-)

0
Matthew Billingham
Jan 10, 2017 at 10:08 AM
3

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.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Like Raghu i find myself writing IS INITIAL in Open SQL, until the Sytax-Check reminds me that i can't.

So i sometimes ask myself why is IS INITIAL not offered with Open SQL.

0

So i sometimes ask myself why is IS INITIAL not offered with Open SQL.

Cause nobody asked us before ...

Thanks to this thread here, the Open SQL team is considering it now, really ...

5

We didn't know who to ask!

3
Horst Keller
Jan 05, 2017 at 06:50 PM
1

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

That would be nice... I catch myself often writing IS INITIAL in my select statements!

1

You can use host expressions with VALUE #( ) as shown above from 7.50 on.

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

4