Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Michael_Keller1
SAP Champion
SAP Champion
5,444
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!

 
7 Comments
larshp
Active Contributor
    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?
shais
Participant
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.
larshp
Active Contributor
0 Kudos
yeap 😉
ged_hurst
Participant
Hmm. I didn't expect that result!
jpsapabap21
Participant
0 Kudos
Looks interesting, I wish I could get this, but what is bar( ) method?
joltdx
Active Contributor
It could be any method, that doesn't really matter, the interesting part is how many times it will be executed... 🙂
SimonOne
Explorer
0 Kudos
https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapdo.htm
The number value of n when entering the loop determines the maximum amount of passes of the statement block.

So loop once only.