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 within loop

Former Member
0 Likes
3,890

hi All,

how good it would be to use SELECT within a loop endloop.

and it may sound stupid but can any standard function module be stopped from giving MESSAGES.?

Regards

14 REPLIES 14
Read only

Former Member
0 Likes
2,467

if u dont bother about performance then go for it,

but its not at all gud to use select with in loop

Read only

0 Likes
2,467

Its better use READ TABLE into the LOOP ... ENDLOOP.

Read only

0 Likes
2,467

if u dont bother about performance then go for it,

but its not at all gud to use select with in loop.

standard function module be stopped from giving MESSAGES.?------> y and when u are expecting this kind of messages

Read only

Former Member
0 Likes
2,467

with selects you have to look at it from the DB side. If you do a internal table loop and a single single row from DB every time, then the program will not be designed to scale. If instead, you do an internal loop but a select that retrieves multiple rows from the DB, you should be ok.

Either way, you don't want to select too small or too much data from the DB at once. Too small = too much overhead, inefficient. Too large = your ABAP memory blows up the instance.

Read only

Former Member
0 Likes
2,467

Hi,

how good it would be to use SELECT within a loop endloop

There is nothing wrong using it...but performance will be the major problem instead of that why don't you do this way instead of select do you select before the loop and try to read with in loop statement that will be good. why do you want to use select inside loop statement.

I didnt understand your second question.

Thanks

Vikranth

Read only

Former Member
0 Likes
2,467

"Standard function module be stopped from giving MESSAGES"

Most likely not. Unless you are willing to change standard SAP code, which means pain with SPAU with every support pack upgrade. Rather, why not just ignore it? If you are writing a customized program, just ignore it if you don't care for the messages.

Read only

0 Likes
2,467

HI ALL,

thanks for the replies. let me explain the problem in detail. its like i have 4 fields that needs to be validated and those are in a internal table or each field i have got sap stndard function modules but they give messages ands not return error code in a table like return(as in any BAPI).

for each row of the table these four fields needs to be validated, how do i do it without using select inside a loop?

regards

Read only

0 Likes
2,467

Hi,

Loop your internal table and get those 4 fields into one variable and then after the loop you do validation that will be fine right.

Thanks

Vikranth

Read only

0 Likes
2,467

I assume that your internal table is already filled with entries,

Now inside the loop why do you want to use a select statement ( are you getting any more data from DB )

If you are using only one standard function module for each of the field validation, then go for code inside the function module ( check which tables are accessed by the FM and what conditions it might be checking and based on which it is issuing the messages, and of them you might be needing only few ) . Use this code ( except for triggering the messages, where you can substitute your own code of setting error codes or anything ) in a subroutine inside the loop. In that way you can avoid the messages.

If you can reply the function module you are using, let me help you with that

Read only

Former Member
0 Likes
2,467

i think you are tryin to get information with a specific data that you hve for each loop pass.

you have have to use the following.

loop at it_table into wa_table.

select * into wa_area

from transparent-table

where field = wa_table-field.

append wa_area to it_newtable.

clear wa_area.

endloop.

but i think that process with take a log time to get at end, i think you have to have the information first into the table i_table and make a read table to the second table.

loop it_table into wa_table.

read table it_table2 into wa_area2 with key field = wa_table-field.

if sy-subrc = 0

move the fields you need to new work area wa_newtable.

append wa_newtable to it_newtable.

endif.

endloop.

endloop.

Read only

Former Member
0 Likes
2,467

Hi,

There is nothing wrong in using SELECT within LOOP and ENDLOOP. Here the performance issue comes into pictures because, If an internal table that ur trtying to loop had large number of records and If you use SELECT with that loop, thnen it will try to hit the database that many times. You are trying to rectierve a record that many times from database table which increases the access time to read or write.

You are increasing the load on the database.

Generally, we dont use it. Instead use the READ table inside a Loop.

IF you dont want to a function module to throw messages then dont handle exceptions in it.

One more thing, Some of the BAPI funciton modules doesnt return exceptions insted they will handle errors in RETURN structure ie BAPIRETURN type.

Here we can process the errors but not the exceptions.

Reward if helpful.

Best Wishes,

Chandralekha

Read only

Former Member
0 Likes
2,467

Hi,

If you want to retrieve records from table according to the internal table values then its better to use for all entries of i_itab in select statement. Within the select query only you can check the condition( Validating the fields ).

Regards,

Rajitha.

Read only

Former Member
0 Likes
2,467

hi,

There is no harm in using SELECT statement inside a LOOP and ENDLOOP statement. Performance is an issue with this option. Using SELECT statement will hit the database several times. Hence you have to be careful of performance while using SELECT.

Reward if Useful

Sumit Agarwal

Read only

0 Likes
2,467

Is there any exception using for Bufferred tables with in loops?