SAP ABAP - While Loop


Advertisements

A WHILE loop statement repeatedly executes a target statement as long as a given condition is true.

The general format for the WHILE command is as follows −

WHILE <logical expression>  

<statement block>. 
    
ENDWHILE.

The statement block may be a single statement or a block of statements.

The WHILE loop executes the statements enclosed by the WHILE and ENDWHILE commands until the logical expression becomes false.

Flow Diagram

While Loop

The WHILE command is preferable while considering the performance of programs. The loop continues until the logical statement is found to be untrue and exits the loop if a false statement is found, and the first statement after the WHILE loop is executed.

Example

REPORT YS_SEP_15.
  
DATA: a type i. 
 
a = 0.
  
WHILE a <> 8.
  
   Write: / 'This is the line:', a.  
   a = a + 1.
   
ENDWHILE.

The above code produces the following output −

This is the line: 0 
This is the line: 1 
This is the line: 2 
This is the line: 3 
This is the line: 4 
This is the line: 5 
This is the line: 6 
This is the line: 7
sap_abap_loop_control.htm

Useful Video Courses


Video

SAPUI5 Online Training

25 Lectures 6 hours

Sanjo Thomas

Video

SAP Webi Online Training

Most Popular

26 Lectures 2 hours

Neha Gupta

Video

SAP Basis Online Training

30 Lectures 2.5 hours

Sumit Agarwal

Video

SAP C4C Online Training

30 Lectures 4 hours

Sumit Agarwal

Video

SAP MM Online Training

14 Lectures 1.5 hours

Neha Malik

Video

SAP WM Online Training

13 Lectures 1.5 hours

Neha Malik

Advertisements