Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125
Beginner

How do you use the REDUCE operator to sum values in an internal table in modern ABAP?

REDUCE is used to aggregate values like totals, counts, etc., in a clean, functional style.

*&---------------------------------------------------------------------*
*& Report  ZREP_LCLCLASS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zrep_lclclass.

TYPESBEGIN OF ty_order,
         id     TYPE i,
         amount TYPE i,
       END OF ty_order.

DATAlt_orders TYPE STANDARD TABLE OF ty_order WITH EMPTY KEY,
      lv_total  TYPE i.

lt_orders VALUE #(
  id amount 100 )
  id amount 250 )
  id amount 150 )
).

lv_total REDUCE iINIT sum 0
                     FOR order IN lt_orders
                     NEXT sum sum order-amount ).

WRITE/ 'Total Amount:'lv_total. 

Output:

Total Amount: 500

Related Questions

Leave an answer

Leave an answer