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 Single Statement

Former Member
0 Likes
1,822

Hi,

I am using Select Single Statement inside a Loop for Validating , is there any problem regarding Performace.

Loop at itb_file_input into wa_itb_file_input.

......

.......

.......

......

.......

SELECT SINGLE varbl

FROM agr_1252

INTO v_varbl

WHERE agr_name EQ wa_itb_file_input-child

AND varbl EQ wa_itb_file_input-orgname.

.....

....

Endloop.

<i>Thanks .</i>Avi.............

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,224

yes..u shud not use any select statment inside a loop as it will increase database hit time ..on each n every loop pass ur porgram will hit databsae and fetch entries..

instead of tht u can use "slect statement with clause "for all entries" in ur internal table and fetch data in one shot and then u can have loop at on tht internal table to process or validate some other conditions..it will enhance performance..

hope it clarifies..

reward if helpfull.

u can press f1 on select statement to learn abt for all entries variant.

amit

7 REPLIES 7
Read only

anversha_s
Active Contributor
0 Likes
1,224

hi,

avoid that logic.

try this.

1) select the records into an internal table.

2) inside loop use read the above internal table

3) performance will improve

Regards

Anver

Read only

0 Likes
1,224

SINGLE or * a SELECT inside a Loop will always adversley affect the Performance.. Use an Itab. sort it & READ itab with Key.. BINARY search for a much improved performance..

~Suresh

Read only

alex_m
Active Contributor
0 Likes
1,224

Yes, it will give perfromance issues. Instead of selecting one time u r selecting multiple time right.

Better dont use select statement inside loop.

Read only

santhosh_patil
Contributor
0 Likes
1,224

HI,

i think there is no problem...

just clear the field v_varbl after each passs...

Only problem it may lead to is performance....drop

--santhosh

Read only

Former Member
0 Likes
1,225

yes..u shud not use any select statment inside a loop as it will increase database hit time ..on each n every loop pass ur porgram will hit databsae and fetch entries..

instead of tht u can use "slect statement with clause "for all entries" in ur internal table and fetch data in one shot and then u can have loop at on tht internal table to process or validate some other conditions..it will enhance performance..

hope it clarifies..

reward if helpfull.

u can press f1 on select statement to learn abt for all entries variant.

amit

Read only

Former Member
0 Likes
1,224

hi Avi .. Select query inside a loop always has impact on performance.

You can use

Select varbl INTO i_varbl FROM agr_1252

FOR ALL ENTRIES IN itb_file_input

WHERE agr_name EQ itb_file_input-child

AND varbl EQ itb_file_input-orgname.

i_varbl is an internal table.

Read only

Former Member
0 Likes
1,224

Hi,

It is better not to use SELECt within a loop, instead you can do as

SELECT  varbl
FROM agr_1252
INTO table i_varbl
FOR ALL ENTRIES IN i_itb_file
WHERE agr_name EQ i_itb_file_input-child
AND varbl EQ i_itb_file_input-orgname.

Loop at itb_file_input into wa_itb_file_input.
......
.......
.......
......
.......
READ TABLE i_itb_file into wa_itb_file
 WITH KEY agr_name EQ wa_itb_file_input-child
         varbl EQ wa_itb_file_input-orgname.
IF sy-subrc = 0.
 v_varbl = wa_itb_file-varbl.
ENDIF.
.....

 ....

Endloop.

Hope you are clear.

Reard poinst and close the thraed if ur problem go solved.