这是我第一次使用ABAP。
DATA: n(1) TYPE I VALUE '2',
sum(2) TYPE I.
DEFINE multiple.
WHILE sy-index < 10.
sum = &1 * sy-index.
WRITE: / &1, 'x', sy-index, sum.
ENDWHILE.
END-OF-DEFINITION.
DO 9 TIMES.
IF sy-index = 1.
CONTINUE.
ENDIF.
multiple sy-index.
ENDDO.
所以,在我的程序产生的输出下面。
1 x 1 1
2 x 2 4
3 x 3 9
实际的结果不是我所期望的。
预期结果应该是…
2 x 1 2
2 x 2 4
2 x 3 6
2 x 4 8
2 x 5 10
..
..
..
首先,请不要在表单、宏、方法或函数模块中操作全局变量。将其作为参数传递。
其次,这里有一些解决你问题的方法。
我还将multiple
功能作为宏,但它应该至少作为FORM
实现。
DATA: sum(2) TYPE i.
DATA: l_outer_loop_index TYPE i.
DEFINE multiple.
sum = &1 * &2.
WRITE: / &1, 'x', &2, sum.
END-OF-DEFINITION.
DO 9 TIMES.
IF sy-index = 1.
CONTINUE.
ENDIF.
l_outer_loop_index = sy-index.
DO 9 TIMES.
multiple l_outer_loop_index sy-index.
ENDDO.
ENDDO.
谢谢Jagger,我参考了他的回答。我有一点零钱。这是我的第一个答案。我希望这对你有帮助。
DATA: sum(2) TYPE i.
DATA: sumstring(2) TYPE c.
DATA: l_outer_loop_index TYPE i.
DATA: result(100) TYPE c.
DATA: num1(10) TYPE c,
num2(10) TYPE c.
DEFINE multiple.
clear: result.
sum = &1 * &2.
WRITE &1 to num1.
WRITE &2 to num2.
WRITE sum to sumstring.
CONDENSE sumstring.
CONDENSE num1.
CONDENSE num2.
concatenate num1 'x' num2 '=' sumstring INTO result SEPARATED BY space.
WRITE: / result.
END-OF-DEFINITION.
DO 9 TIMES.
IF sy-index = 1.
CONTINUE.
ENDIF.
l_outer_loop_index = sy-index.
DO l_outer_loop_index TIMES.
multiple l_outer_loop_index sy-index.
IF l_outer_loop_index = sy-index.
WRITE: / .
ENDIF.
ENDDO.
ENDDO.
试试我的解决方案
DATA: n(1) TYPE i VALUE '2',
sum(2) TYPE i.
DO 9 TIMES.
IF sy-index = 1.
CONTINUE.
ENDIF.
PERFORM multi using sy-index.
ENDDO.
FORM multi USING i_num TYPE i.
DATA: lv_num TYPE i.
MOVE i_num TO lv_num.
DO 10 TIMES.
IF sy-index = 1.
CONTINUE.
ENDIF.
sum = lv_num * sy-index.
WRITE: / lv_num, 'x', sy-index, sum.
ENDDO.
ENDFORM.