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, NEXT = operation.
* 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_count) = REDUCE i( INIT count = 0 FOR val = 0 THEN val + 1 UNTIL val > 5 NEXT count = count + val ).
WRITE:'Sum of first 5 number :' ,lv_count.
Output
********************************Thank You*****************************
Comments
Post a Comment