Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

need suggestions on my select statement.

Hello experts,

I am having with my select statement since it is running very slow. Normally, the itab it_vendor has records exceeding 7,000. So it loops 7, 000 times and I have 2 select statements which adds to the performance slowdown. Here it is guys:

*Select records records from BSIK and BSAK based on itab it_vendor

LOOP AT it_vendor.

*Select records from BSIK

SELECT belnr lifnr budat buzei gjahr sgtxt dmbtr

shkzg saknr hkont zlspr FROM bsik

INTO TABLE it_bsak

FOR ALL ENTRIES IN it_vendor

WHERE bukrs EQ p_bukrs

AND budat LE p_keydt

AND hkont IN so_saknr

AND lifnr EQ it_vendor-lifnr

AND umsks EQ space

AND umskz EQ space.

*Select records from BSAK

SELECT belnr lifnr budat buzei gjahr sgtxt dmbtr

shkzg saknr hkont zlspr FROM bsak

APPENDING TABLE it_bsak

FOR ALL ENTRIES IN it_vendor

WHERE bukrs EQ p_bukrs

AND augdt GT p_keydt

AND budat LE p_keydt

AND hkont IN so_saknr

AND lifnr EQ it_vendor-lifnr

AND umsks EQ space

AND umskz EQ space.

ENDLOOP.

Tags:
replied

Since you are using the FOR ALL ENTRIES extension of the select statement, you should not have these inside the loop. What it is correctly doing is getting all the records for all the vendors every time thru the loop. The FOR ALL ENTRIES will get all the records for all of the vendors in one shot, no need to LOOP at the internal table. Make sure that you change your where clauses to how I have them below.



* Get the IT_VENDOR itab here


<b> check not it_vendor[] is initial.
sort it_vendor ascending by lifnr .</b>

*Select records from BSIK
SELECT belnr lifnr budat buzei gjahr sgtxt dmbtr
shkzg saknr hkont zlspr FROM bsik
INTO TABLE it_bsak
FOR ALL ENTRIES IN it_vendor
WHERE<b> lifnr EQ it_vendor-lifnr</b>
and  bukrs EQ p_bukrs
AND budat LE p_keydt
AND hkont IN so_saknr
AND umsks EQ space
AND umskz EQ space.

*Select records from BSAK
SELECT belnr lifnr budat buzei gjahr sgtxt dmbtr
shkzg saknr hkont zlspr FROM bsak
APPENDING TABLE it_bsak
FOR ALL ENTRIES IN it_vendor
WHERE  <b>lifnr EQ it_vendor-lifnr</b>
and bukrs EQ p_bukrs
AND augdt GT p_keydt
AND budat LE p_keydt
AND hkont IN so_saknr
AND umsks EQ space
AND umskz EQ space.
 

Regards,

Rich Heilman

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question