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 count problem

Former Member
0 Likes
594

Hi i use the select count in loop and i now that its not good for performence . in this loop i count employee that in org. unit and in wa_teken_itab-objid i have every time other org unit . maybe someone have idea how can change it for a better select

regards

LOOP AT teken_itab INTO wa_teken_itab.

SELECT stell COUNT( * ) AS ex_immobile_num "job

FROM pa0001

INTO wa_count_immobile_itab

WHERE ( persg EQ '6' OR persg EQ '7' OR persg EQ '8' ) "Employee Group

AND orgeh = wa_teken_itab-objid

AND orgeh NE '00009999' "Org Unit

AND begda <= so_date

AND endda => so_date

GROUP BY stell.

IF sy-subrc = 0.

APPEND wa_count_immobile_itab TO count_immobile_itab.

CLEAR wa_count_immobile_itab.

ENDIF.

ENDSELECT.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
566

Hi,

Instead of using select in loop you can go for Select for all entries option.

Ashvender

4 REPLIES 4
Read only

Former Member
0 Likes
567

Hi,

Instead of using select in loop you can go for Select for all entries option.

Ashvender

Read only

0 Likes
566

o.k... but its a problem becouse u cant do select for all entries in count statment

regards

Read only

0 Likes
566

Hi,

Ok. If select for all entries cannot be used then make it as Select Single statement or Select .... INTO TABLE statement instead of Select & Endselect.

Ashvender

Read only

Former Member
0 Likes
566

Antonio,

LOOP AT teken_itab INTO wa_teken_itab.

SELECT stell COUNT( * ) AS ex_immobile_num "job

FROM pa0001

INTO wa_count_immobile_itab

********************************************

FOR ALL ENTRIES IN wa_teken_itab

WHERE orgeh = wa_teken_itab-objid and

***************************************************

( persg EQ '6' OR persg EQ '7' OR persg EQ '8' ) "Employee Group

AND orgeh NE '00009999' "Org Unit

AND begda <= so_date

AND endda => so_date

GROUP BY stell.

IF sy-subrc = 0.

APPEND wa_count_immobile_itab TO count_immobile_itab.

CLEAR wa_count_immobile_itab.

ENDIF.

********************

ENDSELECT.

******************

ENDLOOP.