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

help with select

Former Member
0 Likes
1,001

select count(*) belnr gjahr

from rseg

into (z_count , rseg-belnr , rseg-gjahr)

where ebeln = <ls_itab>-ebeln

and ebelp = <ls_itab>-ebelp

and lfbnr = <ls_itab>-lblni

group by belnr gjahr.

if sy-subrc = 0.

<ls_itab>-zgjahr = rseg-gjahr.

<ls_itab>-zbelnr = rseg-belnr.

endif.

endselect.

what is wrong with this???

i heard that <b>ENDSELECT</b> not good for performance what can i do to not use it in this select.

11 REPLIES 11
Read only

Former Member
0 Likes
967

Create a table with the three field and then change the select statement to

select count(*) belnr gjahr

from rseg appending

into table count_tab

where ebeln = <ls_itab>-ebeln

and ebelp = <ls_itab>-ebelp

and lfbnr = <ls_itab>-lblni

group by belnr gjahr.

Regards,

Ravi

Read only

Former Member
0 Likes
967

select count(*) belnr gjahr

from rseg

into (z_count , <b>rseg-belnr , rseg-gjahr</b>)

where ebeln = <ls_itab>-ebeln

and ebelp = <ls_itab>-ebelp

and lfbnr = <ls_itab>-lblni

group by belnr gjahr.

if sy-subrc = 0.

<ls_itab>-zgjahr = <b>rseg-gjahr</b>.

<ls_itab>-zbelnr = <b>rseg-belnr</b>.

endif.

endselect.

1)u select the value from rseg and into rseg both in same table.

make a internal table type rseg where u store seelcted value.

2)if u use any airthmatic function( count , sum...) than u have to use select end select.

3) to avoid select end select.ur requirment is to calulate total number of data use <b>SY-DBCNT</b>

Read only

0 Likes
967

Do you want to modify <ls_itab>? Then do this:

select ebeln ebelp lblni belnr gjahr

from rseg

into table itab

FOR ALL ENTRIES IN <ls_itab>

where ebeln = <ls_itab>-ebeln

and ebelp = <ls_itab>-ebelp

and lfbnr = <ls_itab>-lblni.

if sy-subrc = 0.

SORT itab BY ebeln ebelp lblni.

LOOP AT <ls_itab>.

l_tabix = sy-tabix.

READ TABLE itab WITH KEY ebeln = <ls_itab>-ebeln

ebelp = <ls_itab>-ebelp

lblni = <ls_itab>-lblni.

IF sy-subrc = 0.

<ls_itab>-zgjahr = itab-gjahr.

<ls_itab>-zbelnr = itab-belnr.

MODIFY <ls_itab> INDEX l_tabix

TRANSPORTING gjahr belnr.

ENDIF.

ENDLOOP.

endif.

Read only

sridharreddy_kondam
Active Contributor
0 Likes
967

Hi Tal,

Declare one internal table with required fields ...

Then

select count(*) belnr gjahr

from rseg

into <b>table internal table</b>

where ebeln = <ls_itab>-ebeln

and ebelp = <ls_itab>-ebelp

and lfbnr = <ls_itab>-lblni

group by belnr gjahr.

Now loop the inernal table and then then check the conditions using Read and if sy-subrc = 0 then delte that record from internal table..

Regards,

Sridhar

Read only

Former Member
0 Likes
967

Liat,

In fact better to avoid SELECT -ENDSELECT. But in your case, since you are using COUNT SELECT -ENDSELECT is needed.

SELECT -ENDSELECT is having the posibility of hiting the database multiple times which reduced the performances.

Cheers,

Thomas.

Read only

Former Member
0 Likes
967

hi,

use <b>for all entries</b> instead of select and endselect.

select count(*) belnr gjahr
from rseg
into table itab
for all entries in <ls_itab>
where ebeln = <ls_itab>-ebeln
and ebelp = <ls_itab>-ebelp
and lfbnr = <ls_itab>-lblni
group by belnr gjahr.

Regards

vijay

Read only

0 Likes
967

i made this

select belnr gjahr

from rseg

into table itab

for all entries in <ls_itab>

where ebeln = <ls_itab>-ebeln

and ebelp = <ls_itab>-ebelp

and lfbnr = <ls_itab>-lblni.

and i get

unable to interept <ls_itab>

Read only

0 Likes
967

Hi Tal,

I think the fields in ls_itab are not matching with the selct fields...u have to select the common fields in both tables...

Check this Link which can definitely help u...

<b>http://www.sapdevelopment.co.uk/tips/tips_select.htm</b>

Just compare with u r requirement and u will solve it...

Regards,

sridhar

Message was edited by: sridhar reddy kondam

Read only

0 Likes
967

How is <ls_itab> defined in your code? Earlier I thought it was already defined min your program as an internal table looking at you code, something like this:

FIELD-SYMBOL: <ls_itab> TYPE STANDARD TABLE.

But now seems it is not the case. What is <ls_itab> then?

Read only

0 Likes
967

field-symbols: <ls_itab> like itab1.

Read only

0 Likes
967

I didnot understand. If you want to have the field symbol of structure like itab1, then why do you need field symbol at all? you could have itab1 itself instead. We generally use field symbol where its structure will be determined at the run time.