where循环跳出方式
[Syntax]
WHILE <condition> [VARY <f> FROM <f1> NEXT <f2>].
<statement block>
ENDWHILE.
(1)无条件终止循环(CONTINUE):
DATA while_index TYPE N VALUE 0.
WHILE while_index < 5.
while_index = while_index + 1.
IF while_index = 3.
CONTINUE.
ENDIF.
WRITE:/ 'while_index',while_index.
ENDWHILE.
(2)有条件终止循环(CHECK):
DATA while_index TYPE N VALUE 0.
WHILE while_index < 5.
while_index = while_index + 1.
CHECK while_index BETWEEN 2 AND 5.
WRITE:/ 'The while_index is',while_index.
ENDWHILE.
(3)完全终止循环(EXIT):
DATA while_index TYPE N VALUE 0.
WHILE while_index < 5.
while_index = while_index + 1.
IF while_index = 3.
EXIT.
ENDIF.
WRITE:/ while_index.
ENDWHILE.
6)使用ONCHANGE实现循环内部数据管控, 当循环的数值发生变动时,可以用表达式ONCHNAGE来触发数值变动事件。
DATA while_index TYPE N VALUE 0.
WHILE while_index < 5.
while_index = while_index + 1.
DO 2 TIMES.
ON CHANGE OF while_index.
WRITE:/ 'The while_index has change value is',while_index.
ENDON.
WRITE:/ 'SY-INDEX=',SY-INDEX.
ENDDO.
ENDWHILE.