‎2006 Apr 12 7:25 PM
hello everyone,
How can I replace the following with DO/ENDO?
<b>loop</b> at i_po_text.
v_length = strlen( v_text ).
if v_length > 6000.
exit.
endif.
concatenate v_text i_po_text-tdline into v_text separated by space.
move: v_text to i_matl_details-po_text.
<b>endloop.</b>
Regards,
Fred.
‎2006 Apr 12 8:32 PM
I agree with Rob. I don't see why you need to replace the LOOP with DO. Something like you did before should be fine.
LOOP AT i_po_text.
CONCATENATE v_text i_po_text-tdline
INTO v_text SEPARATED BY space.
<b>CONDENSE v_text.</b>
v_length = STRLEN( v_text ).
IF v_length > 6000.
EXIT.
ENDIF.
ENDLOOP.
‎2006 Apr 12 7:28 PM
Fred,
Try this.
DO.
READ Table i_PO_TEXT index sy-index.
v_length = strlen( v_text ).
if v_length > 6000.
exit.
endif.
concatenate v_text i_po_text-tdline into v_text separated by space.
move: v_text to i_matl_details-po_text.
endif.
Regards,
Ravi
Note :Please mark the helpful answers
‎2006 Apr 12 7:29 PM
DO.
READ table i_po_text index sy-index.
concatenate v_text i_po_text-tdline into v_text separated by space.
move: v_text to i_matl_details-po_text.
v_length = strlen( v_text ).
if v_length > 6000.
exit.
endif.
enddo.
‎2006 Apr 12 7:29 PM
Hi,
data: v_lines type i.
describe table i_po_text lines v_lines.
DO v_lines times.
read table i_po_text index sy-index.
if sy-subrc = 0.
v_length = strlen( v_text ).
if v_length > 6000.
exit.
endif.
concatenate v_text i_po_text-tdline into v_text separated by space.
move: v_text to i_matl_details-po_text.
endif.
enddo.Regards
vijay
‎2006 Apr 12 7:36 PM
My 2 cents:
DO.
READ TABLE i_po_text INDEX sy-index.
IF sy-subrc <> 0.
EXIT.
ENDIF.
v_length = strlen( v_text ).
IF v_length > 6000.
EXIT.
ENDIF.
CONCATENATE v_text i_po_text-tdline INTO v_text SEPARATED BY space.
MOVE: v_text TO i_matl_details-po_text.
ENDDO.
Rob
‎2006 Apr 12 8:26 PM
But why do you want to do this? The LOOP is roughly twice as fast as the DO.
Rob
‎2006 Apr 12 8:32 PM
I agree with Rob. I don't see why you need to replace the LOOP with DO. Something like you did before should be fine.
LOOP AT i_po_text.
CONCATENATE v_text i_po_text-tdline
INTO v_text SEPARATED BY space.
<b>CONDENSE v_text.</b>
v_length = STRLEN( v_text ).
IF v_length > 6000.
EXIT.
ENDIF.
ENDLOOP.
‎2006 Apr 12 9:01 PM
hi,
I was told that what I had earlier with 'Loop' is fine, but 'DO/ENDO' is better in terms of performance and that doing 'Loop' within another loop is not good practice.
But if you guyz suggest that I leave it with 'Loop', then let me know, and I won't change it.
Regards,
Fred.
‎2006 Apr 12 9:10 PM
Don't change it. I did test it and the loop is faster. Nested loops should be avoided.
Rob
‎2006 Apr 12 9:12 PM
I am assuming you are talking in the context of your program that reads the change documents to find all the materials that changed. You then pull information regarding all those materials from the materials master tables except the PO text which you are getting from calling READ_TEXT. Here you get the text in an internal table and you want to convert that into a string before updating your final internal table.
loop at materials_that_changed.
get po text in internal table for the current loop
material.
loop at the potext internal table.
prepare the string.
endloop.
move the string to materials_that_changed internal
table field, po_text.
modify.
endloop.Is this accurate description?
If it is true, doing a loop within a loop will not hurt the performance, because at any point of time, your po_text internal table will contain only the text for one material and I guess that should not be more than a couple of records.
Srinivas
‎2006 Apr 12 9:18 PM
Hi Srinivas,
Yes that description is true.
I'll take Rob and your advice and not change my original loop statement.
Appreciate your replies and help very much.
Thanks.
Regards,
Fred.
‎2006 Apr 12 9:25 PM
In my description of your program logic, you have to make sure that you <b><u>refresh the contents of po_text for each material</u></b>. Otherwise you will end up accumulating all the texts for all the materials as you loop.
‎2006 Apr 12 9:36 PM
Srinivas is correct - it's only when both tables become large that problems arise with nested loops.
Rob
‎2006 Apr 12 9:59 PM