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

select endselect

Former Member
0 Likes
2,425

hello friends,

for the first time my select statement is asking for end select .

why, and when to keep endselect.

thank you.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,946

You should write...


SELECT FIELD1 FIELD2
INTO TABLE MY_TAB
FROM MARA.

And...never use SELECT-ENDSELECT....In 5 years of ABAP programming I only needed twice....So avoid it anytime you can -;)

Greetings,

Blag.

13 REPLIES 13
Read only

Former Member
0 Likes
1,946

Hey saritha

Select...endselect is like a loop on the database table.

Also if u have specified 'upto n rows' in your select query , it will ask you for an endselect.

can you please copy paste your code here so that we can have a look.

Cheers

shivika

Read only

Former Member
0 Likes
1,946

Hi Saritha,

Give ur select statement. I am definite that you have missed INTO in your select statement.

Thanks

Aneesh.

Read only

Former Member
0 Likes
1,947

You should write...


SELECT FIELD1 FIELD2
INTO TABLE MY_TAB
FROM MARA.

And...never use SELECT-ENDSELECT....In 5 years of ABAP programming I only needed twice....So avoid it anytime you can -;)

Greetings,

Blag.

Read only

Former Member
0 Likes
1,946

do not use select endselect and it will be performance issue.

Simple example

  • <b>Select endselect example.</b>

tables : mara.

data : i_mara like mara occurs 0 with header line.

start-of-selection.

select * from mara into i_mara.

write:/ i_mara-matnr.

endselect.

  • <b>normal select query</b>

tables : mara.

data : i_mara like mara occurs 0 with header line.

start-of-selection.

select * from mara into <b>table</b> i_mara.

loop at i_mara.

write:/ i_mara-matnr.

endloop.

Read only

abdul_hakim
Active Contributor
0 Likes
1,946

Hi Saritha,

U need to use ENDSELECT when you are looping through the database table ie Fetching more than one entries from the table without using the fetch technique.

For eg.

______

PARAMETERS pa_matnr LIKE mara-matnr.

DATA: wa_mara LIKE mara.

SELECT * FROM mara INTO wa_mara WHERE matnr = pa_matnr.

WRITE:/ wa_matnr-matnr.

ENDSELECT.

Read only

Former Member
0 Likes
1,946

i think if you can paste your select query it will be better to analyze.

but i think you are not spaecifying into table itab. if table word is not there it will ask for endselect. only into will fetch 1 record at a time. so you have to loop it for fetching all the record by select..endselect loop. Or if you want asingle row use select single then it will not ask for endselect.

select matnr into <b>table</b> imara from mara where..." no endselect.

select matnr into imara from mara where..." with endselect.

append itab.

endselect.

or select single matnr into imara from mara where..." without endselect but single row.

regards

shiba dutta

Read only

former_member196280
Active Contributor
0 Likes
1,946

Do this it will won't ask .

TABLES : <Table name>

Reward points.

Regards,

SaiRam

Read only

Former Member
0 Likes
1,946

Hi Saritha,

SELECT-ENDSELECT, as our friends have specified, is like a loop in a database table. If you fire a query like the following one:

SELECT * FROM MARA INTO WA_MARA.
<--logic-->
ENDSELECT.

Here, the runtime environment does not know how many records are there in MARA. It hits the database table, fetch one record, perform the logic, and goes back to find another record. So unless and until you specify a 'SINGLE' or 'INTO TABLE OF', you'll have to use ENDSELECT. The former explicitly specifies that there is only one record coming, and hence a loop is needless, while the latter hits the table and selects all the matching records at one go.

Its always better to go for SELECT..INTO TABLE OF...as it minimizes database hits.

Regards

Anil Madhavan

Read only

dev_parbutteea
Active Contributor
0 Likes
1,946

Hi,

you need only to specify endselect when using select up to n rows.

Else, it affects performance.

Regards,

Sooness.

Read only

Former Member
0 Likes
1,946

Hi Saritha,

<b> It is not advisible to use end select.</b>

So the solution is either if you are

1> selecting a single line of values from the data base tables then use "SINGLE" i.e select single field_name1 field_name2 field_namen from table_name into int_table.

2> Else if you are selecting multiple rows then use INTO table int_table.

This should solve the problem.

Reward Points if useful.

Thanks,

Tej..

Read only

Former Member
0 Likes
1,946

Hi,

bcoz u have not give into clause in your select stmt.

Wheever u r not giving into options its must to give endselect. its like loop at DBTAB.

Jogdand

Read only

Former Member
0 Likes
1,946

hi saritha,

y should write select statement like this to avoid this problem,

select * from <database table> <b>into table</b> <itab> where condition.

because if u dont write <b>table</b> keyword in the select statement then it selects one record from database and fills work area of internal table then append statement can move that record to internal table body from work area,

for this it asks abt end select.

if u write <b>table</b> keyword in select statement then u can avoid this.

u just try this then it dont ask for endslect.

regards,

seshu.

Read only

Former Member
0 Likes
1,946

Hi Saritha,

u need to give the ENDSELECT with SELECT query when ur fetching tha data into work area of the table instead of directly into table.

in this case u need to end the SELECT query with ENDSELECT.

But this will decrease the performance.

Instead of using this directly fetch the data into table instead of work area.

HERE I WILL GIVE U TWO EXAMPLES

SELECT * FROM <table> INTO w_table WHERE <condition>.

ENDSELECT.

NEVER USE THIS INSTEAD.

SELECT * FROM <table> INTO TABLE it_table WHERE <condition>

Reward points if it is helpful,

Thanks,

KRISHNA PRASAD .K