且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用ABAP代码实现从1累加到100

更新时间:2022-08-22 13:28:08

itab = VALUE #( FOR j = 1 WHILE j <= 100 ( j ) ).

* Reduce 后面跟类型

* A constructor expression with the reduction operator  

* REDUCE creates a result of a data type specified using type  

* from one or more iteration expressions.

* At least one variable or one field symbol must be specified. The variables or field symbols declared after  

* INIT can only be used after NEXT.  

* At least one iteration expression must then be specified using FOR and it is also possible to specify multiple  

* consecutive iteration expressions.

DATA(sum) = REDUCE i( INIT x = 0 FOR wa IN itab NEXT x = x + wa ).

WRITE: / sum.