Skip to Content
Technical Articles
Author's profile photo Michael Keller

What does DO/ENDDO do?

Dear community, for the little fun in between here’s some ABAP to check:

DATA lv_count TYPE i VALUE 1.

DO lv_count TIMES.
    lv_count = lv_count + 1.
    WRITE / 'What am I doing?'.
ENDDO.

Simple question is: How often the loop is executed?

Possible answers:

  1. Once only.
  2. Over and over and over (never stops).

If you want to try it out quickly, you should use the transpiler by Lars Hvam. The right answer to the question above is available at help.sap.com.

 

Best regards, thanks for reading and stay healty

Michael

 

P. S.: Not tired of reading blogs? Check this one about ADT element info. Really great!

 

Assigned tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Lars Hvam
      Lars Hvam
          DATA tab TYPE string_table.
          APPEND |foo| TO tab.
          APPEND |bar| TO tab.
          APPEND |moo| TO tab.
          LOOP AT tab TRANSPORTING NO FIELDS WHERE table_line = bar( ).
          ENDLOOP.

      this is also interesting, how many times is the bar() method executed?

      Author's profile photo Shai Sinai
      Shai Sinai
      DATA tab TYPE string_table.
      APPEND |foo| TO tab.
      APPEND |bar| TO tab.
      APPEND |moo| TO tab.
      DATA tabix TYPE sy-tabix.
      LOOP AT tab TRANSPORTING NO FIELDS WHERE table_line = bar( tabix ).
      tabix = sy-tabix.
      ENDLOOP.

      Would make it even more interesting.

      Author's profile photo Lars Hvam
      Lars Hvam

      yeap 😉

      Author's profile photo Jagdish Patil
      Jagdish Patil

      Looks interesting, I wish I could get this, but what is bar( ) method?

      Author's profile photo Jörgen Lindqvist
      Jörgen Lindqvist

      It could be any method, that doesn't really matter, the interesting part is how many times it will be executed... 🙂

      Author's profile photo GED HURST
      GED HURST

      Hmm. I didn't expect that result!