Application Development 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: 

Replacing 'Loop' with 'Do'...

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

13 REPLIES 13

Former Member
0 Kudos

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

LucianoBentiveg
Active Contributor
0 Kudos

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.

former_member188685
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

But why do you want to do this? The LOOP is roughly twice as fast as the DO.

Rob

Former Member
0 Kudos

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.

0 Kudos

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.

0 Kudos

Don't change it. I did test it and the loop is faster. Nested loops should be avoided.

Rob

0 Kudos

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

0 Kudos

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.

0 Kudos

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.

0 Kudos

Srinivas is correct - it's only when both tables become large that problems arise with nested loops.

Rob

0 Kudos

Yes, I am already refreshing the tables.

Thanx.

Fred.