data: N1(1), N2(1), N3(2). do 9 times. N1 = SY-INDEX. do 9 times. N2 = SY-INDEX. N3 = N1 * N2. write: N1, 'x', N2, '=', N3, '|'. enddo. write SY-ULINE. enddo.
data: begin of TEXT, WORD1(4) value 'This', WORD2(4) value 'is', WORD3(4) value 'a', WORD4(4) value 'loop', end of TEXT. data: STRING1(4), STRING2(4). do 4 times varying STRING1 from TEXT-WORD1 next TEXT-WORD2. write STRING1. if STRING1 = 'is'. STRING1 = 'was'. " TEXT-WORD2的值也會變更 endif. enddo. skip. skip. do 2 times varying STRING1 from TEXT-WORD1 next TEXT-WORD3 varying STRING2 from TEXT-WORD2 next TEXT-WORD4. write: STRING1, STRING2. enddo.
This is a loop This was a loop
data: begin of WORD, W1(1) value 'a', W2(1) value 'b', W3(2) value 'c', W4(3) value 'd', W5(4) value 'e', end of WORD. data LEN type I. describe field WORD length LEN in character mode. " 以文字模式計算物件長度 data STR2(1). do len times varying STR2 from WORD-W1 next WORD-W2. " STR2, WORD-W1, WORD-W2的類型及長度需相同 write: '(' no-gap, STR2 no-gap, ')'. enddo.
(a) (b) (c) ( ) (d) ( ) ( ) (e) ( ) ( ) ( )