REDUCE keyword in ABAP

    * It is also called as reduction operator.

    * Reduce operator creates a result of specified data type after going through iterations.

    * Previously we make a LOOP on the internal table and calculate the count, total, subtotal etc.

    * In SAP ABAP new syntax, instead of LOOP, we can use REDUCE operator to calculate the count, total, subtotal etc.

     * The syntax to use a REDUCE operator is as follows:

                REDUCE <type>(INIT ... FOR... THEN... UNTIL... NEXT... )

    * In the syntax - REDUCE = keyword, <type> = data type of the result, INIT = initial value, FOR = initialize iteration, THEN = increment, UNTIL = iteration end condition, NEXToperation.

    * In the REDUCE syntax, even if THEN keyword is not specified the default increment value is 1.


Report

REPORT zab_rp_reduce_count.

DATA(lv_countREDUCE iINIT count FOR val THEN val + UNTIL val > NEXT count count + val ).
WRITE:'Sum of first 5 number :' ,lv_count.


Output



********************************Thank You*****************************

Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).