代码语言:javascript复制
*定义
… REDUCE type(
INIT result = start_value
…
FOR for_exp1
FOR for_exp2
…
NEXT …
result = iterated_value
… )
*案例1
TYPES: BEGIN OF TY_LINE,
COL1 TYPE I,
END OF TY_LINE,
TY_TAB TYPE STANDARD TABLE OF TY_LINE WITH EMPTY KEY.
DATA(GT_ITAB) = VALUE TY_TAB( FOR J = 1 THEN J 1 UNTIL J > 10
( COL1 = J )
).
DATA(LV_SUM) = REDUCE I( INIT X = 0 FOR LS_ITAB IN GT_ITAB NEXT X = X LS_ITAB-COL1 ).
CL_DEMO_OUTPUT=>DISPLAY( LV_SUM ).
*案例2
YPES OUTREF TYPE REF TO IF_DEMO_OUTPUT.
DATA(OUTPUT) = REDUCE OUTREF( INIT OUT = CL_DEMO_OUTPUT=>NEW( )
TEXT = `Count up:`
FOR N = 1 THEN N 2 UNTIL N > 11
NEXT OUT = OUT->WRITE( TEXT )
TEXT = |{ N }| ).
OUTPUT->DISPLAY( ).