this select command meaning?

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

digitalife
Posts: 137
Joined: Wed Nov 06, 2002 3:50 am
Location: China

Post by digitalife » Wed Dec 04, 2002 2:07 am

i test in my system,sap/r3 4.5B,

the SELECT SINGLE * FROM has the same speed as SELECT * FROM UP TO 1 ROWS.
this is my test program:

Code: Select all

TABLES:MSEG.

SELECT SINGLE * FROM MSEG WHERE MATNR = '1MM00'.
    IF SY-SUBRC EQ 0.
       WRITE:/ MSEG-MATNR.
    ENDIF.

Code: Select all

TABLES:MSEG.

SELECT  * FROM MSEG UPTO 1 ROWS WHERE MATNR = '1MM00'.
    IF SY-SUBRC EQ 0.
       WRITE:/ MSEG-MATNR.
    ENDIF.
ENDSELECT.
anyway,someone name guest Frank say:

this is some explain in help i founded,i think you are wrong.

SY-SUBRC = 8: Only with SELECT SINGLE FOR UPDATE: Not all
primary key fields in der WHERE condition were
specified. No line was read.
I Like SAP

Wolfgang G Propfe
Posts: 469
Joined: Sun Oct 20, 2002 5:57 pm
Location: Houston, TX, USA
Contact:

Post by Wolfgang G Propfe » Wed Dec 04, 2002 11:15 am

Dear digitalife:
The issue is not so much the run-time, which is probably about the same. The issue is that you should have a full key for a SELECT SINGLE, because you expect a single record (or none). In your case, there could be more than one record. Using the UP TO syntax, you avoid warnings in the extended syntax check, and it becomes obvious, that you just want any hit and don't expect exactly one. It is easier to maintain later on.

But the experts don't always agree. I know, that m@t (BTW, where is he?) thinks the SINGLE is fine. It is more a matter of style and maintainability.

Regards,
Wolfgang

digitalife
Posts: 137
Joined: Wed Nov 06, 2002 3:50 am
Location: China

Post by digitalife » Wed Dec 04, 2002 8:04 pm

All of your point i agree. :D
I Like SAP

Bill
Posts: 12
Joined: Fri Oct 25, 2002 2:14 am
Location: China

Post by Bill » Sat Dec 07, 2002 8:45 am

I would like to share my idea.

Basically, Select single * & Select * up to 1 rows will return 1 result if there is any. They are almost the same in functionality.

Before 4.6, when you use select single *, u must specify all the key fields in where clause, otherwise u will get a warning message. Even it works, it still makes you look not professional.

On the contrary, when using Select * up to 1 rows, u don't have to explicitly specify all the key fields...

Guest

Post by Guest » Mon Dec 09, 2002 4:36 am

Take a look at SE30, Tips and Tricks, Select single Vs Select-Endselect.

i.e.

* If you are interested in exactly one row of a database table or view
* use the Select Single statement instead of a Select-Endselect-loop
* Select Single requires one communication with the database system,
* whereas Select-Endselect needs two.

There is probably about 5-10% time-saving by using Select Single. Personally I use Select Single if the full key is being used, and Select-Endselect Up to 1 Rows if the full key cannot be specified. Both will return 1 row of data, but following the above makes it instantly clear whether or not more than 1 row was potentially available.

Post Reply