2019-02-15——ABAP6回路控制

循环类型

循环类型 说明
while 当给定条件为真时,重复一个语句或一组语句。在执行循环体之前测试条件
do do语句对于将特定任务重复特定次数很有用
nested(嵌套) 可以在任何另一个while或do循环中使用一个或多个循环

while

while 
.
endwhile
report ys_sep_15.
data: a type i.
a=0.
while a<>8.
  write: / 'this is the line:', a.
  a=a+1.
endwhile.
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

DO

do [n times].
.
enddo.
report yh_sep_15.
do 5 times.
write: / 'hello'.
enddo.
Hello 
Hello 
Hello 
Hello 
Hello 

nested(嵌套)

do [n times].
.
  do [m times].
  .
  enddo.
enddo.
report ys_sep_15.
data: a1 type i, b1 type i.
a1 = 0.
b1 = 0.
do 2 times.
a1 = a1 + 1.
write: / 'outer', a1.

do 3 times.
b1 = b1 + 1.
write: / 'inner', b1.
enddo.
enddo.
Outer   1 
Inner   1 
Inner   2 
Inner   3 
Outer   2 
Inner   4
Inner   5 
Inner   6

循环控制语句

控制语句 说明
continue 导致循环跳过其身体的剩余部分,并开始下一个循环传递
check 如果条件为假,则在check之后的剩余语句被忽略,并且系统开始下一循环通过
exit 完全终止循环,并将执行转移到循环后立即执行的语句

continue

report yh_sep_15.
do 5 times.
if sy-index = 3.

continue.

endif.
write / sy-index.
enddo.
1
2
4
5

check

report th_sep_15.
do 5 times.
check sy-index detween 3 and 4.
write / sy-index.
enddo.
3
4

exit

report yh_sep_15.
do 5 times.
if sy-index = 3.
exit.
endif.
write / sy-index.
enddo.
1
2

你可能感兴趣的:(2019-02-15——ABAP6回路控制)