Skip to Content
author's profile photo Former Member
Former Member

Cumulative sum in ALV report

HI , In Alv report need to how to sum all DMBTR for perticular EBELN from EKBE table.I dont know how to write a code for each line item summation. like: EBELN DMBTR 4000005 10000 4000005 5000 4000005 15000 here what i need i need to sum all values of DMBTR for EBELN value for each line item. Thanks and Regards Sankil

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Jan 02, 2014 at 07:15 AM

    TYPES: BEGIN OF TY_EKBE,

    EBELN TYPE EKBE-EBELN,

    DMBTR TYPE EKBE-DMBTR,

    SUM TYPE DMBTR,

    END OF TY_EKBE.

    DATA: IT_EKBE TYPE STANDARD TABLE OF TY_EKBE,

    IT_FINAL TYPE STANDARD TABLE OF TY_EKBE,

    WA_FINAL LIKE LINE OF IT_FINAL,

    WA_EKBE LIKE LINE OF IT_EKBE,

    SUM TYPE DMBTR,

    TEMP TYPE DMBTR.

    SELECT EBELN DMBTR FROM EKBE INTO TABLE IT_EKBE UP TO 10 ROWS.

    SORT IT_EKBE BY EBELN.

    LOOP AT IT_EKBE INTO WA_EKBE.

    SUM = WA_EKBE-DMBTR + SUM.

    AT END OF EBELN.

    MOVE WA_EKBE-EBELN TO WA_FINAL-EBELN.

    MOVE SUM TO WA_FINAL-SUM.

    APPEND WA_FINAL TO IT_FINAL.

    CLEAR: SUM,WA_FINAL.

    ENDAT.

    ENDLOOP.

    LOOP AT IT_FINAL INTO WA_FINAL.

    WRITE: / WA_FINAL-EBELN, WA_FINAL-SUM.

    ENDLOOP.



    You can also try using SUM statement as well as collect statement.


    Regards,


    Philip


    Capture5.PNG (1.7 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 02, 2014 at 07:22 AM

    The "standard" ALV tool for this is declaring DMBTR as summed and EBELN as a sort criteria with sub-total.

    Else two solutions:

    Easy one

    • Forbid user to change sort and filter criteria ( it_toolbar_excluding and similar tool)
    APPEND grid->mc_fc_filter TO gt_toolbar_excluding.
    APPEND grid->mc_fc_delete_filter TO gt_toolbar_excluding.
    APPEND grid->mc_fc_sort TO gt_toolbar_excluding.
    APPEND grid->mc_fc_subtot TO gt_toolbar_excluding.
    
    
    • Add a new column "cum. amount" and fill it in a simple LOOP (in field catalog prevent sum of this column NO_SUM)
    LOOP AT itab ASSIGNING <fs>.
    AT NEW ebeln.
    CLEAR <fs>-acc_amnt.
    ENDAT.
    ADD <fs>-amnt TO <fs>-acc_amnt.
    ENDLOOP.

    a little more difficult

    If you are actually ready to spend some (much) time for a true cumulative field and allow user to change sort and filter criteria

    - add a new column field with initial value like previous case

    - handle event AFTER_REFRESH of the ALV grid

    In the handling method

    • prevent infinite loop (use a global data) as the refresh at the end will trigger once again this method
    • extract sort and filter criteria (do you want to add EBELN if not already a sort criteria ?)
    • update the special column like in previous case only using displayed record (get_filtered_entries) and adapting to other sort criteria if required (e.g. user sort by matnr then ebeln...)
    • refresh the alv display, using soft option if you didn't change sort criteria.

    Regards,

    Raymond

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 02, 2014 at 06:59 AM

    Hi Sankil,

    You can use COLLECT stement after sorting records based on EBELN.

    sort it_ekbe by ebeln.

    **In loop

    COLLECT wa_ekbe INTO it_ekbe_final.

    **endloop.

    Deependra

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 02, 2014 at 07:05 AM

    Hi Sankil,

    Please understand the requirement, What exactly you want to disply from EKBE ( goods recevied value/total PO value ) ??? . this table will show the complete material flow of the business in which case you required the information.

    See example below, for one PO line item multiple entries with the different history


    pastedImage_0.png (18.9 kB)
    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Check this

      TABLES ekbe.

      TYPES: BEGIN OF ty_ekbe,
      ebeln TYPE ebeln,
      ebelp TYPE ebelp,
      dmbtr TYPE dmbtr,
      END OF ty_ekbe.

      TYPES: BEGIN OF ty_final,
      ebeln TYPE ebeln,
      dmbtr TYPE dmbtr,
      END OF ty_final.

      DATA: it_ekbe TYPE STANDARD TABLE OF ty_ekbe WITH HEADER LINE,
      it_final TYPE STANDARD TABLE OF ty_final WITH HEADER LINE..

      SELECT ebeln ebelp dmbtr FROM ekbe INTO TABLE it_ekbe
      WHERE ebeln = '3000000049' AND
      vgabe = '1'.
      LOOP AT it_ekbe.

      MOVE: it_ekbe-ebeln TO it_final-ebeln,
      it_ekbe-dmbtr TO it_final-dmbtr.

      COLLECT it_final.
      CLEAR: it_ekbe,
      it_final.
      ENDLOOP.


      pass the it_final to the FM ALV

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.