‎2009 Jan 28 4:25 PM
hi
is there a way to use select single * without using into?
i just want to check the sy-subrc of the selection
thanks
Thread moved to Performance Tuning Forum
Edited by: Vijay Babu Dudla on Jan 28, 2009 11:02 PM
‎2009 Jan 28 4:26 PM
‎2009 Jan 28 4:26 PM
‎2009 Jan 28 4:27 PM
Hello,
No you have to use INTO with SELECT SINGLE.
i just want to check the sy-subrc of the selection
You should use SELECT COUNT * for this purpose.
BR,
Suhas
PS: Eric shall i say duplicate post for this or the Mods will understand from the timings
Edited by: Suhas Saha on Jan 28, 2009 9:57 PM
‎2009 Jan 28 4:30 PM
Yes, there is a way. Declare corresponding structure with tables. It will implicitly place an entry in that work area.
TABLES: tab_name.
SELECT SINGLE * FROM tab_name WHERE ....
Marcin
‎2009 Jan 28 4:31 PM
Since COUNT is an aggregate, it will likely have poorer performance. I think SELECT SINGLE ... INTO...is the best way.
Rob
‎2009 Jan 28 4:33 PM
Hello Rob,
Point taken, but you cannot use SELECT SINGLE w/o INTO.
Suhas
‎2009 Jan 28 4:39 PM
What's so bad about INTO?
Reminds me of the question "How can I sort a table without using SORT?"...
Thomas
‎2009 Jan 28 4:42 PM
>
> Hello Rob,
>
> Point taken, but you cannot use SELECT SINGLE w/o INTO.
>
> Suhas
Yeah - I know it's not what the OP wanted. But it's the standard way to do it. Without any reason not to do it this way, that's what I would do.
Rob
‎2009 Jan 28 4:44 PM
>
> Since COUNT is an aggregate, it will likely have poorer performance. I think SELECT SINGLE ... INTO...is the best way.
>
> Rob
I did a fast test on table BKPF (SE38 => Performance ...):
SELECT SINGLE * is clearly slower, than SELECT COUNT( * )
SELECT SINGLE <specific_field> takes more or less the same time, than SELECT COUNT( * )
(this is a development system, number of entries in BKPF: about 120K)
‎2009 Jan 28 4:50 PM
>
> I did a fast test on table BKPF (SE38 => Performance ...):
> SELECT SINGLE * is clearly slower, than SELECT COUNT( * )
> SELECT SINGLE <specific_field> takes more or less the same time, than SELECT COUNT( * )
>
> (this is a development system, number of entries in BKPF: about 120K)
Did you do each more than once and take the lowest?
Rob
‎2009 Jan 28 4:51 PM
I was pressing the 'Measure time' button more than ten times (in both cases).
‎2009 Jan 28 4:54 PM
Well, it doesn't seem right. I'll try to look into it.
Rob
‎2009 Jan 28 4:59 PM
Hello Eric,
Keeping my fingers crossed !!! Share your findings with us Rob !!!
Suhas
‎2009 Jan 28 8:16 PM
OK - not the results I expected. I ran this:
REPORT ztest LINE-SIZE 80 MESSAGE-ID 00.
TABLES: ekko.
PARAMETERS p_ebeln LIKE ekko-ebeln OBLIGATORY MEMORY ID bes.
DATA: start TYPE i,
end TYPE i,
dif TYPE i,
count TYPE i.
SELECT COUNT( * ) FROM ekko
INTO count
WHERE ebeln = p_ebeln.
DO 5 TIMES.
GET RUN TIME FIELD start.
SELECT COUNT( * ) FROM ekko
INTO count
WHERE ebeln = p_ebeln.
GET RUN TIME FIELD end.
dif = end - start.
WRITE: /001 'Time for SELECT COUNT( * )', ':', dif, 'microseconds'.
ENDDO.
SELECT SINGLE ebeln FROM ekko
INTO ekko-ebeln
WHERE ebeln = p_ebeln.
DO 5 TIMES.
GET RUN TIME FIELD start.
SELECT SINGLE ebeln FROM ekko
INTO ekko-ebeln
WHERE ebeln = p_ebeln.
GET RUN TIME FIELD end.
dif = end - start.
WRITE: /001 'Time for SELECT SINGLE * ', ':', dif, 'microseconds'.
ENDDO.and got pretty much the same results as Eric. I also did an explain from ST05 and they were almost identical.
Mea culpa.
I ran this in a DB2 ECC6 environment. I'd be interested to learn of results from other releases (particulary older ones).
Rob
Edited by: Vijay Babu Dudla on Jan 28, 2009 11:01 PM
‎2009 Jan 29 8:31 AM
>
> I ran this in a DB2 ECC6 environment. I'd be interested to learn of results from other releases (particulary older ones).
No difference on ECC6 with Oracle 10. Sorry, can't help with older releases.
Thomas
‎2009 Jan 28 4:40 PM
Hi,
The only option to use without INTO statement.
Tables: VBAK.
SELECT SINGLE * FROM VBAK WHERE <CONDT>.
IF SY-SUBRC EQ 0.
ENDIF.
‎2009 Jan 28 4:42 PM
Still doing an INTO internally, you just don't see it...that's why TABLES is obsolete.
Thomas
‎2009 Jan 28 4:42 PM
Yes you can, like this
TABLES: VBAK.
SELECT SINGLE * FROM VBAK WHERE VBELN = '00000100'.
Note that I have used TABLES statement, which automatically creates a work area under the dictionary table name, so VBAK itself will stand for the table as well as work area. So no separate work area is required for INTO.
‎2009 Jan 28 4:43 PM
Yes you can, like this
TABLES: VBAK.
SELECT SINGLE * FROM VBAK WHERE VBELN = '00000100'.
Note that I have used TABLES statement, which automatically creates a work area under the dictionary table name, so VBAK itself will stand for the table as well as work area. So no separate work area is required for INTO.
‎2009 Jan 29 7:54 AM
@Rob,
what you expect is not completely wrong, there are recommendation out, which say, that count(*) will
first build up the aggregate over all entries. But in newer systems this is definitely not true. I can not say whether all systems behave that way, that they don't check all records.
The actual recommendations are however still different:
+ either
SELECT COUNT(*)
INTO numb
FROM db
UP TO 1 ROWS
WHERE ...
or if it is a fully specified key, i.e. a SELECT wqith primary key
SELECT SINGLE key1
INTO ls_db_tab
FROM db_tab
WHERE key1 = ... key2 = ...
The INTO is required in newer systems.
Siegfried