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 statement.

Former Member
0 Likes
7,148

hi can anybody tell me when we use select..endselect statement. is it good using this statement.

11 REPLIES 11
Read only

Former Member
0 Likes
2,602

Hi,

The select .. endselect works as a loop fetching single record for every loop pause..

as you kept a select inside a loop .. you have 2 loops.. going to the database unnecessarily so many times is not a good idea...

instead you can write

select * from ztable3 for all entries in itab1 where field4 = itab1-field4.

then ...

loop at itab1.

read table ztable3 with key field4 = itab1-field4.

..move your fields...

append itab2.

endloop.

Do not use select endselect and it affects the performance issue

Regards,

Priyanka.

Read only

Former Member
0 Likes
2,602

hi,

If the result of the selection is meant to be a table, the data is usually (for further information, see INTO -Klausel ) read line by line within a processing loop introduced by SELECT and concluded by ENDSELECT . For each line read, the processing passes through the loop once. If the result of the selection is meant to be a single record, the closing ENDSELECT is omitted.

SELECT is not concluded by ENDSELECT

if it is a SELECT SINGLE command,

if only aggregate functions appear in the INTO clause or

if the INTO clause INTO TABLE itab or APPENDING TABLE itab does not include the addition PACKAGE SIZE .

don't use select /endselect instead use table incase of multiple records .

Read only

Former Member
0 Likes
2,602

Hi

Select ... endselect is not advisible to use in ABAP program. It will affect ur system performance. Instead use into table internal.

Ex:

select matnr .... from mara into table itab where matnr = p_matnr....

Reward me if its useful.

Regards

Ravi

Read only

0 Likes
2,602

I disagree. It all depends on what you want to do. I find the SELECT ... ENDSELECT statement very useful for some purposes.

So let's say we have to check for some criterium to determine if a possible problem is a real problem.

DATA: l_client TYPE syst-mandt.
...
IF some-test-that-is-true.
  SELECT mandt
         INTO l_client
         FROM t001
         WHERE bukrs =  l_mydata-bukrs AND
               waers <> l_mydata-waers
    l_error = 'X'.
  ENDSELECT.
ENDIF.

This as opposed to selecting into a variable and then checking if something was found. Unfortunately the SELECT statement has no addition similar to TRANSPORTING NO FIELDS for READ TABLE.


Kjetil Kilhavn (Vettug AS) - ABAP developer since Feb 2000, but will probably never be a Rockstar developer
Read only

Former Member
0 Likes
2,602

I think the best way to use this statement is when you are using only one access and process of the table. All action is inside the statement.

Ex:

Select * from table

-


all you need must be inside this statement and not accessing it again.

-


Endselect

Read only

Former Member
0 Likes
2,602

HI,

YOU USE SELECT ENDSELECT WHEN YOU WANT TO LOOP THE RECORDS OF A TABLE

BUT YOU ALLREADY LOOP IT EXTERNALLY SO LOOPING A TABLE 2 TIMES IS NOT A GOOD THING IT WILL EFEECT YOUR SYSTEM PERFOMANCE

SO IT'S BETEER TO AVOID IT.

Read only

Former Member
0 Likes
2,602

Hi,

Select ... endselect is not recommended if data is huge. u can use this will very small tabls.

Jogdand M B

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,602

Select Endselect statement are mostly used when any arithmetical calculations are performed.(ie...select sum, select max etc...)

Instead of applying this in normal data fetch we can use select single which gives better performance when compared to select endselect.

Read only

Former Member
0 Likes
2,602

The ENDSELECT statement closes a loop started with SELECT.





A SELECT command for which the INTO|APPENDING TABLE</b> itab is inserted into an internal table, must be followed by ENDSELECT if the addition PACKAGE SIZE is used.

For all other SELECT commands, ENDSELECT must be used unless a single line above the addition SINGLE is read after SELECT and unless the columns of the result set are statically specified and contain only aggregate functions without the specification of the addition GROUP BY.

Syntax 
SELECT result 
       FROM source 
       INTO|APPENDING target 
       [[FOR ALL ENTRIES IN itab] WHERE sql_cond] 
       [GROUP BY group] [HAVING group_cond] 
       [ORDER BY sort_key]. 
  ... 
[ENDSELECT].

Effect

SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects.

The select statement reads a result set (whose structure is determined in result) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set.

The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops.

Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the current application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions.

reward points if it is usefull ...

Girish

Read only

Former Member
0 Likes
2,602

Hi Kiran Reddy,

I Think Girish Kumar Answer is suitable for your query........

Don't confuse with multipple answers just understand the currect answer.

<b>My Advice is to avoid the Select...Endselect it will decrease the performance.</b>

<u><b>Go thru the following link for more info on where we use select..endselect statement</b></u>

http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm

If it is useful allocate points

Regards,

<i><b>Naveen Mutyapu</b></i>

Read only

Former Member
0 Likes
2,602

hai,

select..endselect acts as a loop to retrieve data from database table.

try this example.

this will retrieve and display rows from kna1 database table.

data:begin of a1 occurs 10,

a(10) type c,

b(10) type c,

end of a1.

select * from kna1 into kna1 up to 10 rows.

write : at / kna1-kunnr, 20 kna1-name1.

end select.

loop at a1;

write: at / a1-a, 20 a1-b.

endloop.