‎2007 Dec 19 10:01 AM
Hi,
I am using a nested LOOP in my print program that uses a form in SAPScript. Please see the code fragment:
LOOP AT it_final INTO wa_final.
LOOP AT it_mseg INTO wa_mseg.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'HEAD'
type = 'TOP'
window = 'MAIN'.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'INFO'
type = 'BODY'
window = 'MAIN'.
ENDLOOP.
ENDLOOP.
The internal table IT_MSEG usually contains only minimal number of lines, say less than 10. I can't find an alternative in this particular scenario. Is it gonna make the system considerably slower?
‎2007 Dec 19 10:08 AM
Hi,
try to use where condition for your second loop base on the values from 1st internal table, may be you have 10 rec in development when coming to production system there may be a chance of getting more records.
Reward if useful.
Thanks,
Sreeram.
‎2007 Dec 19 10:08 AM
Hi,
try to use where condition for your second loop base on the values from 1st internal table, may be you have 10 rec in development when coming to production system there may be a chance of getting more records.
Reward if useful.
Thanks,
Sreeram.
‎2007 Dec 19 11:14 AM
Dear Sreeram,
Data in IT_MSEG is already filtered based on input in select-options. The problem with your suggestion is, there is no direct link between IT_FINAL and IT_MSEG.
Arun.
‎2007 Dec 19 10:10 AM
‎2007 Dec 19 11:15 AM
Sravan,
I'm not talking about nested selects. I'm using nested "LOOP AT". In the loop, I'm not touching the database at all.
‎2007 Dec 19 10:26 AM
Hi Arun,
IF it_final is your header level and it_mseg is your item level then I dont think you can avoid this nested loop.
But if you have to select a single entry from it_mseg, then you can do like this,
LOOP AT it_final INTO wa_final.
READ TABLE it_mseg INTO wa_mseg.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'HEAD'
type = 'TOP'
window = 'MAIN'.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'INFO'
type = 'BODY'
window = 'MAIN'.
ENDLOOP.
Regards
Sourabh Verma
‎2007 Dec 19 11:07 AM
Thats the problem Sourabh, It is not a single entry that i take from IT_MSEG. IT_FINAL is at header level. IT_MSEG has line items.
‎2007 Dec 19 11:19 AM
Hi, see this link:
/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops
Rob recomends the indexed or parallel loop...
Regards
‎2007 Dec 20 4:47 AM
Dear Rodrigo,
That blog by Rob was really worth. Thanks. Thanks to all.
Regards
Arun.
‎2007 Dec 20 4:39 AM
For nested loops problem, go for parellel cursor technique , an eg. simmilar to ur req. header and line item can be printed/processed in the manner as given below.
SORT : it_mara BY matnr ,
it_makt BY matnr .
i = 1.
LOOP AT it_mara INTO wa_mara.
LOOP AT it_makt INTO wa_makt FROM i.
IF wa_makt-matnr <> wa_mara-matnr.
i = sy-tabix.
EXIT.
ENDIF.
write 😕 wa_mara-matnr , wa_makt-MAKTX .
ENDLOOP.
ENDLOOP.
PS: Reward Poins if Helpfull.
Regards
Naveen Gupta
‎2007 Dec 20 4:46 AM