‎2011 Jul 25 10:28 AM
Hello ,
I am trying to aviod the below select statement within a loop statement , got to know that this select cannot be avioded by other colleagues. Any suggestions?
Have also searched the forum, and got to know that not all selects within loops are avioded.
Here , inside the table t_t682i, I need entries where KSCHL = ZP17. But If I aviod the loop using READ statment,
the possibility is , I dont find any values for the first entry of ZP17 , then I have to go to second entry and get the values.
LOOP AT t_t682i ASSIGNING <lfs_t682i>.
SELECT kschl
vkorg
matnr
knumh
INTO TABLE t_knumh_mrp
*FROM (<lfs_t682i>-atab)*
FOR ALL ENTRIES IN lt_mkpf_mseg
WHERE kschl = zp17
AND vkorg = in02
AND matnr = lt_mkpf_mseg-matnr
AND ( datab LE lt_mkpf_mseg-budat AND datbi GE
lt_mkpf_mseg-budat ).
ENDLOOP.
Edited by: B@SAP123 on Jul 25, 2011 2:59 PM
‎2011 Jul 25 10:39 AM
Hello,
LOOP AT t_t682i ASSIGNING <lfs_t682i>.
SELECT ....
INTO TABLE t_knumh_mrp
*FROM (<lfs_t682i>-atab)*
FOR ALL ENTRIES IN lt_mkpf_mseg
WHERE kschl = zp17
AND vkorg = in02
AND matnr = lt_mkpf_mseg-matnr
AND ( datab LE lt_mkpf_mseg-budat AND datbi GE
lt_mkpf_mseg-budat ).
ENDLOOP.Are you selecting data dynamically from the DDIC table, whose name is maintained in <lfs_t682i>-atab ? If yes, i can't think of any logic to avoid the LOOP!
BR,
Suhas
‎2011 Jul 25 10:46 AM
Hi Suhas,
Thanks for the reply.
Yes. The DDIC table name from which I need to select is in the table t_t682i (<lfs_t682i>-atab ) , I am selecting dynamically
Thanks,
Vijaya
‎2011 Jul 25 11:29 AM
Hello Vijaya,
Just make sure that you've done a D.A.D from t_t682i based on the field atab
SELECT inside LOOP is not suggested if you're selecting data from the same DB table. In your case it is more like selecting data from different tables(which are not known till runtime).
May be the performance gurus might have something to add.
BR,
Suhas
‎2011 Jul 25 12:39 PM
Hello Suhas,
Thanks. May be basic question, but could nto get what you meant by
"" make sure that you've done a D.A.D from t_t682i based on the field atab ""
If it was to mean to SORTING, deleting the duplicates from the table , then yes, I have done that.
Edited by: B@SAP123 on Jul 25, 2011 5:10 PM
‎2011 Jul 25 3:40 PM
Hello Vijaya,
If it was to mean to SORTING, deleting the duplicates from the table , then yes, I have done that.
If you've deleted the duplicates from the internal table t_t682i , i don't think there should be problem.
‎2011 Jul 26 1:13 PM
I can confirm, as soon as you are selecting here from different tables, you are on a safe side.
‎2011 Aug 11 4:48 PM
Hi,
Selecting data from the same table inside a loop is a performance issue.
in your case, u r selecting the details from differnt database tables which is known only at run time. i feel this is not at all a performance issue.
‎2011 Jul 28 9:21 AM
hi,
Try to take join and use for all interies instead of select inside loop.
regards,
Amit
‎2011 Aug 18 2:54 PM
I second gayatri. In any case this is an interesting read.
‎2011 Aug 23 4:41 PM