Example to apply WHILE statement in ABAP/4

You will apply this statement when you want to loop data with condition loops.

Example 1: Simple Loop

DATA: lv_int TYPE I VALUE 1.
WHILE lv_int <= 4.
WRITE:/ lv_int.
lv_int = lv_int + 1.




ENDWHILE.

The output is 

1
2
3
4

Example 3: Nested Loops

DATA: lv_int TYPE I VALUE 1,
lv_int2 TYPE I.

WHILE lv_int <= 4.
WRITE:/ lv_int.
lv_int2 = 1.
WHILE lv_int2 <= 2.
WRITE: lv_int2.
lv_int2 = lv_int2 + 1.
ENDWHILE.
lv_int = lv_int + 1.




ENDWHILE.

The output is 


1  1 2
2 1 2
3 1 2
4 1 2

Post new comment