SAP ABAP - Do Loop


Advertisements

Unconditional loops repeatedly execute several statements without specifying any condition. The DO statement implements unconditional loops by executing a set of statement blocks several times unconditionally.

Syntax

The general format for the DO statement is as follows −

DO [n TIMES]. 
 
<statement block>.
  
ENDDO.

‘Times’ imposes a restriction on the number of loop passes, which is represented by ‘n’. The value of ‘n’ should not be negative or zero. If it is zero or negative, the statements in the loop are not executed.

Flow Diagram

Do While Loop

Example

Report YH_SEP_15.
  
Do 15 TIMES. 
 
Write: / 'Hello'.
  
ENDDO.

The above code produces the following output −

Hello 
Hello 
Hello 
Hello 
Hello 
Hello 
Hello 
Hello 
Hello 
Hello 
Hello 
Hello 
Hello 
Hello 
Hello

In this example, the system understands that the loop is to be processed 15 times.

sap_abap_loop_control.htm
Advertisements