Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

on select statement

Former Member
0 Likes
531

diff between select upto 1 rows and select single * ?

4 REPLIES 4
Read only

dani_mn
Active Contributor
0 Likes
506

HI,

check this thread for your answer.

Regards,

HRA

Read only

aris_hidalgo
Contributor
0 Likes
506

select single as the name implies gets a single record based on some condition while select up to 1 rows is the same except that for example, you can get the latest value by adding the statement ORDER BY in you select statement. Here is an example:

***SELECT SINGLE

SELECT single bukrs anln1 gjahr

afabe knafa kansw

answl kaafa nafal

aafav aafag nafap

aafap nafav nafag

FROM anlc INTO (it_anlc-bukrs, it_anlc-anln1, it_anlc-gjahr,

it_anlc-afabe, it_anlc-knafa, it_anlc-kansw,

it_anlc-answl, it_anlc-kaafa, it_anlc-nafal,

it_anlc-aafav, it_anlc-aafag, it_anlc-nafap,

it_anlc-aafap, it_anlc-nafav, it_anlc-nafag)

WHERE anln1 EQ it_anla-anln1

AND anln2 EQ it_anla-anln2

AND bukrs IN r_iwerk

AND afabe EQ '01'.

***SELECT UP TO 1 ROWS

SELECT bukrs anln1 gjahr

afabe knafa kansw

answl kaafa nafal

aafav aafag nafap

aafap nafav nafag

FROM anlc UP TO 1 ROWS

INTO (it_anlc-bukrs, it_anlc-anln1, it_anlc-gjahr,

it_anlc-afabe, it_anlc-knafa, it_anlc-kansw,

it_anlc-answl, it_anlc-kaafa, it_anlc-nafal,

it_anlc-aafav, it_anlc-aafag, it_anlc-nafap,

it_anlc-aafap, it_anlc-nafav, it_anlc-nafag)

WHERE anln1 EQ it_anla-anln1

AND anln2 EQ it_anla-anln2

AND bukrs IN r_iwerk

AND afabe EQ '01'

ORDER BY gjahr DESCENDING.

ENDSELECT.

In the example, select single will get the record that matches your condition unlike in select up to 1 rows it will get the latest record since I am ordering it by GJAHR(Fiscal year) in descending order.

Hope this helps...

P.S. Please award points for useful answers.

Read only

Former Member
0 Likes
506

Select Single -> You need to specify all the key fields

Select upto 1 rows - > Keys fields are not required.

Select Single is not a loop.

Select Upto 1 rows is a Loop. So you have to specify SELECT & ENDSELECT.

Cheers

VJ

Read only

abdul_hakim
Active Contributor
0 Likes
506

have a look at the below link..

https://www.sdn.sap.com/irj/sdn/developerareas/abap?rid=/library/uuid/840ad679-0601-0010-cd8e-9989fd...

Cheers,

Abdul Hakim

Mark all useful answers...