Skip to Content
author's profile photo
Former Member

Select single

Can we use Select single inside the loop..? will it cause any performance issue....?

Regards,

Murugan Arumugam

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

10 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 11:34 AM

    try to avoid select statement inside loop it will decrease the performance

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 11:35 AM

    HI,

    yaa u can.

    but u can select only one row using this.

    this is good compared to select * in performance wise.

    rgds,

    bharat.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 11:35 AM

    You Can.

    Are you using it for validation or reading data. If so then you may wish to use the

    AT NEW command

    So that you only do the read each time the where condition would change.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 11:35 AM

    Hi,

    Why u use select single in loop statement better write your query befor loop statement and then use read statement for use this data according to key field.

    Rewards points if it is useful.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 11:43 AM

    Hi,

    there is no issues using like that.In select single u only have to take care whether the conditions used to fetch includes all primary key fields.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 11:44 AM

    Hello,

    <b>Select statement inside a loop</b> is not a good programming practice. It will make some <b>performance issues</b>. Instead of this u can select the record in to one<b> internal table</b> fist and u can use the <b>read table</b> command inside the loop statement. That is better.

    Reward if helpful,

    Regards,

    LIJO JOHN

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 11:47 AM

    Hi Murugan,

    As far as performance is concerned Select single is not advisable. Better would be, you retreive the data outside the loop into a internal table and then use READ statement. But if the amount of data is less then you can go for SELECT SINGLE also. It will serve your purpose.

    It is a subjective matter and depends on the amount of data you are handling.

    Rewards points if helpful

    regards

    Sourabh Verma

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 11:48 AM

    Hi,

    Avoid select statement using inside loop

    it will decrease the performance.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 11:48 AM

    Hi murugan,

    The <i><b>Best answer</b></i> i could get 4 u is this....

    if you are 100% sure , you can't code a database join, then :

    Theoretically , the "for all entries" clause has an advantage over a loop of select singel by primary key. This is becuase the abap interpreter can group together several rows in the itab into one select (see note <b>48230</b>) so it could get the requested result using less conversations with the database.

    The down side is that by doing so, the where predicates will not be a simple equation predicates, they may become "in" predicates and so on (see note <b>48230</b>). This change in the sql may lead to a more costly access path.

    So, unfortunatly, you will probably be forced to write and test both options and see which costs less.

    • by costs i mean total getpages or "in db2 time" for the whole workload, and not transaction elapsed time.)

    • as a rule of thumb I would lean to select single by primary key, over "for all entries" ... but as i said, its depends on several factors....

    Above article is taken from...

    http://blogs.ittoolbox.com/sap/db2/archives/for-all-entries-vs-db2-join-8912>

    Refer that too...

    Hope it helps!!!

    <i><b>*Reward useful answers*</b></i>

    Regards,

    <b>Naveenan</b>

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 07:30 AM

    Thanks a lot

    Add comment
    10|10000 characters needed characters exceeded